forked from 177shivam/dependabot-for-clojure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rfc
executable file
·102 lines (78 loc) · 2.1 KB
/
rfc
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
#!/usr/bin/env bash
RFC_DRAFT_FIRST=${RFC_DRAFT_FIRST:-0}
set_hooks_commit_msg()
{
dirname=".git/hooks"
filename="$dirname/commit-msg";
if [ -x "$filename" ]; then
return;
fi
url=$(git config --get remote.origin.url)
host=$(echo $url | cut -d '/' -f 3)
port_arg=""
if grep -q ':' <<<"$host" ; then
port_arg="-P $(echo $host | cut -d ':' -f 2)"
host=$(echo $host | cut -d ':' -f 1)
fi
mkdir -p $dirname
[ ! -f "$filename" ] && scp $port_arg $host:hooks/commit-msg $dirname || { echo "Couldn't download commit-msg hook"; exit 1; }
chmod +x $filename;
}
rebase_changes()
{
git fetch origin;
GIT_EDITOR=$0 git rebase -i origin/$BRANCH;
}
editor_mode()
{
if [ $(basename "$1") = "git-rebase-todo" ]; then
sed 's/^pick /reword /g' "$1" > $1.new && mv $1.new $1;
return;
fi
if [ $(basename "$1") = "COMMIT_EDITMSG" ]; then
while true; do
echo Commit: "\"$(head -n 1 $1)\""
return;
done
fi
cat <<EOF
$0 - editor_mode called on unrecognized file $1 with content:
$(cat $1)
EOF
return 1;
}
assert_diverge()
{
git diff origin/$BRANCH..HEAD | grep -q .;
}
main()
{
br=$(git branch | grep "*");
current_branch=${br#* };
# Go to top-level in the working directory
cd $(git rev-parse --show-toplevel);
if [ -z "$1" ]; then
echo "You have not mentioned the branch, exiting.";
return;
fi
if [ "$current_branch" != "$1" ] && [ "$GIT_EDITOR" != "$0" ]; then
echo "your current branch is $current_branch and you want to push to $1. We do not allow this." ;
return;
fi
if [ -e "$1" ]; then
editor_mode "$@";
return;
fi
export BRANCH="$1";
set_hooks_commit_msg;
rebase_changes;
assert_diverge;
if [ $RFC_DRAFT_FIRST -eq 1 ]; then
echo "pushing drafts to gerrit branch = $BRANCH";
git push origin HEAD:refs/drafts/$BRANCH;
else
echo "pushing changes to gerrit branch = $BRANCH";
git push origin HEAD:refs/for/$BRANCH;
fi
}
main "$@"