From: Junio C Hamano Date: Tue, 27 Feb 2018 18:33:57 +0000 (-0800) Subject: Merge branch 'sb/describe-blob' X-Git-Tag: v2.17.0-rc0~70 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/1ba6846a19b0358ddf4098d44ba5804646c36412?ds=inline;hp=-c Merge branch 'sb/describe-blob' "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 --- 1ba6846a19b0358ddf4098d44ba5804646c36412 diff --combined builtin/describe.c index c428984706,1e7ba09693..e4869df7b4 --- a/builtin/describe.c +++ b/builtin/describe.c @@@ -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, @@@ -624,13 -618,8 +624,13 @@@ 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 a5d9015024,50029ff6a8..bae78c4e89 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@@ -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