-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_git_cmd
73 lines (67 loc) · 2.27 KB
/
.bash_git_cmd
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
#!bash
gunpushed() {
local branch remote tracking rbranch
branch=`git symbolic-ref -q HEAD`
if [ -n "$branch" ]; then
branch="${branch##refs/heads/}"
remote=`git config branch.${branch}.remote`
tracking=`git config branch.${branch}.merge`
if [ -n "$remote" -a -n "$tracking" ]; then
tracking="${tracking##refs/heads/}"
rbranch="$remote/$tracking"
echo "UNPUSHED: git log $rbranch..$branch"
git log $rbranch..$branch
echo "UNPULLED: git log $branch..$rbranch"
git log $branch..$rbranch
fi
fi
}
gpu() {
local branch remote tracking
branch=`git symbolic-ref -q HEAD`
if [ -n "$branch" ]; then
branch="${branch##refs/heads/}"
remote=`git config branch.${branch}.remote`
tracking=`git config branch.${branch}.merge`
if [ -n "$remote" -a -n "$tracking" ]; then
tracking="${tracking##refs/heads/}"
echo "git push $remote $tracking"
git push $remote $tracking
fi
fi
}
gmerge() {
local toMerge force branch remote n m rbranch tracking
toMerge=$1
force=$2
echo "gmerge: fetching..."
git fetch || return
echo "gmerge: checking if current branch is up to date (use 'gmerge branch force' to skip)..."
branch=`git symbolic-ref -q HEAD`
if [ -z "$branch" ]; then
echo "gmerge: not currently on a branch"
return 1
fi
branch="${branch##refs/heads/}"
remote=`git config branch.${branch}.remote`
tracking=`git config branch.${branch}.merge`
if [ -n "$remote" -a -n "$merge" ]; then
tracking="${tracking##refs/heads/}"
rbranch="$remote/$tracking"
n=`git log --pretty=oneline $rbranch..$branch | wc -l`
m=`git log --pretty=oneline $branch..$rbranch | wc -l`
if [ "$n" -gt 0 -o "$m" -gt 0 ]; then
echo "gmerge: ERROR local branch '$branch' is out of sync with remote tracking branch '$rbranch'"
if [ -n "$force" ]; then
echo "gmerge: ... ignoring (force option present)"
else
gunpushed
return 1
fi
fi
else
echo "gmerge: can't identify remote tracking branch for local branch '$branch'"
fi
echo "gmerge: merging origin/$toMerge ('git merge --abort' to cancel)"
git merge --no-ff origin/$toMerge
}