[PATCH v2 05/13] Teach rebase interactive the reset command
- From
- Jörg Sommer <joerg@alea.gnuu.de>
- Date
- Apr 14, 2008, 00:21 UTC
- Message-ID
- <1208132469-26471-5-git-send-email-joerg@alea.gnuu.de>
- In-Reply-To
- <1208132469-26471-4-git-send-email-joerg@alea.gnuu.de>
This command does a hard reset of the HEAD, i.e. the next operation used this commit as parent. This is necessary to redo the commits of different branches they become merged later.
Signed-off-by: Jörg Sommer <joerg@alea.gnuu.de> --- git-rebase--interactive.sh | 10 ++++++++++ t/t3404-rebase-interactive.sh | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 6ac316a..a4b7aad 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -351,6 +351,15 @@ do_next () { git update-ref "$mark" HEAD || die "update-ref failed" ;; + reset|r) + comment_for_reflog reset + + tmp=$(git rev-parse --verify "$(mark_to_ref $sha1)") || + die "Invalid parent '$sha1' in $command $sha1 $rest" + + mark_action_done + output git reset --hard $tmp + ;; *) warn "Unknown command: $command $sha1 $rest" die_with_patch $sha1 "Please fix this in the file $TODO." @@ -572,6 +581,7 @@ do # edit = use commit, but stop for amending # squash = use commit, but meld into previous commit # mark :mark = mark the current HEAD for later reference +# reset commit = reset HEAD to the commit # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index fa3560e..78673a6 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -85,6 +85,9 @@ for line in $FAKE_LINES; do mark*) echo "mark ${line#mark}" echo "mark ${line#mark}" >> "$1";; + reset*) + echo "reset ${line#reset}" + echo "reset ${line#reset}" >> "$1";; *) echo sed -n "${line}s/^pick/$action/p" sed -n "${line}p" < "$1".tmp @@ -206,6 +209,20 @@ test_expect_success 'setting marks works' ' ls $marks_dir | wc -l | grep -Fx 0 ' +test_expect_success 'reset with nonexistent mark fails' ' + export FAKE_LINES="reset:0 1" && + test_must_fail git rebase -i HEAD~1 && + unset FAKE_LINES && + git rebase --abort +' + +test_expect_success 'reset to HEAD is a nop' ' + test_tick && + head=$(git rev-parse --short HEAD) && + FAKE_LINES="reset$head" git rebase -i HEAD~4 && + test "$(git rev-parse --short HEAD)" = "$head" +' + test_expect_success 'preserve merges with -p' ' git checkout -b to-be-preserved master^ && : > unrelated-file &&
-- 1.5.5