@matheusbsbs / matheus-bagliano / commits / 2bb98169be
Fork 0

for-each-ref: utilize core.warnAmbiguousRefs for :short-format

core.warnAmbiguousRefs is used to select strict mode for the abbreviation for the ":short" format specifier of "refname" and "upstream". In strict mode, the abbreviated ref will never trigger the 'warn_ambiguous_refs' warning. I.e. for these refs: refs/heads/xyzzy refs/tags/xyzzy the abbreviated forms are: heads/xyzzy tags/xyzzy Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Bert Wesarg committed Apr 13, 2009 at 12:25 UTC 2bb98169be7b0ac4f70815b4490904c652edae61
3 files changed +22 -4
Documentation/git-for-each-ref.txt
+2
@@ -75,6 +75,8 @@ For all objects, the following names can be used:
75 refname::
76 The name of the ref (the part after $GIT_DIR/).
77 For a non-ambiguous short name of the ref append `:short`.
78 + The option core.warnAmbiguousRefs is used to select the strict
79 + abbreviation mode.
80
81 objecttype::
82 The type of the object (`blob`, `tree`, `commit`, `tag`).
builtin-for-each-ref.c
+5 -1
@@ -601,7 +601,8 @@ static void populate_value(struct refinfo *ref)
601 if (formatp) {
602 formatp++;
603 if (!strcmp(formatp, "short"))
604 - refname = shorten_unambiguous_ref(refname, 0);
604 + refname = shorten_unambiguous_ref(refname,
605 + warn_ambiguous_refs);
606 else
607 die("unknown %.*s format %s",
608 (int)(formatp - name), name, formatp);
@@ -917,6 +918,9 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
918 sort = default_sort();
919 sort_atom_limit = used_atom_cnt;
920
921 + /* for warn_ambiguous_refs */
922 + git_config(git_default_config, NULL);
923 +
924 memset(&cbdata, 0, sizeof(cbdata));
925 cbdata.grab_pattern = argv;
926 for_each_ref(grab_single_ref, &cbdata);
t/t6300-for-each-ref.sh
+15 -3
@@ -301,10 +301,11 @@ test_expect_success 'Check for invalid refname format' '
301
302 cat >expected <<\EOF
303 heads/master
304 -master
304 +tags/master
305 EOF
306
307 -test_expect_success 'Check ambiguous head and tag refs' '
307 +test_expect_success 'Check ambiguous head and tag refs (strict)' '
308 + git config --bool core.warnambiguousrefs true &&
309 git checkout -b newtag &&
310 echo "Using $datestamp" > one &&
311 git add one &&
@@ -315,12 +316,23 @@ test_expect_success 'Check ambiguous head and tag refs' '
316 test_cmp expected actual
317 '
318
319 +cat >expected <<\EOF
320 +heads/master
321 +master
322 +EOF
323 +
324 +test_expect_success 'Check ambiguous head and tag refs (loose)' '
325 + git config --bool core.warnambiguousrefs false &&
326 + git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
327 + test_cmp expected actual
328 +'
329 +
330 cat >expected <<\EOF
331 heads/ambiguous
332 ambiguous
333 EOF
334
323 -test_expect_success 'Check ambiguous head and tag refs II' '
335 +test_expect_success 'Check ambiguous head and tag refs II (loose)' '
336 git checkout master &&
337 git tag ambiguous testtag^0 &&
338 git branch ambiguous testtag^0 &&