-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-submit
More file actions
executable file
·103 lines (92 loc) · 2.09 KB
/
git-submit
File metadata and controls
executable file
·103 lines (92 loc) · 2.09 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
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
#!/bin/bash
force=0
for i in `seq 1 $#`
do
eval curarg=\$$i
if [ "$curarg" = "-f" ]
then
force=1
else
topic=$curarg
fi
done
remote="$(git config --get submit.remote)"
current="$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)"
upstream="$(git rev-parse --symbolic-full-name --abbrev-ref @{u})"
parent="${upstream#*/}" # trim the leading remote name portion
num_submit="$(git rev-list @{u}.. | wc -l)"
reviewers="$(git config --get-all submit.reviewer) $(git config --get-all branch.$current.submit-reviewer)"
noreview="$(git config --get-all submit.noreview) $(git config --get-all branch.$current.submit-noreview)"
_splitNoReview() {
echo "$noreview" | sed 's/ /\n/g'
}
_joinReviewer() {
yesreviewers=$*
noreviewers=($noreview)
for noreviewer in "${noreviewers[@]}"
do
yesreviewers=$(echo "$yesreviewers" | sed "s/ *$noreviewer *//g")
done
if [ -z "$yesreviewers" ]
then
echo "r=$yesreviewers" | sed 's/ \+/,r=/g'
fi
}
_gen_ChangeIdInput() {
echo "tree `git write-tree`"
if parent=`git rev-parse "HEAD^0" 2>/dev/null`
then
echo "parent $parent"
fi
echo "author `git var GIT_AUTHOR_IDENT`"
echo "committer `git var GIT_COMMITTER_IDENT`"
echo
printf '%s' "$clean_message"
}
_gen_ChangeId() {
_gen_ChangeIdInput |
git hash-object -t commit --stdin
}
if [ -z "$remote" ]
then
echo "submit.remote is not set"
exit 1
fi
if [ -z "$parent" ]
then
echo "can not determine upstream of current branch"
exit 1
fi
if [ "$num_submit" -eq 0 ]
then
echo "nothing found to submit between $current and $upstream"
exit 0
#elif [ "$num_submit" -ne 1 -a $force -eq 0 ]
#then
# echo "can only submit a single commit, found $num_submit"
# exit 1
fi
R=
if [ -n "$reviewers" ]
then
R=%$(_joinReviewer $reviewers)
if [ "$R" == "%r=" ]
then
R=
fi
fi
target="$parent"
git pull
if [ "$parent" != "$current" ]
then
target="$target/$current"
git push "$remote" HEAD:refs/for/$target$R
else
if [ -z $topic ]
then
topic=`_gen_ChangeId`
fi
target="$target/$topic"
git branch -m $topic && git push "$remote" HEAD:refs/for/$target$R
fi
git branch -vv