]>
git.immae.eu Git - perso/Immae/Projets/Scripts/Public.git/blob - backup_git_dirs
f2d20553b9227ad94599588a7a915019d304488a
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
25 # Feel like tipping/donating? https://www.immae.eu/licenses_and_tipping
30 function backup_refs
() {
31 pushd "$1" > /dev
/null
33 if git
rev-parse --git-dir > /dev
/null
2>&1; then
34 git
for-each-ref --format='%(refname)' refs
/$REF_NS | while read ref
; do
35 git update
-ref -d "$ref"
38 git
for-each-ref --format='%(refname)' refs
/heads refs
/tags
| while read ref
; do
39 new_ref
=$(echo "$ref" | sed -e "s@^refs/@refs/$REF_NS/@")
40 git update
-ref $new_ref $ref
44 git reflog
--pretty=tformat
:'%H' refs
/stash
2>/dev
/null
| while read ref
; do
45 git update
-ref refs
/$REF_NS/stash
/stash_
$stash $ref
49 export GIT_INDEX_FILE
=`mktemp /tmp/git-backup-index.XXXXXX`
51 head_commit
=$(git show-ref --hash --head ^HEAD)
53 COMMIT
=`git commit-tree --no-gpg-sign $(git write-tree) -p $head_commit -m "Automatic backup"`
54 git update
-ref refs
/$REF_NS/workdir
$COMMIT
55 rm -f "$GIT_INDEX_FILE"
58 if git remote
| grep -q "^$REMOTE$"; then
59 git push
--no-verify --no-signed -q --force $REMOTE "refs/$REF_NS/*:refs/$REF_NS/*"
60 git
for-each-ref --format='%(refname)' refs
/$REF_NS | while read ref
; do
61 git update
-ref -d "$ref"
64 # git fetch $REMOTE --force "refs/$REF_NS/*:refs/$REF_NS/*"
71 for directory
in "$@"; do
72 backup_refs
$directory