-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull
More file actions
61 lines (54 loc) · 1.82 KB
/
pull
File metadata and controls
61 lines (54 loc) · 1.82 KB
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
#!/bin/bash
HERE=$(dirname ${BASH_SOURCE[0]})
. ${HERE}/fixpath
function exitlikethis
{
>&2 echo $@
exit 1
}
branch=$(branch)
stashybranch=
targetBranch=$branch
if [ -z "$branch" ] ; then
exitlikethis Not a git repo.
fi
possibleTargetBranch=
if [ "$#" = 1 ] ; then
possibleTargetBranch=$1
fi
if [ -n "$possibleTargetBranch" ] ; then
if ! branchexists $possibleTargetBranch ; then
exitlikethis targetBranch: $possibleTargetBranch does not exist
else
targetBranch=$possibleTargetBranch
fi
fi
if [ -n "$targetBranch" ] ; then
echo Pulling target branch: $targetBranch
if git status | head -20 | grep '^Changes ' > /dev/null; then
stashybranch=$(date +'stash_%Y_%m_%d_%H_%M_%S')
# git branch -D "$stashybranch"
git checkout -b "$stashybranch" "$branch" || exitlikethis "Failed to create faux stash branch $stashybranch"
git add -u
git commit -m "backing up before pulling $targetBranch"
echo STASH BRANCH CREATED HERE: $stashybranch
echo IF THERE IS TROUBLE LATER RESTORE WITH:
cat > ./_restore.sh <<EOFRESTORE
git checkout "$branch"
git merge "$stashybranch" --no-commit --no-ff
git branch -D "$stashybranch"
EOFRESTORE
cat ./_restore.sh
echo OR JUST RUN sh ./_restore.sh
git checkout "$branch" || exitlikethis "Failed to re-checkout branch $branch"
fi
git checkout "$targetBranch" || exitlikethis "Failed to checkout $targetBranch"
git pull || exitlikethis "Failed to git pull"
if [ "$branch" != "$targetBranch" ] ; then
git checkout "$branch" || exitlikethis "Failed to checkout $branch"
fi
fi
if [ -n "$stashybranch" ] ; then
git merge "$stashybranch" --no-commit --no-ff || exitlikethis "Failed to merge $stashybranch"
git branch -D "$stashybranch"
fi