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 891a0d2

Browse files
committed
multiple changes to mkpr
- keep branches by default (-k is now "cleanup") - if branch already exists, checkout and reset instead of delete and create - do not attempt to create a pr if one already exists - add `-t <rev>` option if you want to stop somewhere other than HEAD
1 parent 9c1a96a commit 891a0d2

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

‎mkpr‎

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,26 @@ get_remote_branch () {
1515
echo "${branch[0]}"
1616
}
1717

18+
branch_exists() {
19+
git rev-parse -q --verify "1ドル" > /dev/null
20+
}
21+
1822
opt_discover=0
1923
opt_branch=0
2024
opt_update=0
21-
opt_keep=0
22-
while getopts dbuk ch; do
25+
opt_cleanup=0
26+
to_rev=HEAD
27+
while getopts dbukt: ch; do
2328
case $ch in
29+
(t) to_rev=$OPTARG
30+
;;
2431
(d) opt_discover=1
2532
;;
2633
(b) opt_branch=1
2734
;;
2835
(u) opt_update=1
2936
;;
30-
(k) opt_keep=1
37+
(k) opt_cleanup=1
3138
;;
3239
esac
3340
done
@@ -42,12 +49,9 @@ base=1ドル
4249
remote=${2:-origin}
4350
target=$(git remote get-url $remote | awk -F/ '{printf "%s/%s", $(NF-1), $NF}')
4451

45-
echo "base: $base"
46-
echo "target: $target"
47-
4852
old_head=$(git rev-parse --abbrev-ref HEAD)
4953

50-
revs=($(git log --reverse --grep '^x-branch:' --format=%H ${base}..HEAD))
54+
revs=($(git log --reverse --grep '^x-branch:' --format=%H ${base}..${to_rev}))
5155
branches=()
5256
for rev in "${revs[@]}"; do
5357
remote_branch=$(get_remote_branch $rev) || exit 1
@@ -64,25 +68,33 @@ for (( i=0; i<${#revs[*]}; i++ )); do
6468
rev=${revs[i]}
6569
remote_branch=${branches[i]}
6670

67-
echo "BRANCH $remote_branch@${rev:0:7}"
68-
git branch -q -D $remote_branch > /dev/null 2>&1 ||:
69-
git checkout -q -b $remote_branch $rev
71+
if branch_exists $remote_branch; then
72+
echo "BRANCH $remote_branch@${rev:0:7} -- exists"
73+
git checkout -q $remote_branch
74+
git reset -q --hard $rev
75+
else
76+
echo "BRANCH $remote_branch@${rev:0:7} -- create"
77+
git branch -q -D $remote_branch > /dev/null 2>&1 ||:
78+
git checkout -q -b $remote_branch $rev
79+
fi
7080

7181
(( $opt_branch == 1 )) && continue
7282

7383
echo "PUSH ${rev:0:7} -> $remote_branch"
7484
git push -u -f origin $remote_branch
7585

76-
if (( $opt_update == 0 )); then
77-
if ! gh pr view > /dev/null 2>&1; then
78-
echo "PR $remote_branch@${rev:0:7}"
79-
gh pr create \
80-
-t "$(git show --quiet --format=%s)" \
81-
-b "$(git show --quiet --format=%b | grep -v '^x-branch:')"
82-
fi
86+
(( $opt_update == 1 )) && continue
87+
88+
if gh pr view > /dev/null 2>&1; then
89+
echo "PR $remote_branch@${rev:0:7} -- exists"
90+
else
91+
echo "PR $remote_branch@${rev:0:7} -- creating"
92+
gh pr create \
93+
-t "$(git show --quiet --format=%s)" \
94+
-b "$(git show --quiet --format=%b | grep -v '^x-branch:')"
8395
fi
8496

85-
if (( $opt_keep == 0 )); then
97+
if (( $opt_cleanup == 1 )); then
8698
echo "DELETE $remote_branch"
8799
git checkout -q --detach
88100
git branch -D $remote_branch > /dev/null 2>&1

0 commit comments

Comments
(0)

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