Build: tweak prometheus requires line, add changelog bits
[pcp.git] / scripts / pcp-push
blob95f060ae5db91d9e986cacfe10cecf9d5074b052
1 #!/bin/sh
3 # typical usage:
4 # push-pcp -b master -t pcp -r 6bad98e4b0537c2e99b3906ca7a36f4998ea3419..
7 tmp=/var/tmp/$$
8 trap "rm -f $tmp.*; exit 0" 0 1 2 3 15
10 _usage()
12 echo >&2 "Usage: pcp-push [options]"
13 echo >&2
14 echo >&2 "options:"
15 echo >&2 " -b branch [defaults to master]"
16 echo >&2 " -n dryrun"
17 echo >&2 " -r range [defaults to \$(cat pushed.sha)..)]"
18 echo >&2 " -s short format, do not include commit messages"
19 exit 1
22 dryrun=false
23 GIT=git
24 branch=master
25 tree=origin
26 short=false
27 if [ -f pushed.sha ]
28 then
29 range=$(cat pushed.sha)..
30 else
31 range=''
33 while getopts "b:nr:s?" c
35 case $c
38 branch="$OPTARG"
41 dryrun=true
42 GIT="echo + git"
45 range="$OPTARG"
48 short=true
51 _usage
52 # NOTREACHED
53 esac
54 done
55 shift `expr $OPTIND - 1`
57 [ $# -eq 0 ] || _usage
59 if [ -z "$range" ]
60 then
61 echo "Error: no range from pushed.sha, so need -r range"
62 exit 1
66 unset GIT_EXTERNAL_DIFF
67 pull=`git config remote.origin.url`
68 case "$pull"
70 *oss.sgi.com*|*git.pcp.io*)
71 # old school ... does not work any more
73 push=`echo "$pull" | sed -e 's/^git:/ssh:/' -e "s;/git.pcp.io/;/git.pcp.io/oss/git/;"`
76 *github*)
77 # new school ...
79 push=''
83 echo "Sorry, no recipe to handle repo: $pull"
84 exit 1
86 esac
88 echo "Changes committed to $pull $branch" >/tmp/msg
89 echo >>/tmp/msg
90 git shortlog --no-merges --numbered $range >$tmp.tmp
91 if [ -s $tmp.tmp ]
92 then
93 cat $tmp.tmp >>/tmp/msg
94 else
95 echo "Nothing to push ... bye."
96 rm -f /tmp/msg
97 exit
99 git log --no-merges -p $range | diffstat -p1 >>/tmp/msg
100 if $short
101 then
103 else
104 echo >>/tmp/msg
105 echo "Details ..." >>/tmp/msg
106 echo >>/tmp/msg
107 git log --no-merges $range >>/tmp/msg
110 xclip -sel clip < /tmp/msg
111 cat /tmp/msg
112 echo "(all of this for email is in /tmp/msg)"
113 rm -f $tmp.y
114 while true
116 if [ -z "$push" ]
117 then
118 echo -n "Push to $pull [y|n|q] (or ctrl+C to abort) "
119 else
120 echo -n "Push to $push? [y|n|q] (or ctrl+C to abort) "
122 read ans </dev/tty
123 if [ -z "$ans" ]
124 then
126 elif [ "$ans" = y ]
127 then
128 touch $tmp.y
129 break
130 elif [ "$ans" = n ]
131 then
132 break
133 elif [ "$ans" = q ]
134 then
135 echo "Quitting ... pushed.sha not updated"
136 exit
138 echo "Answer the question, bozo!"
139 done
140 if [ -f $tmp.y ]
141 then
142 $GIT push $push
143 $GIT push --tags $push
144 # may have local git mirror that needs to be updated ...
146 if [ -d $HOME/git-mirror ]
147 then
148 here=`pwd`
149 cd $HOME/git-mirror
150 for dir in *
152 [ -d "$dir" ] || continue
153 [ -f "$dir/config" ] || continue
154 if grep "url = $pull" "$dir/config" >/dev/null 2>&1
155 then
156 # found repo with url matching the one we've just pushed to
158 cd $dir
159 echo "Update local $dir git mirror ..."
160 git fetch
161 cd ..
163 done
164 cd $here
168 rm -f $tmp.y
169 while true
171 echo -n "Push to github mirror? [y|n|q] (or ctrl+C to abort) "
172 read ans </dev/tty
173 if [ -z "$ans" ]
174 then
176 elif [ "$ans" = y ]
177 then
178 touch $tmp.y
179 break
180 elif [ "$ans" = n ]
181 then
182 break
183 elif [ "$ans" = q ]
184 then
185 echo "Quitting ... pushed.sha not updated"
186 exit
188 echo "Answer the question, bozo!"
189 done
190 if [ -f $tmp.y ]
191 then
192 push="ssh://git@github.com/performancecopilot/pcp.git"
193 $GIT push --mirror $push
196 # remember last commit that was pushed ...
198 sha=`git log | sed -e 's/commit //' -e 1q`
199 if $dryrun
200 then
201 echo "+ echo $sha >pushed.sha"
202 else
203 echo "$sha" >pushed.sha
204 case `id -un`
206 kenj)
207 echo "To send commit mail ..."
208 echo '$ sendcommitmail'
210 esac