-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpropose
More file actions
executable file
·168 lines (134 loc) · 4.14 KB
/
propose
File metadata and controls
executable file
·168 lines (134 loc) · 4.14 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/sh
USAGE='[-m <message>]'
. legit-setup.sh
# Get the commit message
message=
user=$(git config user.email)
user=${user//@/_}
is_fix=false
is_merge=false
merge=
while test $# != 0
do
case "$1" in
-m)
shift
# Get the message, but trim whitespace from it
message=`echo $1 | sed 's/^\s*//;s/\s*$//'`
# This will be blank if the user either failed to provide a
# message, or if it was only whitespace (which we reject)
if [ -z "$message" ]; then
usage
fi
;;
-f|--is-fix)
is_fix=true ;;
--is-merge)
is_merge=true
shift
merge=$1
if test -z "$merge"
then
usage
fi
;;
*)
usage
esac
shift
done
if ! test -n "$user"
then
die "fatal: no user was found. Set one in git config"
fi
# People need to specify a message!
if [ ! -n "$message" ]; then
echo "# Please enter the proposal message for your changes. Lines starting" > .git/PROPOSAL_EDITMSG
echo "# with '#' will be ignored, and an empty message aborts the proposal." >> .git/PROPOSAL_EDITMSG
git_editor .git/PROPOSAL_EDITMSG
# Remove comments, whitespace and blank lines
message=`sed '/\s*#/d;s/^\s*//;s/\s*$//;/./,$!d' .git/PROPOSAL_EDITMSG`
if [ -z "$message" ]; then
echo "Aborting because of empty message"
exit 0
fi
fi
# Has this repo been legitimised?
if ! git show-ref --quiet refs/heads/tracking; then
>&2 echo "fatal: no tracking branch exists"
exit -1
fi
require_clean_work_tree 'make a proposal'
# Check we're not in a locked branch, or the tracking branch
orig_head=`git symbolic-ref -q --short HEAD`
if [ "$orig_head" = "tracking" ]; then
die "fatal: you are in the tracking branch. Please checkout the
the branch you wish to propose."
fi
# The commit at the head of the proposal is used as it's ID
name=`git rev-parse --verify HEAD`
# Let's do this
git checkout --quiet tracking
if ! [ -a .tracking/users/$user ]
then
die_neatly "fatal: You aren't registered in the system"
fi
# Hash collisions shouldn't happen...
if [ -d .tracking/proposals/$name ]; then
die_neatly "fatal: this proposal already exists"
fi
##if test false = "$is_merge"
#then
parent=(`find_branch_point $name`)
#fi
if [ $? != 0 ]
then
git checkout --quiet $orig_head
die_neatly "Couldn't find a parent proposal or locked branch for HEAD"
fi
if test true = "$is_fix" && [ -z "${parent[1]}" ]; then
die_neatly "You've specified this is a fix, but the proposal isn't based on a proposal"
fi
# Make the proposal and fill it with the proposal message
mkdir .tracking/proposals/$name
cd .tracking/proposals/$name
echo "Proposer: $(git config user.name) <$(git config user.email)>" > proposal
echo "Submitted-at: $(date -R)" >> proposal
echo "Status: Open" >> proposal
echo "Votes: 0" >> proposal
echo "Start: ${parent[0]}" >> proposal
if test true = "$is_merge"
then
echo "Merge-of: $merge" >> proposal
append_header Merged-By $name ../$merge/proposal
git add ../$merge/proposal > /dev/null 2>&1
fi
if test false = "$is_merge" && [ -n "${parent[1]}" ]
then
if test true = "$is_fix"; then
echo "Fix-of: ${parent[1]}" >> proposal
append_header Fixed-By $name ../${parent[1]}/proposal
else
echo "Extension-of: ${parent[1]}" >> proposal
append_header Extended-By $name ../${parent[1]}/proposal
fi
git add ../${parent[1]}/proposal > /dev/null 2>&1
fi
echo "" >> proposal
echo "$message" >> proposal
cd ..
echo $name >> open
# Git won't shutup when adding files, so pipe everything to /dev/null
git add open >> /dev/null 2>&1
git add $name >> /dev/null 2>&1
cd ../users
proposal_count=$(expr $(read_header proposals $user) + 1)
replace_header Proposals $proposal_count $user
git add $user >> /dev/null 2>&1
git commit --quiet -m "Proposed: $name"
# Need to be back in the tree root so git can delete .tracking when we
# switch back to the proposal branch
cd ../..
git checkout --quiet $orig_head
git checkout --quiet -b proposals/$name
echo "Created Proposal: $name"