Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b98133

Browse files
committed
new version of git-ptt
1 parent 83362c1 commit 0b98133

File tree

1 file changed

+38
-65
lines changed

1 file changed

+38
-65
lines changed

‎git-ptt‎

Lines changed: 38 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,47 @@
11
#!/bin/bash
2-
# inspired by https://wchargin.github.io/posts/managing-dependent-pull-requests/
32

4-
push_args=()
5-
6-
get_remote_name() {
7-
local branch
8-
branch=$(git rev-parse --abbrev-ref HEAD)
9-
10-
git config --get ptt.$branch.remote ||
11-
git config --get --default "origin" ptt.remote
12-
}
13-
14-
get_remote_branch () {
15-
local branch
16-
branch=($(git show --quiet --format=%b | awk '/^x-branch: / {print 2ドル}'))
17-
18-
if (( "${#branch[*]}" == 0 )); then
19-
echo "ERROR: no x-branch directive" >&2
20-
return 1
21-
elif (( "${#branch[*]}" > 1 )); then
22-
echo "ERROR: multiple x-branch directives" >&2
23-
return 1
24-
fi
25-
26-
echo "${branch[0]}"
3+
usage() {
4+
cat <<EOF
5+
0ドル: usage: 0ドル [-f] [-F] [-r <remote>] <rev>
6+
EOF
277
}
288

29-
OPTSPEC="\
30-
git ptt [-r|--remote <remote> [-f|--force-with-lease] [-F|--force] [-q|--query]
31-
--
32-
h,help show help
33-
34-
r,remote=<REMOTE> specify name of remote
35-
f,force-with-lease see git-push(1)
36-
F,force really force
37-
q,query query only (don't push)
38-
"
39-
40-
eval "$(git rev-parse --parseopt -- "$@" <<<$OPTSPEC || echo exit $?)"
41-
42-
ptt_push=1
43-
while (( $# )); do
44-
case 1ドル in
45-
(-r|--remote)
46-
shift
47-
ptt_remote=1ドル
48-
;;
49-
(-f|--force-with-lease)
50-
push_args+=(--force-with-lease)
51-
;;
52-
(-F|--force)
53-
push_args+=(-f)
54-
;;
55-
(-q|--query)
56-
ptt_push=0
57-
;;
58-
(--) shift
59-
break
60-
;;
9+
force=
10+
remote=$(git config --get --default origin ptt.remote)
11+
query_only=0
12+
13+
while getopts qfr: ch; do
14+
case $ch in
15+
(f) force="--force-with-lease"
16+
;;
17+
(F) force="--force"
18+
;;
19+
(r) remote="$OPTARG"
20+
;;
21+
22+
(q) query_only=1
23+
;;
24+
25+
(\?) usage >&2
26+
exit 2
27+
;;
6128
esac
62-
63-
shift
6429
done
30+
shift $(( OPTIND - 1 ))
6531

66-
cid=$(git rev-parse --short HEAD)
32+
(($#==1))|| { usage >&2;exit 2; }
6733

68-
[[ "$ptt_remote" ]] || ptt_remote=$(get_remote_name)
69-
ptt_remote_branch=$(get_remote_branch) || exit 1
70-
ptt_remote_ref=$(git rev-parse -q --short $ptt_remote/$ptt_remote_branch || echo "none")
34+
git rev-list "$@" | tac | while read rev; do
35+
target=($(git show $rev -q --format=%b | awk '/^x-branch:/ {print 2ドル}'))
7136

72-
printf "%s -> %s:%s [%s]\n" "$cid" "$ptt_remote" "$ptt_remote_branch" "$ptt_remote_ref"
73-
(( ptt_push == 1 )) &&
74-
git push "${push_args[@]}" $ptt_remote HEAD:refs/heads/$ptt_remote_branch
37+
if (( ${#target[*]} > 1 )); then
38+
echo "ERROR: multiple x-branch directives in $rev." >&2
39+
exit 1
40+
elif (( ${#target[*]} == 0 )); then
41+
continue
42+
fi
43+
44+
git show -q --format="%h %s -> %Cred${remote}/${target}%Creset" $rev
45+
(( $query_only )) && continue
46+
git push ${force} ${remote} ${rev}:refs/heads/${target}
47+
done

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /