sha1_name: do not trigger detailed diagnosis for file arguments
authorMatthieu Moy <Matthieu.Moy@imag.fr>
Mon, 18 Jun 2012 18:18:20 +0000 (20:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 18 Jun 2012 22:13:16 +0000 (15:13 -0700)
diagnose_invalid_sha1_path() is meant to be called to diagnose a
misspelt <treeish>:<pathname> when <pathname> does not exist in
<treeish>.  However, the code may call it if <treeish>:<pathname> is
invalid (which triggers another call with only_to_die == 1), but for
another reason. This happens when calling e.g.

  git log existing-file HEAD:existing-file

because existing-file is a path and not a revision, the code
verifies that the arguments that follow to be paths.  This leads to
an incorrect message like "existing-file does not exist in HEAD",
even though the path exists in HEAD.

Check that the search for <pathname> in <treeish> fails before
triggering the diagnosis.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_name.c
t/t1506-rev-parse-diagnosis.sh

index 03ffc2caaa6524a3361bc47a89e101ced2f0e987..aff224b2a0cbc955b05eb67119bf5b15d05e2d64 100644 (file)
@@ -1115,7 +1115,7 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
                        if (new_filename)
                                filename = new_filename;
                        ret = get_tree_entry(tree_sha1, filename, sha1, &oc->mode);
-                       if (only_to_die) {
+                       if (ret && only_to_die) {
                                diagnose_invalid_sha1_path(prefix, filename,
                                                           tree_sha1, object_name);
                                free(object_name);
index 0843a1c13b3e1458418ee59c548e5441f113bbe7..e81dcd6de6639227e5e74a978aa193286e449ec8 100755 (executable)
@@ -171,4 +171,15 @@ test_expect_success 'relative path when startup_info is NULL' '
        grep "BUG: startup_info struct is not initialized." error
 '
 
+test_expect_success '<commit>:file correctly diagnosed after a pathname' '
+       test_must_fail git rev-parse file.txt HEAD:file.txt 1>actual 2>error &&
+       test_i18ngrep ! "exists on disk" error &&
+       test_i18ngrep "unknown revision or path not in the working tree" error &&
+       cat >expect <<-\EOF &&
+       file.txt
+       HEAD:file.txt
+       EOF
+       test_cmp expect actual
+'
+
 test_done