Merge branch 'rr/rebase-checkout-reflog'
authorJunio C Hamano <gitster@pobox.com>
Thu, 11 Jul 2013 20:04:33 +0000 (13:04 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Jul 2013 20:04:33 +0000 (13:04 -0700)
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

1  2 
builtin/checkout.c
t/t7512-status-help.sh
wt-status.c
diff --combined builtin/checkout.c
index 3be00188216f503ea1f9269acd312aebdb72a0fa,79f4495a2d08fb35d320454b3eb026f553286cb4..7fe0bffaf8b875b40b5e4e0e5c207f978c932691
@@@ -587,7 -587,7 +587,7 @@@ static void update_refs_for_switch(cons
                                   struct branch_info *new)
  {
        struct strbuf msg = STRBUF_INIT;
-       const char *old_desc;
+       const char *old_desc, *reflog_msg;
        if (opts->new_branch) {
                if (opts->new_orphan_branch) {
                        if (opts->new_branch_log && !log_all_ref_updates) {
        old_desc = old->name;
        if (!old_desc && old->commit)
                old_desc = sha1_to_hex(old->commit->object.sha1);
-       strbuf_addf(&msg, "checkout: moving from %s to %s",
-                   old_desc ? old_desc : "(invalid)", new->name);
+       reflog_msg = getenv("GIT_REFLOG_ACTION");
+       if (!reflog_msg)
+               strbuf_addf(&msg, "checkout: moving from %s to %s",
+                       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) {
                /* Nothing to do. */
@@@ -825,43 -830,38 +830,43 @@@ static int git_checkout_config(const ch
  }
  
  struct tracking_name_data {
 -      const char *name;
 -      char *remote;
 +      /* const */ char *src_ref;
 +      char *dst_ref;
 +      unsigned char *dst_sha1;
        int unique;
  };
  
 -static int check_tracking_name(const char *refname, const unsigned char *sha1,
 -                             int flags, void *cb_data)
 +static int check_tracking_name(struct remote *remote, void *cb_data)
  {
        struct tracking_name_data *cb = cb_data;
 -      const char *slash;
 -
 -      if (prefixcmp(refname, "refs/remotes/"))
 -              return 0;
 -      slash = strchr(refname + 13, '/');
 -      if (!slash || strcmp(slash + 1, cb->name))
 +      struct refspec query;
 +      memset(&query, 0, sizeof(struct refspec));
 +      query.src = cb->src_ref;
 +      if (remote_find_tracking(remote, &query) ||
 +          get_sha1(query.dst, cb->dst_sha1)) {
 +              free(query.dst);
                return 0;
 -      if (cb->remote) {
 +      }
 +      if (cb->dst_ref) {
 +              free(query.dst);
                cb->unique = 0;
                return 0;
        }
 -      cb->remote = xstrdup(refname);
 +      cb->dst_ref = query.dst;
        return 0;
  }
  
 -static const char *unique_tracking_name(const char *name)
 +static const char *unique_tracking_name(const char *name, unsigned char *sha1)
  {
 -      struct tracking_name_data cb_data = { NULL, NULL, 1 };
 -      cb_data.name = name;
 -      for_each_ref(check_tracking_name, &cb_data);
 +      struct tracking_name_data cb_data = { NULL, NULL, NULL, 1 };
 +      char src_ref[PATH_MAX];
 +      snprintf(src_ref, PATH_MAX, "refs/heads/%s", name);
 +      cb_data.src_ref = src_ref;
 +      cb_data.dst_sha1 = sha1;
 +      for_each_remote(check_tracking_name, &cb_data);
        if (cb_data.unique)
 -              return cb_data.remote;
 -      free(cb_data.remote);
 +              return cb_data.dst_ref;
 +      free(cb_data.dst_ref);
        return NULL;
  }
  
@@@ -924,8 -924,8 +929,8 @@@ static int parse_branchname_arg(int arg
                if (dwim_new_local_branch_ok &&
                    !check_filename(NULL, arg) &&
                    argc == 1) {
 -                      const char *remote = unique_tracking_name(arg);
 -                      if (!remote || get_sha1(remote, rev))
 +                      const char *remote = unique_tracking_name(arg, rev);
 +                      if (!remote)
                                return argcount;
                        *new_branch = arg;
                        arg = remote;
diff --combined t/t7512-status-help.sh
index bd8aab0a5c4f47f76d08712d406eae4efa6adae5,d6c66d73ab8fe96a723accbe9b7aac1d2d93f990..31a798fda21f178cbbedf47ee92dbd997f9c4e42
@@@ -77,7 -77,7 +77,7 @@@ test_expect_success 'status when rebas
        ONTO=$(git rev-parse --short HEAD^^) &&
        test_must_fail git rebase HEAD^ --onto HEAD^^ &&
        cat >expected <<-EOF &&
-       # HEAD detached at $ONTO
+       # rebase in progress; onto $ONTO
        # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
        #   (fix conflicts and then run "git rebase --continue")
        #   (use "git rebase --skip" to skip this patch)
@@@ -104,7 -104,7 +104,7 @@@ test_expect_success 'status when rebas
        echo three >main.txt &&
        git add main.txt &&
        cat >expected <<-EOF &&
-       # HEAD detached at $ONTO
+       # rebase in progress; onto $ONTO
        # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
        #   (all conflicts fixed: run "git rebase --continue")
        #
@@@ -136,7 -136,7 +136,7 @@@ test_expect_success 'status during reba
        ONTO=$(git rev-parse --short rebase_i_conflicts) &&
        test_must_fail git rebase -i rebase_i_conflicts &&
        cat >expected <<-EOF &&
-       # HEAD detached at $ONTO
+       # rebase in progress; onto $ONTO
        # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
        #   (fix conflicts and then run "git rebase --continue")
        #   (use "git rebase --skip" to skip this patch)
@@@ -162,7 -162,7 +162,7 @@@ test_expect_success 'status during reba
        test_must_fail git rebase -i rebase_i_conflicts &&
        git add main.txt &&
        cat >expected <<-EOF &&
-       # HEAD detached at $ONTO
+       # rebase in progress; onto $ONTO
        # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
        #   (all conflicts fixed: run "git rebase --continue")
        #
@@@ -188,10 -188,9 +188,9 @@@ test_expect_success 'status when rebasi
        export FAKE_LINES &&
        test_when_finished "git rebase --abort" &&
        ONTO=$(git rev-parse --short HEAD~2) &&
-       TGT=$(git rev-parse --short two_rebase_i) &&
        git rebase -i HEAD~2 &&
        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'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@@ -216,9 -215,8 +215,8 @@@ test_expect_success 'status when splitt
        ONTO=$(git rev-parse --short HEAD~3) &&
        git rebase -i HEAD~3 &&
        git reset HEAD^ &&
-       TGT=$(git rev-parse --short HEAD) &&
        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'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
@@@ -246,11 -244,10 +244,10 @@@ test_expect_success 'status after editi
        export FAKE_LINES &&
        test_when_finished "git rebase --abort" &&
        ONTO=$(git rev-parse --short HEAD~3) &&
-       TGT=$(git rev-parse --short three_amend) &&
        git rebase -i HEAD~3 &&
        git commit --amend -m "foo" &&
        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'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@@ -280,7 -277,7 +277,7 @@@ test_expect_success 'status: (continue 
        git rebase -i HEAD~3 &&
        git rebase --continue &&
        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'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@@ -302,7 -299,7 +299,7 @@@ test_expect_success 'status: (continue 
        git rebase --continue &&
        git reset HEAD^ &&
        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'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
@@@ -329,7 -326,7 +326,7 @@@ test_expect_success 'status: (continue 
        git rebase --continue &&
        git commit --amend -m "foo" &&
        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'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@@ -351,7 -348,7 +348,7 @@@ test_expect_success 'status: (amend fir
        git commit --amend -m "a" &&
        git rebase --continue &&
        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'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@@ -374,7 -371,7 +371,7 @@@ test_expect_success 'status: (amend fir
        git rebase --continue &&
        git reset HEAD^ &&
        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'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
@@@ -402,7 -399,7 +399,7 @@@ test_expect_success 'status: (amend fir
        git rebase --continue &&
        git commit --amend -m "d" &&
        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'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@@ -426,7 -423,7 +423,7 @@@ test_expect_success 'status: (split fir
        git commit -m "e" &&
        git rebase --continue &&
        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'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@@ -451,7 -448,7 +448,7 @@@ test_expect_success 'status: (split fir
        git rebase --continue &&
        git reset HEAD^ &&
        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'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
@@@ -481,7 -478,7 +478,7 @@@ test_expect_success 'status: (split fir
        git rebase --continue &&
        git commit --amend -m "h" &&
        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'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@@ -510,7 -507,7 +507,7 @@@ test_expect_success 'status in an am se
        cat >expected <<-\EOF &&
        # On branch am_already_exists
        # You are in the middle of an am session.
 -      #   (fix conflicts and then run "git am --resolved")
 +      #   (fix conflicts and then run "git am --continue")
        #   (use "git am --skip" to skip this patch)
        #   (use "git am --abort" to restore the original branch)
        #
@@@ -532,7 -529,7 +529,7 @@@ test_expect_success 'status in an am se
        cat >expected <<-\EOF &&
        # On branch am_not_exists
        # You are in the middle of an am session.
 -      #   (fix conflicts and then run "git am --resolved")
 +      #   (fix conflicts and then run "git am --continue")
        #   (use "git am --skip" to skip this patch)
        #   (use "git am --abort" to restore the original branch)
        #
@@@ -601,7 -598,7 +598,7 @@@ test_expect_success 'status when rebas
        ONTO=$(git rev-parse --short HEAD^^) &&
        test_must_fail git rebase HEAD^ --onto HEAD^^ &&
        cat >expected <<-EOF &&
-       # HEAD detached at $ONTO
+       # rebase in progress; onto $ONTO
        # You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
        #
        # Unmerged paths:
@@@ -632,8 -629,7 +629,8 @@@ test_expect_success 'status when cherry
        cat >expected <<-\EOF &&
        # On branch cherry_branch
        # You are currently cherry-picking.
 -      #   (fix conflicts and run "git commit")
 +      #   (fix conflicts and run "git cherry-pick --continue")
 +      #   (use "git cherry-pick --abort" to cancel the cherry-pick operation)
        #
        # Unmerged paths:
        #   (use "git add <file>..." to mark resolution)
@@@ -656,8 -652,7 +653,8 @@@ test_expect_success 'status when cherry
        cat >expected <<-\EOF &&
        # On branch cherry_branch
        # You are currently cherry-picking.
 -      #   (all conflicts fixed: run "git commit")
 +      #   (all conflicts fixed: run "git cherry-pick --continue")
 +      #   (use "git cherry-pick --abort" to cancel the cherry-pick operation)
        #
        # Changes to be committed:
        #
        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 &&
        git checkout atag &&
        cat >expected <<-\EOF
        nothing to commit (use -u to show untracked files)
        EOF
        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
  '
  
diff --combined wt-status.c
index b191c65382b0714978fe1a6351639ed746db099f,85a00f12fded56369111d9462f0fba0b03980003..72db2900b407239dba0ce426818a69fa1835f47e
@@@ -826,7 -826,7 +826,7 @@@ static void show_am_in_progress(struct 
        if (advice_status_hints) {
                if (!state->am_empty_patch)
                        status_printf_ln(s, color,
 -                              _("  (fix conflicts and then run \"git am --resolved\")"));
 +                              _("  (fix conflicts and then run \"git am --continue\")"));
                status_printf_ln(s, color,
                        _("  (use \"git am --skip\" to skip this patch)"));
                status_printf_ln(s, color,
@@@ -955,12 -955,10 +955,12 @@@ static void show_cherry_pick_in_progres
        if (advice_status_hints) {
                if (has_unmerged(s))
                        status_printf_ln(s, color,
 -                              _("  (fix conflicts and run \"git commit\")"));
 +                              _("  (fix conflicts and run \"git cherry-pick --continue\")"));
                else
                        status_printf_ln(s, color,
 -                              _("  (all conflicts fixed: run \"git commit\")"));
 +                              _("  (all conflicts fixed: run \"git cherry-pick --continue\")"));
 +              status_printf_ln(s, color,
 +                      _("  (use \"git cherry-pick --abort\" to cancel the cherry-pick operation)"));
        }
        wt_status_print_trailer(s);
  }
@@@ -1037,7 -1035,6 +1037,6 @@@ got_nothing
  }
  
  struct grab_1st_switch_cbdata {
-       int found;
        struct strbuf buf;
        unsigned char nsha1[20];
  };
@@@ -1061,7 -1058,6 +1060,6 @@@ static int grab_1st_switch(unsigned cha
        for (end = target; *end && *end != '\n'; end++)
                ;
        strbuf_add(&cb->buf, target, end - target);
-       cb->found = 1;
        return 1;
  }
  
@@@ -1178,7 -1174,10 +1176,10 @@@ void wt_status_print(struct wt_status *
                        branch_name += 11;
                else if (!strcmp(branch_name, "HEAD")) {
                        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];
                                branch_name = state.detached_from;
                                if (!get_sha1("HEAD", sha1) &&