Merge branch 'sb/describe-blob' into next
authorJunio C Hamano <gitster@pobox.com>
Wed, 14 Feb 2018 21:34:32 +0000 (13:34 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Feb 2018 21:34:32 +0000 (13:34 -0800)
"git describe $garbage" stopped giving any errors when the garbage
happens to be a string with 40 hexadecimal letters.

* sb/describe-blob:
describe: confirm that blobs actually exist

1  2 
builtin/describe.c
t/t6120-describe.sh
diff --combined builtin/describe.c
index c4289847063ac02ed061f890ffd71cd329d67109,1e7ba0969328350abada01dd1f929e55f531ff04..e4869df7b434845544dfcc0c37cae6a77cd42dad
@@@ -8,7 -8,6 +8,7 @@@
  #include "builtin.h"
  #include "exec_cmd.h"
  #include "parse-options.h"
 +#include "revision.h"
  #include "diff.h"
  #include "hashmap.h"
  #include "argv-array.h"
@@@ -184,7 -183,7 +184,7 @@@ static int get_name(const char *path, c
        }
  
        /* Is it annotated? */
 -      if (!peel_ref(path, peeled.hash)) {
 +      if (!peel_ref(path, &peeled)) {
                is_annotated = !!oidcmp(oid, &peeled);
        } else {
                oidcpy(&peeled, oid);
@@@ -274,13 -273,10 +274,13 @@@ static void append_name(struct commit_n
                n->name_checked = 1;
        }
  
 -      if (n->tag)
 +      if (n->tag) {
 +              if (all)
 +                      strbuf_addstr(dst, "tags/");
                strbuf_addstr(dst, n->tag->tag);
 -      else
 +      } else {
                strbuf_addstr(dst, n->path);
 +      }
  }
  
  static void append_suffix(int depth, const struct object_id *oid, struct strbuf *dst)
@@@ -383,7 -379,7 +383,7 @@@ static void describe_commit(struct obje
        if (!match_cnt) {
                struct object_id *cmit_oid = &cmit->object.oid;
                if (always) {
 -                      strbuf_addstr(dst, find_unique_abbrev(cmit_oid->hash, abbrev));
 +                      strbuf_add_unique_abbrev(dst, cmit_oid->hash, abbrev);
                        if (suffix)
                                strbuf_addstr(dst, suffix);
                        return;
@@@ -502,7 -498,7 +502,7 @@@ static void describe(const char *arg, i
  
        if (cmit)
                describe_commit(&oid, &sb);
-       else if (lookup_blob(&oid))
+       else if (sha1_object_info(oid.hash, NULL) == OBJ_BLOB)
                describe_blob(oid, &sb);
        else
                die(_("%s is neither a commit nor blob"), arg);
@@@ -613,9 -609,7 +613,9 @@@ int cmd_describe(int argc, const char *
                        }
                } else if (dirty) {
                        static struct lock_file index_lock;
 -                      int fd;
 +                      struct rev_info revs;
 +                      struct argv_array args = ARGV_ARRAY_INIT;
 +                      int fd, result;
  
                        read_cache_preload(NULL);
                        refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
                        if (0 <= fd)
                                update_index_if_able(&the_index, &index_lock);
  
 -                      if (!cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1,
 -                                          diff_index_args, prefix))
 +                      init_revisions(&revs, prefix);
 +                      argv_array_pushv(&args, diff_index_args);
 +                      if (setup_revisions(args.argc, args.argv, &revs, NULL) != 1)
 +                              BUG("malformed internal diff-index command line");
 +                      result = run_diff_index(&revs, 0);
 +
 +                      if (!diff_result_code(&revs.diffopt, result))
                                suffix = NULL;
                        else
                                suffix = dirty;
diff --combined t/t6120-describe.sh
index a5d901502414f25616a474152ee0f5816465bd37,50029ff6a8df6c0e11a3f5dea75905062e088b97..bae78c4e89e2402d5ab37e3b7cd094dde41d69b3
@@@ -122,7 -122,7 +122,7 @@@ test_expect_success 'describe --contain
  '
  
  : >err.expect
 -check_describe A --all A^0
 +check_describe tags/A --all A^0
  test_expect_success 'no warning was displayed for A' '
        test_cmp err.expect err.actual
  '
@@@ -374,8 -374,12 +374,16 @@@ test_expect_success ULIMIT_STACK_SIZE '
        test_cmp expect actual
  '
  
 +check_describe tags/A --all A
 +check_describe tags/c --all c
 +check_describe heads/branch_A --all --match='branch_*' branch_A
 +
+ test_expect_success 'describe complains about tree object' '
+       test_must_fail git describe HEAD^{tree}
+ '
+ test_expect_success 'describe complains about missing object' '
+       test_must_fail git describe $_z40
+ '
  test_done