Skip to content

Commit 4dd32f1

Browse files
committed
Merge pull request #6 from chriscool/gpe-cr-improvements
Gpe cr improvements
2 parents 444a416 + f0ca0e7 commit 4dd32f1

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

git-push-each

+32-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
#!/bin/sh
22

33
usage="USAGE
4-
$0 [--clean] <remote> <branch-prefix>
4+
$0 [--clean] [<remote> [<branch-prefix>]]
55
push each commit from stdin to its own branch.
66
7+
DESCRIPTION
8+
Read commit <sha1> hashes from stdin, one per line, and
9+
for each one, push a branch to <remote>.
10+
The branch is named following the <branch-prefix>-<sha1>
11+
pattern and points to <sha1>.
12+
By default <branch-prefix> is 'gpe-' and <remote> is
13+
'origin'.
14+
715
OPTIONS
816
--clean delete all branches matching pattern:
917
<branch-prefix><hash>
@@ -25,6 +33,12 @@ EXAMPLE
2533
# defaults
2634
remote="origin"
2735
prefix="gpe-"
36+
37+
die() {
38+
echo >&2 "$@"
39+
exit 1
40+
}
41+
2842
clean=0
2943
dryrun=0
3044

@@ -42,7 +56,7 @@ while [ $# -gt 0 ]; do
4256
dryrun=1
4357
shift ;;
4458
--*)
45-
die "$(eval_gettext "unrecognised option: '\$arg'")" ;;
59+
die "Unrecognised option: '$arg'\n$usage" ;;
4660
*)
4761
# get args
4862
case "$#" in
@@ -54,29 +68,37 @@ while [ $# -gt 0 ]; do
5468
1)
5569
remote=$1
5670
shift ;;
71+
*)
72+
die "Too many arguments: '$@'\n$usage" ;;
5773
esac ;;
5874
esac
5975
done
6076

77+
test -n "$remote" || die "Empty <remote> argument\n$usage"
78+
test -n "$prefix" || die "Empty <branch-prefix> argument\n$usage"
79+
6180
# clean up mode
6281
if [ $clean -eq 1 ]; then
63-
spec="($prefix[0-9a-f]{40})"
64-
for line in $(git branch -r | egrep -wo "$remote/$spec" | egrep -o "$spec")
82+
spec="($prefix[0-9a-fA-F]{40})"
83+
temp=$(mktemp) || die "mktemp failed"
84+
git branch -r >"$temp" || die "Could not list remote branches"
85+
for line in $(egrep -wo "$remote/$spec" "$temp" | egrep -o "$spec")
6586
do
66-
echo "git push $remote :$line"
67-
if [ $dryrun -eq 0 ]; then
68-
git push "$remote" ":$line"
69-
fi
87+
echo "git push $remote :$line"
88+
if [ $dryrun -eq 0 ]; then
89+
git push "$remote" ":$line" || die "Could not git push '$remote' ':$line'"
90+
fi
7091
done
92+
rm "$temp"
7193
exit 0
7294
fi
7395

7496
# push mode
75-
for line in $(egrep -wo [0-9a-f]{40})
97+
for line in $(egrep -wo [0-9a-fA-F]{40})
7698
do
7799
spec="$line:refs/heads/$prefix$line"
78100
echo "git push $remote $spec"
79101
if [ $dryrun -eq 0 ]; then
80-
git push "$remote" "$spec"
102+
git push "$remote" "$spec" || die "Could not git push '$remote' '$spec'"
81103
fi
82104
done

0 commit comments

Comments
 (0)