Merge branch 'rr/rebase-checkout-reflog'
Invocations of "git checkout" used internally by "git rebase" were counted as "checkout", and affected later "git checkout -" to the the user to an unexpected place. * rr/rebase-checkout-reflog: checkout: respect GIT_REFLOG_ACTION status: do not depend on rebase reflog messages t/t2021-checkout-last: "checkout -" should work after a rebase finishes wt-status: remove unused field in grab_1st_switch_cbdata t7512: test "detached from" as well
This commit is contained in:
commit
6af984043f
@ -587,7 +587,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
|
|||||||
struct branch_info *new)
|
struct branch_info *new)
|
||||||
{
|
{
|
||||||
struct strbuf msg = STRBUF_INIT;
|
struct strbuf msg = STRBUF_INIT;
|
||||||
const char *old_desc;
|
const char *old_desc, *reflog_msg;
|
||||||
if (opts->new_branch) {
|
if (opts->new_branch) {
|
||||||
if (opts->new_orphan_branch) {
|
if (opts->new_orphan_branch) {
|
||||||
if (opts->new_branch_log && !log_all_ref_updates) {
|
if (opts->new_branch_log && !log_all_ref_updates) {
|
||||||
@ -620,8 +620,13 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
|
|||||||
old_desc = old->name;
|
old_desc = old->name;
|
||||||
if (!old_desc && old->commit)
|
if (!old_desc && old->commit)
|
||||||
old_desc = sha1_to_hex(old->commit->object.sha1);
|
old_desc = sha1_to_hex(old->commit->object.sha1);
|
||||||
|
|
||||||
|
reflog_msg = getenv("GIT_REFLOG_ACTION");
|
||||||
|
if (!reflog_msg)
|
||||||
strbuf_addf(&msg, "checkout: moving from %s to %s",
|
strbuf_addf(&msg, "checkout: moving from %s to %s",
|
||||||
old_desc ? old_desc : "(invalid)", new->name);
|
old_desc ? old_desc : "(invalid)", new->name);
|
||||||
|
else
|
||||||
|
strbuf_insert(&msg, 0, reflog_msg, strlen(reflog_msg));
|
||||||
|
|
||||||
if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
|
if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
|
||||||
/* Nothing to do. */
|
/* Nothing to do. */
|
||||||
|
@ -116,4 +116,38 @@ test_expect_success 'master...' '
|
|||||||
test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)"
|
test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)"
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success '"checkout -" works after a rebase A' '
|
||||||
|
git checkout master &&
|
||||||
|
git checkout other &&
|
||||||
|
git rebase master &&
|
||||||
|
git checkout - &&
|
||||||
|
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '"checkout -" works after a rebase A B' '
|
||||||
|
git branch moodle master~1 &&
|
||||||
|
git checkout master &&
|
||||||
|
git checkout other &&
|
||||||
|
git rebase master moodle &&
|
||||||
|
git checkout - &&
|
||||||
|
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '"checkout -" works after a rebase -i A' '
|
||||||
|
git checkout master &&
|
||||||
|
git checkout other &&
|
||||||
|
git rebase -i master &&
|
||||||
|
git checkout - &&
|
||||||
|
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '"checkout -" works after a rebase -i A B' '
|
||||||
|
git branch foodle master~1 &&
|
||||||
|
git checkout master &&
|
||||||
|
git checkout other &&
|
||||||
|
git rebase master foodle &&
|
||||||
|
git checkout - &&
|
||||||
|
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
@ -77,7 +77,7 @@ test_expect_success 'status when rebase in progress before resolving conflicts'
|
|||||||
ONTO=$(git rev-parse --short HEAD^^) &&
|
ONTO=$(git rev-parse --short HEAD^^) &&
|
||||||
test_must_fail git rebase HEAD^ --onto HEAD^^ &&
|
test_must_fail git rebase HEAD^ --onto HEAD^^ &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached at $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
|
# You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
|
||||||
# (fix conflicts and then run "git rebase --continue")
|
# (fix conflicts and then run "git rebase --continue")
|
||||||
# (use "git rebase --skip" to skip this patch)
|
# (use "git rebase --skip" to skip this patch)
|
||||||
@ -104,7 +104,7 @@ test_expect_success 'status when rebase in progress before rebase --continue' '
|
|||||||
echo three >main.txt &&
|
echo three >main.txt &&
|
||||||
git add main.txt &&
|
git add main.txt &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached at $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
|
# You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
|
||||||
# (all conflicts fixed: run "git rebase --continue")
|
# (all conflicts fixed: run "git rebase --continue")
|
||||||
#
|
#
|
||||||
@ -136,7 +136,7 @@ test_expect_success 'status during rebase -i when conflicts unresolved' '
|
|||||||
ONTO=$(git rev-parse --short rebase_i_conflicts) &&
|
ONTO=$(git rev-parse --short rebase_i_conflicts) &&
|
||||||
test_must_fail git rebase -i rebase_i_conflicts &&
|
test_must_fail git rebase -i rebase_i_conflicts &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached at $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
|
# You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
|
||||||
# (fix conflicts and then run "git rebase --continue")
|
# (fix conflicts and then run "git rebase --continue")
|
||||||
# (use "git rebase --skip" to skip this patch)
|
# (use "git rebase --skip" to skip this patch)
|
||||||
@ -162,7 +162,7 @@ test_expect_success 'status during rebase -i after resolving conflicts' '
|
|||||||
test_must_fail git rebase -i rebase_i_conflicts &&
|
test_must_fail git rebase -i rebase_i_conflicts &&
|
||||||
git add main.txt &&
|
git add main.txt &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached at $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
|
# You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
|
||||||
# (all conflicts fixed: run "git rebase --continue")
|
# (all conflicts fixed: run "git rebase --continue")
|
||||||
#
|
#
|
||||||
@ -188,10 +188,9 @@ test_expect_success 'status when rebasing -i in edit mode' '
|
|||||||
export FAKE_LINES &&
|
export FAKE_LINES &&
|
||||||
test_when_finished "git rebase --abort" &&
|
test_when_finished "git rebase --abort" &&
|
||||||
ONTO=$(git rev-parse --short HEAD~2) &&
|
ONTO=$(git rev-parse --short HEAD~2) &&
|
||||||
TGT=$(git rev-parse --short two_rebase_i) &&
|
|
||||||
git rebase -i HEAD~2 &&
|
git rebase -i HEAD~2 &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached from $TGT
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
|
# You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
|
||||||
# (use "git commit --amend" to amend the current commit)
|
# (use "git commit --amend" to amend the current commit)
|
||||||
# (use "git rebase --continue" once you are satisfied with your changes)
|
# (use "git rebase --continue" once you are satisfied with your changes)
|
||||||
@ -216,9 +215,8 @@ test_expect_success 'status when splitting a commit' '
|
|||||||
ONTO=$(git rev-parse --short HEAD~3) &&
|
ONTO=$(git rev-parse --short HEAD~3) &&
|
||||||
git rebase -i HEAD~3 &&
|
git rebase -i HEAD~3 &&
|
||||||
git reset HEAD^ &&
|
git reset HEAD^ &&
|
||||||
TGT=$(git rev-parse --short HEAD) &&
|
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached at $TGT
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
|
# You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
|
||||||
# (Once your working directory is clean, run "git rebase --continue")
|
# (Once your working directory is clean, run "git rebase --continue")
|
||||||
#
|
#
|
||||||
@ -246,11 +244,10 @@ test_expect_success 'status after editing the last commit with --amend during a
|
|||||||
export FAKE_LINES &&
|
export FAKE_LINES &&
|
||||||
test_when_finished "git rebase --abort" &&
|
test_when_finished "git rebase --abort" &&
|
||||||
ONTO=$(git rev-parse --short HEAD~3) &&
|
ONTO=$(git rev-parse --short HEAD~3) &&
|
||||||
TGT=$(git rev-parse --short three_amend) &&
|
|
||||||
git rebase -i HEAD~3 &&
|
git rebase -i HEAD~3 &&
|
||||||
git commit --amend -m "foo" &&
|
git commit --amend -m "foo" &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached from $TGT
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
|
# You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
|
||||||
# (use "git commit --amend" to amend the current commit)
|
# (use "git commit --amend" to amend the current commit)
|
||||||
# (use "git rebase --continue" once you are satisfied with your changes)
|
# (use "git rebase --continue" once you are satisfied with your changes)
|
||||||
@ -280,7 +277,7 @@ test_expect_success 'status: (continue first edit) second edit' '
|
|||||||
git rebase -i HEAD~3 &&
|
git rebase -i HEAD~3 &&
|
||||||
git rebase --continue &&
|
git rebase --continue &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached from $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
||||||
# (use "git commit --amend" to amend the current commit)
|
# (use "git commit --amend" to amend the current commit)
|
||||||
# (use "git rebase --continue" once you are satisfied with your changes)
|
# (use "git rebase --continue" once you are satisfied with your changes)
|
||||||
@ -302,7 +299,7 @@ test_expect_success 'status: (continue first edit) second edit and split' '
|
|||||||
git rebase --continue &&
|
git rebase --continue &&
|
||||||
git reset HEAD^ &&
|
git reset HEAD^ &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached from $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
||||||
# (Once your working directory is clean, run "git rebase --continue")
|
# (Once your working directory is clean, run "git rebase --continue")
|
||||||
#
|
#
|
||||||
@ -329,7 +326,7 @@ test_expect_success 'status: (continue first edit) second edit and amend' '
|
|||||||
git rebase --continue &&
|
git rebase --continue &&
|
||||||
git commit --amend -m "foo" &&
|
git commit --amend -m "foo" &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached from $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
||||||
# (use "git commit --amend" to amend the current commit)
|
# (use "git commit --amend" to amend the current commit)
|
||||||
# (use "git rebase --continue" once you are satisfied with your changes)
|
# (use "git rebase --continue" once you are satisfied with your changes)
|
||||||
@ -351,7 +348,7 @@ test_expect_success 'status: (amend first edit) second edit' '
|
|||||||
git commit --amend -m "a" &&
|
git commit --amend -m "a" &&
|
||||||
git rebase --continue &&
|
git rebase --continue &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached from $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
||||||
# (use "git commit --amend" to amend the current commit)
|
# (use "git commit --amend" to amend the current commit)
|
||||||
# (use "git rebase --continue" once you are satisfied with your changes)
|
# (use "git rebase --continue" once you are satisfied with your changes)
|
||||||
@ -374,7 +371,7 @@ test_expect_success 'status: (amend first edit) second edit and split' '
|
|||||||
git rebase --continue &&
|
git rebase --continue &&
|
||||||
git reset HEAD^ &&
|
git reset HEAD^ &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached from $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
||||||
# (Once your working directory is clean, run "git rebase --continue")
|
# (Once your working directory is clean, run "git rebase --continue")
|
||||||
#
|
#
|
||||||
@ -402,7 +399,7 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
|
|||||||
git rebase --continue &&
|
git rebase --continue &&
|
||||||
git commit --amend -m "d" &&
|
git commit --amend -m "d" &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached from $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
||||||
# (use "git commit --amend" to amend the current commit)
|
# (use "git commit --amend" to amend the current commit)
|
||||||
# (use "git rebase --continue" once you are satisfied with your changes)
|
# (use "git rebase --continue" once you are satisfied with your changes)
|
||||||
@ -426,7 +423,7 @@ test_expect_success 'status: (split first edit) second edit' '
|
|||||||
git commit -m "e" &&
|
git commit -m "e" &&
|
||||||
git rebase --continue &&
|
git rebase --continue &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached from $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
||||||
# (use "git commit --amend" to amend the current commit)
|
# (use "git commit --amend" to amend the current commit)
|
||||||
# (use "git rebase --continue" once you are satisfied with your changes)
|
# (use "git rebase --continue" once you are satisfied with your changes)
|
||||||
@ -451,7 +448,7 @@ test_expect_success 'status: (split first edit) second edit and split' '
|
|||||||
git rebase --continue &&
|
git rebase --continue &&
|
||||||
git reset HEAD^ &&
|
git reset HEAD^ &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached from $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
||||||
# (Once your working directory is clean, run "git rebase --continue")
|
# (Once your working directory is clean, run "git rebase --continue")
|
||||||
#
|
#
|
||||||
@ -481,7 +478,7 @@ test_expect_success 'status: (split first edit) second edit and amend' '
|
|||||||
git rebase --continue &&
|
git rebase --continue &&
|
||||||
git commit --amend -m "h" &&
|
git commit --amend -m "h" &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached from $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
|
||||||
# (use "git commit --amend" to amend the current commit)
|
# (use "git commit --amend" to amend the current commit)
|
||||||
# (use "git rebase --continue" once you are satisfied with your changes)
|
# (use "git rebase --continue" once you are satisfied with your changes)
|
||||||
@ -601,7 +598,7 @@ test_expect_success 'status when rebase conflicts with statushints disabled' '
|
|||||||
ONTO=$(git rev-parse --short HEAD^^) &&
|
ONTO=$(git rev-parse --short HEAD^^) &&
|
||||||
test_must_fail git rebase HEAD^ --onto HEAD^^ &&
|
test_must_fail git rebase HEAD^ --onto HEAD^^ &&
|
||||||
cat >expected <<-EOF &&
|
cat >expected <<-EOF &&
|
||||||
# HEAD detached at $ONTO
|
# rebase in progress; onto $ONTO
|
||||||
# You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
|
# You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
|
||||||
#
|
#
|
||||||
# Unmerged paths:
|
# Unmerged paths:
|
||||||
@ -669,7 +666,7 @@ test_expect_success 'status when cherry-picking after resolving conflicts' '
|
|||||||
test_i18ncmp expected actual
|
test_i18ncmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'status showing detached from a tag' '
|
test_expect_success 'status showing detached at and from a tag' '
|
||||||
test_commit atag tagging &&
|
test_commit atag tagging &&
|
||||||
git checkout atag &&
|
git checkout atag &&
|
||||||
cat >expected <<-\EOF
|
cat >expected <<-\EOF
|
||||||
@ -677,6 +674,14 @@ test_expect_success 'status showing detached from a tag' '
|
|||||||
nothing to commit (use -u to show untracked files)
|
nothing to commit (use -u to show untracked files)
|
||||||
EOF
|
EOF
|
||||||
git status --untracked-files=no >actual &&
|
git status --untracked-files=no >actual &&
|
||||||
|
test_i18ncmp expected actual &&
|
||||||
|
|
||||||
|
git reset --hard HEAD^ &&
|
||||||
|
cat >expected <<-\EOF
|
||||||
|
# HEAD detached from atag
|
||||||
|
nothing to commit (use -u to show untracked files)
|
||||||
|
EOF
|
||||||
|
git status --untracked-files=no >actual &&
|
||||||
test_i18ncmp expected actual
|
test_i18ncmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -1037,7 +1037,6 @@ got_nothing:
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct grab_1st_switch_cbdata {
|
struct grab_1st_switch_cbdata {
|
||||||
int found;
|
|
||||||
struct strbuf buf;
|
struct strbuf buf;
|
||||||
unsigned char nsha1[20];
|
unsigned char nsha1[20];
|
||||||
};
|
};
|
||||||
@ -1061,7 +1060,6 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
|
|||||||
for (end = target; *end && *end != '\n'; end++)
|
for (end = target; *end && *end != '\n'; end++)
|
||||||
;
|
;
|
||||||
strbuf_add(&cb->buf, target, end - target);
|
strbuf_add(&cb->buf, target, end - target);
|
||||||
cb->found = 1;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1178,7 +1176,10 @@ void wt_status_print(struct wt_status *s)
|
|||||||
branch_name += 11;
|
branch_name += 11;
|
||||||
else if (!strcmp(branch_name, "HEAD")) {
|
else if (!strcmp(branch_name, "HEAD")) {
|
||||||
branch_status_color = color(WT_STATUS_NOBRANCH, s);
|
branch_status_color = color(WT_STATUS_NOBRANCH, s);
|
||||||
if (state.detached_from) {
|
if (state.rebase_in_progress || state.rebase_interactive_in_progress) {
|
||||||
|
on_what = _("rebase in progress; onto ");
|
||||||
|
branch_name = state.onto;
|
||||||
|
} else if (state.detached_from) {
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
branch_name = state.detached_from;
|
branch_name = state.detached_from;
|
||||||
if (!get_sha1("HEAD", sha1) &&
|
if (!get_sha1("HEAD", sha1) &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user