Skip to content

Commit bc918ac

Browse files
committed
Merge branch 'rr/rebase-sha1-by-string-query'
Allow various commit objects to be given to "git rebase" by ':/look for this string' syntax, e.g. "git rebase --onto ':/there'". * rr/rebase-sha1-by-string-query: rebase: use peel_committish() where appropriate sh-setup: add new peel_committish() helper t/rebase: add failing tests for a peculiar revision
2 parents 8d8975a + 2e6e276 commit bc918ac

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

git-rebase.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ then
436436
shift
437437
;;
438438
esac
439-
upstream=`git rev-parse --verify "${upstream_name}^0"` ||
439+
upstream=$(peel_committish "${upstream_name}") ||
440440
die "$(eval_gettext "invalid upstream \$upstream_name")"
441441
upstream_arg="$upstream_name"
442442
else
@@ -472,7 +472,7 @@ case "$onto_name" in
472472
fi
473473
;;
474474
*)
475-
onto=$(git rev-parse --verify "${onto_name}^0") ||
475+
onto=$(peel_committish "$onto_name") ||
476476
die "$(eval_gettext "Does not point to a valid commit: \$onto_name")"
477477
;;
478478
esac

git-sh-setup.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,15 @@ then
313313
}
314314
: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
315315
fi
316+
317+
peel_committish () {
318+
case "$1" in
319+
:/*)
320+
peeltmp=$(git rev-parse --verify "$1") &&
321+
git rev-parse --verify "${peeltmp}^0"
322+
;;
323+
*)
324+
git rev-parse --verify "${1}^0"
325+
;;
326+
esac
327+
}

t/t3400-rebase.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ test_expect_success 'rebase against master' '
5959
git rebase master
6060
'
6161

62+
test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' '
63+
test_when_finished "git branch -D torebase" &&
64+
git checkout -b torebase my-topic-branch^ &&
65+
upstream=$(git rev-parse ":/Add B") &&
66+
onto=$(git rev-parse ":/Add A") &&
67+
git rebase --onto $onto $upstream &&
68+
git reset --hard my-topic-branch^ &&
69+
git rebase --onto ":/Add A" ":/Add B" &&
70+
git checkout my-topic-branch
71+
'
72+
6273
test_expect_success 'the rebase operation should not have destroyed author information' '
6374
! (git log | grep "Author:" | grep "<>")
6475
'

t/t3404-rebase-interactive.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,4 +939,15 @@ test_expect_success 'rebase -i respects core.commentchar' '
939939
test B = $(git cat-file commit HEAD^ | sed -ne \$p)
940940
'
941941

942+
test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
943+
test_when_finished "git branch -D torebase" &&
944+
git checkout -b torebase branch1 &&
945+
upstream=$(git rev-parse ":/J") &&
946+
onto=$(git rev-parse ":/A") &&
947+
git rebase --onto $onto $upstream &&
948+
git reset --hard branch1 &&
949+
git rebase --onto ":/A" ":/J" &&
950+
git checkout branch1
951+
'
952+
942953
test_done

0 commit comments

Comments
 (0)