mirror of
https://github.com/git/git.git
synced 2024-11-25 10:54:00 +08:00
rebase -i: work on a detached HEAD
Earlier, rebase -i refused to rebase a detached HEAD. Now it no longer does. Incidentally, this fixes "git gc --auto" shadowing the true exit status. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
61ab92df40
commit
73697a0b57
@ -317,17 +317,20 @@ do_next () {
|
||||
else
|
||||
NEWHEAD=$(git rev-parse HEAD)
|
||||
fi &&
|
||||
message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO)" &&
|
||||
git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
|
||||
git symbolic-ref HEAD $HEADNAME && {
|
||||
case $HEADNAME in
|
||||
refs/*)
|
||||
message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO)" &&
|
||||
git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
|
||||
git symbolic-ref HEAD $HEADNAME
|
||||
;;
|
||||
esac && {
|
||||
test ! -f "$DOTEST"/verbose ||
|
||||
git diff --stat $(cat "$DOTEST"/head)..HEAD
|
||||
} &&
|
||||
rm -rf "$DOTEST" &&
|
||||
git gc --auto &&
|
||||
warn "Successfully rebased and updated $HEADNAME."
|
||||
|
||||
git gc --auto
|
||||
|
||||
exit
|
||||
}
|
||||
|
||||
@ -367,7 +370,11 @@ do
|
||||
|
||||
HEADNAME=$(cat "$DOTEST"/head-name)
|
||||
HEAD=$(cat "$DOTEST"/head)
|
||||
git symbolic-ref HEAD $HEADNAME &&
|
||||
case $HEADNAME in
|
||||
refs/*)
|
||||
git symbolic-ref HEAD $HEADNAME
|
||||
;;
|
||||
esac &&
|
||||
output git reset --hard $HEAD &&
|
||||
rm -rf "$DOTEST"
|
||||
exit
|
||||
@ -445,8 +452,8 @@ do
|
||||
test -z "$ONTO" && ONTO=$UPSTREAM
|
||||
|
||||
: > "$DOTEST"/interactive || die "Could not mark as interactive"
|
||||
git symbolic-ref HEAD > "$DOTEST"/head-name ||
|
||||
die "Could not get HEAD"
|
||||
git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
|
||||
echo "detached HEAD" > "$DOTEST"/head-name
|
||||
|
||||
echo $HEAD > "$DOTEST"/head
|
||||
echo $UPSTREAM > "$DOTEST"/upstream
|
||||
|
@ -309,4 +309,12 @@ test_expect_success '--continue tries to commit, even for "edit"' '
|
||||
test $parent = $(git rev-parse HEAD^)
|
||||
'
|
||||
|
||||
test_expect_success 'rebase a detached HEAD' '
|
||||
grandparent=$(git rev-parse HEAD~2) &&
|
||||
git checkout $(git rev-parse HEAD) &&
|
||||
test_tick &&
|
||||
FAKE_LINES="2 1" git rebase -i HEAD~2 &&
|
||||
test $grandparent = $(git rev-parse HEAD~2)
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Loading…
Reference in New Issue
Block a user