]>
git.immae.eu Git - perso/Immae/Projets/Scripts/Public.git/blob - backup_git_dirs
2 # The MIT License (MIT)
4 # Copyright (c) 2011-2016 Ismaël Bouya http://www.normalesup.org/~bouya/
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 function backup_refs
() {
28 pushd "$1" > /dev
/null
30 if git
rev-parse --git-dir > /dev
/null
2>&1; then
31 git
for-each-ref --format='%(refname)' refs
/$REF_NS | while read ref
; do
32 git update
-ref -d "$ref"
35 git
for-each-ref --format='%(refname)' refs
/heads refs
/tags
| while read ref
; do
36 new_ref
=$(echo "$ref" | sed -e "s@^refs/@refs/$REF_NS/@")
37 git update
-ref $new_ref $ref
41 git reflog
--pretty=tformat
:'%H' refs
/stash
2>/dev
/null
| while read ref
; do
42 git update
-ref refs
/$REF_NS/stash
/stash_
$stash $ref
46 export GIT_INDEX_FILE
=`mktemp /tmp/git-backup-index.XXXXXX`
48 head_commit
=$(git show-ref --hash --head ^HEAD)
50 COMMIT
=`git commit-tree $(git write-tree) -p $head_commit -m "Automatic backup"`
51 git update
-ref refs
/$REF_NS/workdir
$COMMIT
52 rm -f "$GIT_INDEX_FILE"
55 if git remote
| grep -q "^$REMOTE$"; then
56 git push
-q --force $REMOTE "refs/$REF_NS/*:refs/$REF_NS/*"
57 git
for-each-ref --format='%(refname)' refs
/$REF_NS | while read ref
; do
58 git update
-ref -d "$ref"
61 # git fetch $REMOTE --force "refs/$REF_NS/*:refs/$REF_NS/*"
68 for directory
in "$@"; do
69 backup_refs
$directory