-
Notifications
You must be signed in to change notification settings - Fork 2
/
git-pull-ff
executable file
·123 lines (95 loc) · 3.63 KB
/
git-pull-ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
### This Git method script pulls all new commits, branches and tags from all
### known remote sources, and attempts fast-forward merges of the current
### workspace with its more up-to-date remote counterparts.
### Script Copyright (C) 2014-2015 by Jim Klimov, License: MIT
### Pieces probably inspired by various posts from Stack Overflow
PATH=/usr/gnu/bin:/usr/sfw/bin:/opt/sfw/bin:/opt/omniti/bin:/bin:/usr/bin:\
/sbin:/usr/sbin:$PATH
LANG=C
LC_ALL=C
export PATH LANG LC_ALL
git_pull_ff() {
currentbranchref="$(git symbolic-ref HEAD 2>&-)"
currentbranch="`git branch | grep '^* ' | sed 's,^* ,,'`" || \
currentbranch=""
TS="`date -u '+%Y%m%dT%H%M%SZ'`" || \
TS="`date | sed 's,[\@\:\ ],_,g'`" || \
TS="before-git-pull-ff$$"
repodir="$(git rev-parse --show-toplevel)" && \
[ -d "$repodir/.zfs/snapshot" ] && \
echo "Trying to make ZFS snapshots '@$TS' of the repo dataset during git-pulling..." && \
mkdir "$repodir/.zfs/snapshot/git-pull-ff--$TS--0--beforePulls" || true
#git pull $currentbranch
#git pull --tags $currentbranch
### Remove local branches deleted remotely
### TODO : not by default, add an option/envvar to enable this
#git fetch --all --prune
git pull --all
git pull --all --recurse-submodules=yes
git fetch --tags
git fetch --tags --recurse-submodules=yes
BREAK=no
trapbreak() {
if [ "$BREAK" = yes ] ; then
echo "Stopping due to multiple breaks..."
if [ x"$currentbranch" != x -a "$currentbranch" != master ]; then
echo "Trying to return to branch $currentbranch..."
git checkout $currentbranch
git branch
fi
[ -d "$repodir/.zfs/snapshot" ] && \
mkdir "$repodir/.zfs/snapshot/git-pull-ff--$TS--X--CleanupAfterGotBreak" || true
exit 1
fi >&2
echo 'Got stop signal, please wait until the end of critical section' >&2
BREAK=yes
}
checkbreak() {
[ "$BREAK" = yes ] && echo "Stopping due to break" && exit 1
return 0
}
git branch -r | grep -v ' -> ' | while read remotebranch
do
# Split <remote>/<branch> into remote and branchref parts
remote="${remotebranch%%/*}"
branchref="refs/heads/${remotebranch#*/}"
if [ "$branchref" == "$currentbranchref" ]
then
echo "Updating current branch $branchref from $remote..."
git pull --ff-only
else
echo "Updating non-current ref $branchref from $remote..."
git fetch "$remote" "$branchref:$branchref"
fi
done
[ -d "$repodir/.zfs/snapshot" ] && \
mkdir "$repodir/.zfs/snapshot/git-pull-ff--$TS--1--afterRemoteFetched" || true
echo "NOTE: Setting trap to avoid bad breakage (current-branch mismatch) on Ctrl+C"
trap "trapbreak" 1 2 3 15
git checkout master && \
git pull --ff-only --all
git pull --ff-only --all --recurse-submodules=yes
#git pull --ff-only master && \
#git pull --ff-only --all
[ -d "$repodir/.zfs/snapshot" ] && \
mkdir "$repodir/.zfs/snapshot/git-pull-ff--$TS--2--afterMasterBranch" || true
[ x"$currentbranch" != x -a "$currentbranch" != master ] && \
git checkout $currentbranch && \
git pull --ff-only --all && \
git pull --ff-only --all --recurse-submodules=yes
# git pull --ff-only $currentbranch && \
# git pull --ff-only --all
echo "DONE!"
[ x"$currentbranch" != x ] && \
echo "Started repo '`pwd`' from branch '$currentbranch'... still there?"
git branch
echo "NOTE: Clearing the trap for critical segment"
trap "-" 1 2 3 15
[ -d "$repodir/.zfs/snapshot" ] && \
mkdir "$repodir/.zfs/snapshot/git-pull-ff--$TS--3--afterCurrentBranch" || true
git pull
[ -d "$repodir/.zfs/snapshot" ] && \
mkdir "$repodir/.zfs/snapshot/git-pull-ff--$TS--Z--afterSync" || true
}
git_pull_ff