Merge branch 'rr/die-on-missing-upstream' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 3 Jul 2013 22:30:24 +0000 (15:30 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Jul 2013 22:30:24 +0000 (15:30 -0700)
When a reflog notation is used for implicit "current branch", we did
not say which branch, and worse said "branch ''".

* rr/die-on-missing-upstream:
sha1_name: fix error message for @{<N>}, @{<date>}
sha1_name: fix error message for @{u}

1  2 
sha1_name.c
diff --combined sha1_name.c
index 371a49d98d27098753016e23fa8a379ed7b72176,01b36ead42c2c7d22550c83061e8ff17b91720f6..b3a90e6f051e8b75458055144829ea72bbe29970
@@@ -517,12 -517,21 +517,21 @@@ static int get_sha1_basic(const char *s
                }
                if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
                                &co_time, &co_tz, &co_cnt)) {
+                       if (!len) {
+                               if (!prefixcmp(real_ref, "refs/heads/")) {
+                                       str = real_ref + 11;
+                                       len = strlen(real_ref + 11);
+                               } else {
+                                       /* detached HEAD */
+                                       str = "HEAD";
+                                       len = 4;
+                               }
+                       }
                        if (at_time)
                                warning("Log for '%.*s' only goes "
                                        "back to %s.", len, str,
                                        show_date(co_time, co_tz, DATE_RFC2822));
                        else {
-                               free(real_ref);
                                die("Log for '%.*s' only has %d entries.",
                                    len, str, co_cnt);
                        }
@@@ -1033,14 -1042,15 +1042,15 @@@ int interpret_branch_name(const char *n
         * points to something different than a branch.
         */
        if (!upstream)
-               return error(_("HEAD does not point to a branch"));
+               die(_("HEAD does not point to a branch"));
        if (!upstream->merge || !upstream->merge[0]->dst) {
                if (!ref_exists(upstream->refname))
-                       return error(_("No such branch: '%s'"), cp);
-               if (!upstream->merge)
-                       return error(_("No upstream configured for branch '%s'"),
-                                    upstream->name);
-               return error(
+                       die(_("No such branch: '%s'"), cp);
+               if (!upstream->merge) {
+                       die(_("No upstream configured for branch '%s'"),
+                               upstream->name);
+               }
+               die(
                        _("Upstream branch '%s' not stored as a remote-tracking branch"),
                        upstream->merge[0]->src);
        }
  int strbuf_branchname(struct strbuf *sb, const char *name)
  {
        int len = strlen(name);
 -      if (interpret_branch_name(name, sb) == len)
 +      int used = interpret_branch_name(name, sb);
 +
 +      if (used == len)
                return 0;
 -      strbuf_add(sb, name, len);
 +      if (used < 0)
 +              used = 0;
 +      strbuf_add(sb, name + used, len - used);
        return len;
  }