{"thread":{"id":"59402","subject":"[PATCH] object-name: fix quiet @{u} parsing","startedAt":"2023-03-16T17:15:19Z","lastAt":"2023-03-16T17:44:30Z","messageCount":2,"participants":["Felipe Contreras","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"473598","messageId":"20230316171514.23741-1-felipe.contreras@gmail.com","threadId":"59402","inReplyTo":null,"subject":"[PATCH] object-name: fix quiet @{u} parsing","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-03-16T17:15:14Z","receivedAt":"2023-03-16T17:15:19Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Currently `git rev-parse --quiet @{u}` is not actually quiet when\nupstream isn't configured:\n\n  fatal: no upstream configured for branch 'foo'\n\nMake it so.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n object-name.c                 | 5 +++--\n t/t1507-rev-parse-upstream.sh | 5 +++++\n 2 files changed, 8 insertions(+), 2 deletions(-)\n\ndiff --git a/object-name.c b/object-name.c\nindex 2dd1a0f56e..d9f3a176d8 100644\n--- a/object-name.c\n+++ b/object-name.c\n@@ -898,6 +898,7 @@ static int get_oid_basic(struct repository *r, const char *str, int len,\n \tchar *real_ref = NULL;\n \tint refs_found = 0;\n \tint at, reflog_len, nth_prior = 0;\n+\tint fatal = !(flags & GET_OID_QUIETLY);\n \n \tif (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {\n \t\tif (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {\n@@ -952,11 +953,11 @@ static int get_oid_basic(struct repository *r, const char *str, int len,\n \n \tif (!len && reflog_len)\n \t\t/* allow \"@{...}\" to mean the current branch reflog */\n-\t\trefs_found = repo_dwim_ref(r, \"HEAD\", 4, oid, &real_ref, 0);\n+\t\trefs_found = repo_dwim_ref(r, \"HEAD\", 4, oid, &real_ref, !fatal);\n \telse if (reflog_len)\n \t\trefs_found = repo_dwim_log(r, str, len, oid, &real_ref);\n \telse\n-\t\trefs_found = repo_dwim_ref(r, str, len, oid, &real_ref, 0);\n+\t\trefs_found = repo_dwim_ref(r, str, len, oid, &real_ref, !fatal);\n \n \tif (!refs_found)\n \t\treturn -1;\ndiff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh\nindex c34714ffe3..549eb315a9 100755\n--- a/t/t1507-rev-parse-upstream.sh\n+++ b/t/t1507-rev-parse-upstream.sh\n@@ -183,6 +183,11 @@ test_expect_success '@{u} error message when no upstream' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success '@{u} silent error when no upstream' '\n+\ttest_must_fail git rev-parse --verify --quiet @{u} 2>actual &&\n+\ttest_must_be_empty actual\n+'\n+\n test_expect_success 'branch@{u} error message with misspelt branch' '\n \tcat >expect <<-EOF &&\n \tfatal: no such branch: ${SQ}no-such-branch${SQ}\n-- \n2.39.2.13.g1fb56cf030\n\n"},{"id":"473602","messageId":"xmqqfsa4lhgk.fsf@gitster.g","threadId":"59402","inReplyTo":"20230316171514.23741-1-felipe.contreras@gmail.com","subject":"Re: [PATCH] object-name: fix quiet @{u} parsing","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-03-16T17:43:55Z","receivedAt":"2023-03-16T17:44:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> Currently `git rev-parse --quiet @{u}` is not actually quiet when\n> upstream isn't configured:\n>\n>   fatal: no upstream configured for branch 'foo'\n>\n> Make it so.\n>\n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> ---\n>  object-name.c                 | 5 +++--\n>  t/t1507-rev-parse-upstream.sh | 5 +++++\n>  2 files changed, 8 insertions(+), 2 deletions(-)\n>\n> diff --git a/object-name.c b/object-name.c\n> index 2dd1a0f56e..d9f3a176d8 100644\n> --- a/object-name.c\n> +++ b/object-name.c\n> @@ -898,6 +898,7 @@ static int get_oid_basic(struct repository *r, const char *str, int len,\n>  \tchar *real_ref = NULL;\n>  \tint refs_found = 0;\n>  \tint at, reflog_len, nth_prior = 0;\n> +\tint fatal = !(flags & GET_OID_QUIETLY);\n>  \n>  \tif (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {\n>  \t\tif (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {\n> @@ -952,11 +953,11 @@ static int get_oid_basic(struct repository *r, const char *str, int len,\n>  \n>  \tif (!len && reflog_len)\n>  \t\t/* allow \"@{...}\" to mean the current branch reflog */\n> -\t\trefs_found = repo_dwim_ref(r, \"HEAD\", 4, oid, &real_ref, 0);\n> +\t\trefs_found = repo_dwim_ref(r, \"HEAD\", 4, oid, &real_ref, !fatal);\n>  \telse if (reflog_len)\n>  \t\trefs_found = repo_dwim_log(r, str, len, oid, &real_ref);\n>  \telse\n> -\t\trefs_found = repo_dwim_ref(r, str, len, oid, &real_ref, 0);\n> +\t\trefs_found = repo_dwim_ref(r, str, len, oid, &real_ref, !fatal);\n>  \n>  \tif (!refs_found)\n>  \t\treturn -1;\n\nAll of the above look sensible.\n\n> diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh\n> index c34714ffe3..549eb315a9 100755\n> --- a/t/t1507-rev-parse-upstream.sh\n> +++ b/t/t1507-rev-parse-upstream.sh\n> @@ -183,6 +183,11 @@ test_expect_success '@{u} error message when no upstream' '\n>  \ttest_cmp expect actual\n>  '\n>  \n> +test_expect_success '@{u} silent error when no upstream' '\n> +\ttest_must_fail git rev-parse --verify --quiet @{u} 2>actual &&\n> +\ttest_must_be_empty actual\n> +'\n\nOK.  This does not check what comes out to the standard output\nstream at all, and only cares that the standard error stream emits\nnothing.  Which is absolutely the right thing to do.  When a command\nexits non-zero, we do not guarantee what output it emits, and the\ninvoker is expected to check the exit status.\n\nWill queue.  Thanks.\n"}]}