From patchwork Tue Nov 13 19:52:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10681453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F6551709 for ; Tue, 13 Nov 2018 19:53:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5198D2B0B3 for ; Tue, 13 Nov 2018 19:53:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45B202B0C6; Tue, 13 Nov 2018 19:53:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1492C2B0C0 for ; Tue, 13 Nov 2018 19:53:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727006AbeKNFwh (ORCPT ); Wed, 14 Nov 2018 00:52:37 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38316 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725892AbeKNFwg (ORCPT ); Wed, 14 Nov 2018 00:52:36 -0500 Received: by mail-wr1-f68.google.com with SMTP id e3-v6so14723466wrs.5 for ; Tue, 13 Nov 2018 11:52:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/gb/FDpQi2kCW3QSHhfAwUnjCxvhV5TG9StfUeAcXTs=; b=OYgB2klHRCH7gorxbhZMNneOY4ga6CiNDkck2SwP3Y/6F8gwBqz8yp6TP/Eku9gnuZ Zr8klF6adPehwBL2CWs1siwqLk7rgdpT+raGgj7X7g8I5gCGwIhBiQr29uCuTKQ4KGkB Is6yR+G2OUKnfTmpzz5xMQrEsVo7WMRbCNZ1fJjFgMsSAZ8iqKQPxZk5KV0dJWmvfn9z V93ij4VEZ78NnaUB4O+TXhPeUekOMu+HprYb7UncQKbj7CIrsGsWVZp9r4lFR4fQJ6uF apjLnyI9aKyi+eWztMoN4I4Goj8L4tuensoVvIjbVeShbJutqWXe6mY/3lJHzaLS/mNK lKTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/gb/FDpQi2kCW3QSHhfAwUnjCxvhV5TG9StfUeAcXTs=; b=WrHCN5WZUKRS1Tc+hE+N80MbOybKl37+afsC7HL1fLfuObHNQWkMjuCqQj0TR7aMe3 D+rviAieD4v5dqbXawNQ0YO6NSaKuJ3l61alwVIGqMMkkyjA/orsu82ss5qziNNuXbtE EmMCEmRh3ZwOhD11iioWwfQJMJrCrINFSl5z+K78/b9nUJ8dx06lbCHyJgQp+vRN2vzq 2O1bd6UB3c2+9L9UH2fKcRk51fq79gSuYmJ8aCG2Nz0UgKvmNuWae2ikQgUYuIhnQPNS Wzm+GQ5lddAe2Ae7+P5wzhgYio6WV/rLTM9D0p+8uZSZbHBgVyvR4WbApkgH2vSTHRTa HkXw== X-Gm-Message-State: AGRZ1gLzY4fs9HjsGWoaKTDWpmQ5VY6A9J4xWrfODBcDdg6IkQIcKF4y Qv4zwF4FbNGGx1SNt9z12osjQu/8SHM= X-Google-Smtp-Source: AJdET5ewaw4KCYj3lSPGByOhvv1LVKW4Nt04Pw3dGRNTx2mosBGllCedXY4SrZi4r+xjKVtqvWdZEQ== X-Received: by 2002:a5d:4586:: with SMTP id p6mr887000wrq.69.1542138776708; Tue, 13 Nov 2018 11:52:56 -0800 (PST) Received: from u.nix.is ([2a01:4f8:190:5095::2]) by smtp.gmail.com with ESMTPSA id y7-v6sm13828560wmy.27.2018.11.13.11.52.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Nov 2018 11:52:55 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Stefan Beller , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 1/7] remote.c: add braces in anticipation of a follow-up change Date: Tue, 13 Nov 2018 19:52:39 +0000 Message-Id: <20181113195245.14296-2-avarab@gmail.com> X-Mailer: git-send-email 2.19.1.1182.g4ecb1133ce In-Reply-To: <20181026230741.23321-1-avarab@gmail.com> References: <20181026230741.23321-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The CodingGuidelines say "When there are multiple arms to a conditional and some of them require braces, enclose even a single line block in braces for consistency.". Fix the code in match_explicit() to conform. While I'm at it change the if/else if/else in guess_ref() to use braces. This is not currently needed, but a follow-up change will add a new multi-line condition to that logic. Signed-off-by: Ævar Arnfjörð Bjarmason --- remote.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/remote.c b/remote.c index b850f2feb3..695b379a44 100644 --- a/remote.c +++ b/remote.c @@ -968,12 +968,13 @@ static char *guess_ref(const char *name, struct ref *peer) if (!r) return NULL; - if (starts_with(r, "refs/heads/")) + if (starts_with(r, "refs/heads/")) { strbuf_addstr(&buf, "refs/heads/"); - else if (starts_with(r, "refs/tags/")) + } else if (starts_with(r, "refs/tags/")) { strbuf_addstr(&buf, "refs/tags/"); - else + } else { return NULL; + } strbuf_addstr(&buf, name); return strbuf_detach(&buf, NULL); @@ -1038,21 +1039,22 @@ static int match_explicit(struct ref *src, struct ref *dst, case 1: break; case 0: - if (starts_with(dst_value, "refs/")) + if (starts_with(dst_value, "refs/")) { matched_dst = make_linked_ref(dst_value, dst_tail); - else if (is_null_oid(&matched_src->new_oid)) + } else if (is_null_oid(&matched_src->new_oid)) { error("unable to delete '%s': remote ref does not exist", dst_value); - else if ((dst_guess = guess_ref(dst_value, matched_src))) { + } else if ((dst_guess = guess_ref(dst_value, matched_src))) { matched_dst = make_linked_ref(dst_guess, dst_tail); free(dst_guess); - } else + } else { error("unable to push to unqualified destination: %s\n" "The destination refspec neither matches an " "existing ref on the remote nor\n" "begins with refs/, and we are unable to " "guess a prefix based on the source ref.", dst_value); + } break; default: matched_dst = NULL; From patchwork Tue Nov 13 19:52:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10681457 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1DF613B5 for ; Tue, 13 Nov 2018 19:53:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92FB72B0B3 for ; Tue, 13 Nov 2018 19:53:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 876A92B0C9; Tue, 13 Nov 2018 19:53:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BEAE2B0B3 for ; Tue, 13 Nov 2018 19:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728815AbeKNFwj (ORCPT ); Wed, 14 Nov 2018 00:52:39 -0500 Received: from mail-wr1-f51.google.com ([209.85.221.51]:43498 "EHLO mail-wr1-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725892AbeKNFwj (ORCPT ); Wed, 14 Nov 2018 00:52:39 -0500 Received: by mail-wr1-f51.google.com with SMTP id y3-v6so14672568wrh.10 for ; Tue, 13 Nov 2018 11:52:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=emF1LzMUUWNGYE5jYyo3UzQniKyjS+tbDWZD9SzKNBQ=; b=F/YQ1jF4mETCktT5plrs86ccnwyLX7RgCmG1BVmSkLUUkcbyoiVNIudeOp2vQM4oHn 7HCQGasOZa7e+aRvlsGTwN6RufT528zaACW4FqaX1Fayw7L5V0r7NIvXJB36IV0OODEb +LmGnax0LHFIzjp1jPawcz1EQigHk6K7wt+XdF5A6bka8l4ph3mOCDiKL7cMjmzwi0RE fj1XDB7C7d+5f9Xhz4JfPC21GHE3X/IC2CBurZodBqbwBGcL6rzxGGayuLZRqwzs3XLr CMGs8cP6yIGY1BWT9HLftwDX2hsnTB0SzlEFFRyzwXYFMmyLB1JqS7kBh+SC+GrVapx5 iBFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=emF1LzMUUWNGYE5jYyo3UzQniKyjS+tbDWZD9SzKNBQ=; b=pgOGxipSrphNLHR6bNH5E2jkvc0nso9CDXtYFWAMmMqMaSZKBJAmJjx/lq3Enh7vbg +VHE4gJgyU4HxKZ9uMNXrfeeARzGHOJA+eAIRNdAnBo+OT6pUUoZMieGYWixADlQbUAW SN7RHf2/vNQAA1oFeVitDPi/i0B3Nz9EYb2mHHaqrmlxVNz8eN9kad4Fn8OcnI6X9gBL axpmZ/RSz/gm8Qx+vXOOjEow2umnUVgo3yXbrsKD7qPOC1oZ60ptEvBn/nuyGdFIeKRl frEwgsyYi5/Th/aeChGBx8DMlSLwQTCQvtw+02BljWpqzDM8cureUGH0BKcQ4WECM58+ QPAA== X-Gm-Message-State: AGRZ1gKQCN9O7eto62f26ftDWaUvNBvCr9eHKfuD6HDPqVMRalPm/n8Y Any1u0ExKra4BbSNRBQv3Bg0y9siBU0= X-Google-Smtp-Source: AJdET5cLRQi+O+ImDhvig4scJcd264mH7bGwJIwaQerEAA9+J4rW45c1NTALiTBEFLT3fZhvF9Mt8w== X-Received: by 2002:adf:b253:: with SMTP id y19-v6mr6039236wra.213.1542138778308; Tue, 13 Nov 2018 11:52:58 -0800 (PST) Received: from u.nix.is ([2a01:4f8:190:5095::2]) by smtp.gmail.com with ESMTPSA id y7-v6sm13828560wmy.27.2018.11.13.11.52.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Nov 2018 11:52:57 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Stefan Beller , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 2/7] i18n: remote.c: mark error(...) messages for translation Date: Tue, 13 Nov 2018 19:52:40 +0000 Message-Id: <20181113195245.14296-3-avarab@gmail.com> X-Mailer: git-send-email 2.19.1.1182.g4ecb1133ce In-Reply-To: <20181026230741.23321-1-avarab@gmail.com> References: <20181026230741.23321-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Mark up the error(...) messages in remote.c for translation. The likes of "unable to push to unqualified destination" are relatively big parts of the UI, i.e. error messages shown when "git push" fails. I don't think any of these are plumbing, an the entire test suite passes when running the tests with GIT_GETTEXT_POISON=1 (after building with GETTEXT_POISON). Signed-off-by: Ævar Arnfjörð Bjarmason --- remote.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/remote.c b/remote.c index 695b379a44..35fe8a178f 100644 --- a/remote.c +++ b/remote.c @@ -406,7 +406,7 @@ static int handle_config(const char *key, const char *value, void *cb) if (!remote->receivepack) remote->receivepack = v; else - error("more than one receivepack given, using the first"); + error(_("more than one receivepack given, using the first")); } else if (!strcmp(subkey, "uploadpack")) { const char *v; if (git_config_string(&v, key, value)) @@ -414,7 +414,7 @@ static int handle_config(const char *key, const char *value, void *cb) if (!remote->uploadpack) remote->uploadpack = v; else - error("more than one uploadpack given, using the first"); + error(_("more than one uploadpack given, using the first")); } else if (!strcmp(subkey, "tagopt")) { if (!strcmp(value, "--no-tags")) remote->fetch_tags = -1; @@ -707,7 +707,7 @@ static void query_refspecs_multiple(struct refspec *rs, int find_src = !query->src; if (find_src && !query->dst) - error("query_refspecs_multiple: need either src or dst"); + error(_("query_refspecs_multiple: need either src or dst")); for (i = 0; i < rs->nr; i++) { struct refspec_item *refspec = &rs->items[i]; @@ -735,7 +735,7 @@ int query_refspecs(struct refspec *rs, struct refspec_item *query) char **result = find_src ? &query->src : &query->dst; if (find_src && !query->dst) - return error("query_refspecs: need either src or dst"); + return error(_("query_refspecs: need either src or dst")); for (i = 0; i < rs->nr; i++) { struct refspec_item *refspec = &rs->items[i]; @@ -996,12 +996,12 @@ static int match_explicit_lhs(struct ref *src, * way to delete 'other' ref at the remote end. */ if (try_explicit_object_name(rs->src, match) < 0) - return error("src refspec %s does not match any.", rs->src); + return error(_("src refspec %s does not match any."), rs->src); if (allocated_match) *allocated_match = 1; return 0; default: - return error("src refspec %s matches more than one.", rs->src); + return error(_("src refspec %s matches more than one."), rs->src); } } @@ -1041,32 +1041,33 @@ static int match_explicit(struct ref *src, struct ref *dst, case 0: if (starts_with(dst_value, "refs/")) { matched_dst = make_linked_ref(dst_value, dst_tail); + } else if (is_null_oid(&matched_src->new_oid)) { - error("unable to delete '%s': remote ref does not exist", + error(_("unable to delete '%s': remote ref does not exist"), dst_value); } else if ((dst_guess = guess_ref(dst_value, matched_src))) { matched_dst = make_linked_ref(dst_guess, dst_tail); free(dst_guess); } else { - error("unable to push to unqualified destination: %s\n" - "The destination refspec neither matches an " - "existing ref on the remote nor\n" - "begins with refs/, and we are unable to " - "guess a prefix based on the source ref.", + error(_("unable to push to unqualified destination: %s\n" + "The destination refspec neither matches an " + "existing ref on the remote nor\n" + "begins with refs/, and we are unable to " + "guess a prefix based on the source ref."), dst_value); } break; default: matched_dst = NULL; - error("dst refspec %s matches more than one.", + error(_("dst refspec %s matches more than one."), dst_value); break; } if (!matched_dst) return -1; if (matched_dst->peer_ref) - return error("dst ref %s receives from more than one src.", - matched_dst->name); + return error(_("dst ref %s receives from more than one src."), + matched_dst->name); else { matched_dst->peer_ref = allocated_src ? matched_src : @@ -1797,7 +1798,7 @@ int get_fetch_map(const struct ref *remote_refs, if (!starts_with((*rmp)->peer_ref->name, "refs/") || check_refname_format((*rmp)->peer_ref->name, 0)) { struct ref *ignore = *rmp; - error("* Ignoring funny ref '%s' locally", + error(_("* Ignoring funny ref '%s' locally"), (*rmp)->peer_ref->name); *rmp = (*rmp)->next; free(ignore->peer_ref); @@ -2165,7 +2166,7 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i else if (!colon[1]) oidclr(&entry->expect); else if (get_oid(colon + 1, &entry->expect)) - return error("cannot parse expected object name '%s'", colon + 1); + return error(_("cannot parse expected object name '%s'"), colon + 1); return 0; } From patchwork Tue Nov 13 19:52:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10681459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F7431709 for ; Tue, 13 Nov 2018 19:53:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 018152B0B3 for ; Tue, 13 Nov 2018 19:53:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA3052B0C6; Tue, 13 Nov 2018 19:53:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8078F2B0C0 for ; Tue, 13 Nov 2018 19:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729564AbeKNFwk (ORCPT ); Wed, 14 Nov 2018 00:52:40 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40355 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727428AbeKNFwk (ORCPT ); Wed, 14 Nov 2018 00:52:40 -0500 Received: by mail-wr1-f68.google.com with SMTP id p4so5519740wrt.7 for ; Tue, 13 Nov 2018 11:53:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jmDLoo6kZfelvQ9Ge0mn06fBMNaVk+08qn68q9tPH80=; b=P6H9y6091K/ArjZpKtVZMUem3yaMTtM2oc+LtoO8xNNa/Zo4SKNup6Jk/avxmdTMOa OZ3X5fWtIo5TtOtSOpMghARpIXdsVvfAyzTt8O754CYe8rPMmw3Y/qmujpfM6hkC5YA3 wwBQJpHjlLLSknUR1bi7ReUZaInVY3rY/LFlxf/X4ZibHZlqZqZ7RbiGK5Vxodt8vm5L pIzEnUhYs+DQmBCR5QK42uTzoHc8PwyNPZ1ZDnXvhwI4ywtZn1wTO443gKpJqpLyg6kb QHFHbkv1OMCcJAcB/t4xeZPcvpTY3TjRUTs93/HUcuu3HTAyGi77RN46j2u/8e/7AHJW t0CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jmDLoo6kZfelvQ9Ge0mn06fBMNaVk+08qn68q9tPH80=; b=IECPlw8E/4raxz40X+SJrQn6n3/GMvCVhTWx6/f7aBmXiH4xNrN1EsqGoUay19bFXw iNNXpcW8ldwFBv8nPMDmMn7IMfzFL/wd5xo4F4x23tkF566K6cQ9IwPHwmHNBEw1E1r2 PdKZfRumjgSHGmrkt4DCdHcQ+lTu4ieCjZOWej7dCi7TIVB+aw9nzbX3FXboGX807Jy7 T1OgLXe2sBRGxv79iwuBzMvUCaXUgI9xgSk5iBZMKwiHFPkEpdZbatLyMus8mcFNnzV1 zIWMi3cOMPzxgHnzUI+EfNPgaf+9n1/gCPGbtxV2Ds1VwK6OZfCpqNwPQi/NkOURUFCN EQkg== X-Gm-Message-State: AGRZ1gLfjVv2RvyNgXJ21F04ilh7RsiqKqPJJeYFPobUnSXC/UJA0RTz 0gBVJXQaob1+Cr+lGSMnMsahPRw+Xgs= X-Google-Smtp-Source: AJdET5c9ktjuvse3c19yz6mP/vFzVyo7OcCWJ5lyt7CDdwwcP7ELUeTjP+DMrOABj5X/H4K/9JvqkQ== X-Received: by 2002:adf:ba8b:: with SMTP id p11-v6mr6055426wrg.203.1542138779999; Tue, 13 Nov 2018 11:52:59 -0800 (PST) Received: from u.nix.is ([2a01:4f8:190:5095::2]) by smtp.gmail.com with ESMTPSA id y7-v6sm13828560wmy.27.2018.11.13.11.52.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Nov 2018 11:52:59 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Stefan Beller , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 3/7] push: improve the error shown on unqualified push Date: Tue, 13 Nov 2018 19:52:41 +0000 Message-Id: <20181113195245.14296-4-avarab@gmail.com> X-Mailer: git-send-email 2.19.1.1182.g4ecb1133ce In-Reply-To: <20181026230741.23321-1-avarab@gmail.com> References: <20181026230741.23321-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Improve the error message added in f8aae12034 ("push: allow unqualified dest refspecs to DWIM", 2008-04-23), which before this change looks like this: $ git push avar v2.19.0^{commit}:newbranch -n error: unable to push to unqualified destination: newbranch The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref. error: failed to push some refs to 'git@github.com:avar/git.git' This message needed to be read very carefully to spot how to fix the error, i.e. to push to refs/heads/newbranch. Now the message will look like this instead: $ ./git-push avar v2.19.0^{commit}:newbranch -n error: The destination you provided is not a full refname (i.e., starting with "refs/"). We tried to guess what you meant by: - Looking for a ref that matches 'newbranch' on the remote side. - Checking if the being pushed ('v2.19.0^{commit}') is a ref in "refs/{heads,tags}/". If so we add a corresponding refs/{heads,tags}/ prefix on the remote side. Neither worked, so we gave up. You must fully qualify the ref. error: failed to push some refs to 'git@github.com:avar/git.git' This improvement is the result of on-list discussion in [1] and [2], as well as my own fixes / reformatting / phrasing on top. The suggestion by Jeff on-list was to make that second bullet point "Looking at the refname of the local source.". The version being added here is more verbose, but also more accurate. saying "local source" could refer to any ref in the local refstore, including something in refs/remotes/*. A later change will teach guess_ref() to infer a ref type from remote-tracking refs, so let's not confuse the two. While I'm at it, add a "TRANSLATORS" comment since the message has gotten more complex and it's not as clear what the two %s's refer to. 1. https://public-inbox.org/git/20181010205505.GB12949@sigill.intra.peff.net/ 2. https://public-inbox.org/git/xmqqbm81lb7c.fsf@gitster-ct.c.googlers.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- remote.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/remote.c b/remote.c index 35fe8a178f..15da4019c3 100644 --- a/remote.c +++ b/remote.c @@ -1049,12 +1049,22 @@ static int match_explicit(struct ref *src, struct ref *dst, matched_dst = make_linked_ref(dst_guess, dst_tail); free(dst_guess); } else { - error(_("unable to push to unqualified destination: %s\n" - "The destination refspec neither matches an " - "existing ref on the remote nor\n" - "begins with refs/, and we are unable to " - "guess a prefix based on the source ref."), - dst_value); + /* + * TRANSLATORS: "matches '%s'%" is the + * part of "git push :" + * push, and "being pushed ('%s')" is the + * . + */ + error(_("The destination you provided is not a full refname (i.e.,\n" + "starting with \"refs/\"). We tried to guess what you meant by:\n" + "\n" + "- Looking for a ref that matches '%s' on the remote side.\n" + "- Checking if the being pushed ('%s')\n" + " is a ref in \"refs/{heads,tags}/\". If so we add a corresponding\n" + " refs/{heads,tags}/ prefix on the remote side.\n" + "\n" + "Neither worked, so we gave up. You must fully qualify the ref."), + dst_value, matched_src->name); } break; default: From patchwork Tue Nov 13 19:52:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10681461 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CA4814D6 for ; Tue, 13 Nov 2018 19:53:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E9E92B0B3 for ; Tue, 13 Nov 2018 19:53:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 637162B0C6; Tue, 13 Nov 2018 19:53:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 081562B0B3 for ; Tue, 13 Nov 2018 19:53:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729768AbeKNFwm (ORCPT ); Wed, 14 Nov 2018 00:52:42 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38182 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726569AbeKNFwl (ORCPT ); Wed, 14 Nov 2018 00:52:41 -0500 Received: by mail-wm1-f66.google.com with SMTP id f2-v6so12575489wme.3 for ; Tue, 13 Nov 2018 11:53:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2jC6GZM1sZyjkN9l/SNT0OrLbSRHjZh9Lv3QgFG2lEI=; b=cZB6x304n/T3EEuvs99YTh5gBbRNE9wOZAK2xAJVGYVgqIHLFVPtk71n8CA1/d8ZaY L5D6hCqxXseM3BSHtr5TWJGLsEV7ZqZHrGH8CJbGf7eztZxFSVfrxqpuPCAcNHGDfFI6 9gugBB5FOgQ639uZQKEhQLW1vIrAw7KNnlhWw2Pdx0d8E5ER6WgMQxChq60YXLI4+KcZ 3j9SsINpBBfEQyKKbM8RxVP1s67CwUqsveevgRsCukvEJOIzBKHtHRRnR99p0VO6dAFT U3VY4spAx6HNLUy0SwQddmInXIn+0FrtkcznMYhHiMGCYTon06IL5r/0iXiDwoLc3GUH vqDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2jC6GZM1sZyjkN9l/SNT0OrLbSRHjZh9Lv3QgFG2lEI=; b=K8grr6vSWpg1yTbe4qz6+xmo/z2cOui1XyRpkIS0NPnvGTsLzSUC3zh9BtLUKohWj4 BbpW0gNRmrm8QEPJ3wdfn5fLRlLkXhE2nBaBMwQVohuQO4C4xS763eIiflIFIJEFH+4O tcyQKTQ1DTuDurD0ArbItR5Q3a8YfVRPpcPFBfCA9Du7dAUtk7oy8Ip8+289JN5xdaBv RXLorqTHpwFJU3s50gZ1nlpXgCnahnAbCcVYWGqfLy3jkdIKJ1TFJJ7Z3AXAW6D8IDSh 9on/gTMJ0oDvtO+zqKPaBKEfnHfBa8vLgffEbF95X75sbhJYaSqoxfr/B4ohYFrl/T3W wUtQ== X-Gm-Message-State: AGRZ1gJPGH495HofZ6J3NlsvCCJsYGCIvOXzD33mC3kote0wiMhAYkau rtelas0ZhjzuDRP7JaVtVV8QUQLUZ08= X-Google-Smtp-Source: AJdET5cso/QdPE3ypBzGGNNJK0cy62imRB/Op95X2PknpRInEVdvxvqF3jHRUl5lru6Fg4j33xNClw== X-Received: by 2002:a7b:c38f:: with SMTP id s15-v6mr4514082wmj.145.1542138781457; Tue, 13 Nov 2018 11:53:01 -0800 (PST) Received: from u.nix.is ([2a01:4f8:190:5095::2]) by smtp.gmail.com with ESMTPSA id y7-v6sm13828560wmy.27.2018.11.13.11.53.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Nov 2018 11:53:00 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Stefan Beller , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 4/7] push: move unqualified refname error into a function Date: Tue, 13 Nov 2018 19:52:42 +0000 Message-Id: <20181113195245.14296-5-avarab@gmail.com> X-Mailer: git-send-email 2.19.1.1182.g4ecb1133ce In-Reply-To: <20181026230741.23321-1-avarab@gmail.com> References: <20181026230741.23321-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A follow-up change will extend this error message with the advice facility. Doing so would make the indentation too deeply nested for comfort. So let's split this into a helper function. There's no changes to the wording here. Just code moving & re-indentation, and re-flowing the "TRANSLATORS" comment. Signed-off-by: Ævar Arnfjörð Bjarmason --- remote.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/remote.c b/remote.c index 15da4019c3..ba8abf4d32 100644 --- a/remote.c +++ b/remote.c @@ -1005,6 +1005,26 @@ static int match_explicit_lhs(struct ref *src, } } +static void show_push_unqualified_ref_name_error(const char *dst_value, + const char *matched_src_name) +{ + /* + * TRANSLATORS: "matches '%s'%" is the part of "git push + * :" push, and "being pushed ('%s')" is + * the . + */ + error(_("The destination you provided is not a full refname (i.e.,\n" + "starting with \"refs/\"). We tried to guess what you meant by:\n" + "\n" + "- Looking for a ref that matches '%s' on the remote side.\n" + "- Checking if the being pushed ('%s')\n" + " is a ref in \"refs/{heads,tags}/\". If so we add a corresponding\n" + " refs/{heads,tags}/ prefix on the remote side.\n" + "\n" + "Neither worked, so we gave up. You must fully qualify the ref."), + dst_value, matched_src_name); +} + static int match_explicit(struct ref *src, struct ref *dst, struct ref ***dst_tail, struct refspec_item *rs) @@ -1049,22 +1069,8 @@ static int match_explicit(struct ref *src, struct ref *dst, matched_dst = make_linked_ref(dst_guess, dst_tail); free(dst_guess); } else { - /* - * TRANSLATORS: "matches '%s'%" is the - * part of "git push :" - * push, and "being pushed ('%s')" is the - * . - */ - error(_("The destination you provided is not a full refname (i.e.,\n" - "starting with \"refs/\"). We tried to guess what you meant by:\n" - "\n" - "- Looking for a ref that matches '%s' on the remote side.\n" - "- Checking if the being pushed ('%s')\n" - " is a ref in \"refs/{heads,tags}/\". If so we add a corresponding\n" - " refs/{heads,tags}/ prefix on the remote side.\n" - "\n" - "Neither worked, so we gave up. You must fully qualify the ref."), - dst_value, matched_src->name); + show_push_unqualified_ref_name_error(dst_value, + matched_src->name); } break; default: From patchwork Tue Nov 13 19:52:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10681463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D04814D6 for ; Tue, 13 Nov 2018 19:53:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 304222B0B3 for ; Tue, 13 Nov 2018 19:53:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2477A2B0C9; Tue, 13 Nov 2018 19:53:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B0802B0B3 for ; Tue, 13 Nov 2018 19:53:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730729AbeKNFwo (ORCPT ); Wed, 14 Nov 2018 00:52:44 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38187 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726569AbeKNFwo (ORCPT ); Wed, 14 Nov 2018 00:52:44 -0500 Received: by mail-wm1-f66.google.com with SMTP id f2-v6so12575561wme.3 for ; Tue, 13 Nov 2018 11:53:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H/iYvIxl3Gd53RnWyN7Xfm/xbBRzcmmCQkBn3d6b7l4=; b=QPWNAQwH3LJa6vd525xOU7SOi/ZzcIT6Utl9Cy2C1MNEn/bn+8i8rjxqgXVKiqI+Mf SSnEpwIA1rfmGalBDUijgl7Nwb3hLrjGYvChukzT+KlhqQY+bTpWUPzV9pyu1R3OoRp/ /0bJ9cLFnO+0vxnD2hwvCpUO+XHzMj/dqONMyZykdcHb6loVZKAEj4ivB8D0IhTNU2+n RzfdHgRU2uusBeMrq4zH22v1wzp7DEoOMX5nSI69n4xgG7hj/u/prRFS1BR+EIhP7hwR 9/0E8decAj5z1Quq715jTnISsFyjPxD1JZwvgsObL9N6VIfzZ9hrfr1wimtMD0QC1ny9 1NFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=H/iYvIxl3Gd53RnWyN7Xfm/xbBRzcmmCQkBn3d6b7l4=; b=iexS0eHZuBLUQZPjN+Hw3rZIKNe5a7RNKTWRQlbK4y/yValDftFgKgGHPQVvY/4O7d I/gW7MJEOvJ9EionmXaUrqv1VZjieZhxiXZ+XW8QLs2olGy/vMdvoZf2h97rdZ7BPWjQ tliI++Fk1mGPJA+fyreOY03GfSPKvPRTifZUCl8YCCUQFmxTSSv/1oLS+WJx73h7kesu cbEzGvJTNJ+tskdDhscouornU0a74DXJLy5eFxK56Cep/jbK3tpcJWX0VbF0jLNpnJMB 0tcHE6D97OHwth/RjKwfTK8JOBkun12uDpoE1/qGaD6O+y1O4a/cahnNuhsVwyV6ZkkS SFZw== X-Gm-Message-State: AGRZ1gJ4SA4xUJ6gn2EzdnjTuF5l7PhLDc6e/jDKuMvUMeAp1t/B3LCJ 4mupDbRKI01NUIK3y8/7i2dwn2vwgXs= X-Google-Smtp-Source: AJdET5fR/kjC1Nu1B9rrH9mW2A7WUoOel8HqZN0bATyCPaTzT+M3dqvIrEsOJWeed2CmWO5S5Eob5g== X-Received: by 2002:a1c:f30b:: with SMTP id q11-v6mr4327046wmq.45.1542138782964; Tue, 13 Nov 2018 11:53:02 -0800 (PST) Received: from u.nix.is ([2a01:4f8:190:5095::2]) by smtp.gmail.com with ESMTPSA id y7-v6sm13828560wmy.27.2018.11.13.11.53.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Nov 2018 11:53:02 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Stefan Beller , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 5/7] push: add an advice on unqualified push Date: Tue, 13 Nov 2018 19:52:43 +0000 Message-Id: <20181113195245.14296-6-avarab@gmail.com> X-Mailer: git-send-email 2.19.1.1182.g4ecb1133ce In-Reply-To: <20181026230741.23321-1-avarab@gmail.com> References: <20181026230741.23321-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an advice to the recently improved error message added in f8aae12034 ("push: allow unqualified dest refspecs to DWIM", 2008-04-23). Now with advice.pushUnqualifiedRefName=true (on by default) we show a hint about how to proceed: $ ./git-push avar v2.19.0^{commit}:newbranch -n error: The destination you provided is not a full refname (i.e., starting with "refs/"). We tried to guess what you meant by: - Looking for a ref that matches 'newbranch' on the remote side. - Checking if the being pushed ('v2.19.0^{commit}') is a ref in "refs/{heads,tags}/". If so we add a corresponding refs/{heads,tags}/ prefix on the remote side. Neither worked, so we gave up. You must fully qualify the ref. hint: The part of the refspec is a commit object. hint: Did you mean to create a new branch by pushing to hint: 'v2.19.0^{commit}:refs/heads/newbranch'? error: failed to push some refs to 'git@github.com:avar/git.git' When trying to push a tag, tree or a blob we suggest that perhaps the user meant to push them to refs/tags/ instead. The if/else duplication for all of OBJ_{COMMIT,TAG,TREE,BLOB} is unfortunate, but is required to correctly mark the messages for translation. See the discussion in <87r2gxebsi.fsf@evledraar.gmail.com> about that. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/config/advice.txt | 7 +++++++ advice.c | 2 ++ advice.h | 1 + remote.c | 37 +++++++++++++++++++++++++++++++++ t/t5505-remote.sh | 28 +++++++++++++++++++++++++ 5 files changed, 75 insertions(+) diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt index 57fcd4c862..88620429ea 100644 --- a/Documentation/config/advice.txt +++ b/Documentation/config/advice.txt @@ -30,6 +30,13 @@ advice.*:: tries to overwrite a remote ref that points at an object that is not a commit-ish, or make the remote ref point at an object that is not a commit-ish. + pushUnqualifiedRefname:: + Shown when linkgit:git-push[1] gives up trying to + guess based on the source and destination refs what + remote ref namespace the source belongs in, but where + we can still suggest that the user push to either + refs/heads/* or refs/tags/* based on the type of the + source object. statusHints:: Show directions on how to proceed from the current state in the output of linkgit:git-status[1], in diff --git a/advice.c b/advice.c index 5f35656409..567209aa79 100644 --- a/advice.c +++ b/advice.c @@ -9,6 +9,7 @@ int advice_push_non_ff_matching = 1; int advice_push_already_exists = 1; int advice_push_fetch_first = 1; int advice_push_needs_force = 1; +int advice_push_unqualified_ref_name = 1; int advice_status_hints = 1; int advice_status_u_option = 1; int advice_commit_before_merge = 1; @@ -63,6 +64,7 @@ static struct { { "pushAlreadyExists", &advice_push_already_exists }, { "pushFetchFirst", &advice_push_fetch_first }, { "pushNeedsForce", &advice_push_needs_force }, + { "pushUnqualifiedRefName", &advice_push_unqualified_ref_name }, { "statusHints", &advice_status_hints }, { "statusUoption", &advice_status_u_option }, { "commitBeforeMerge", &advice_commit_before_merge }, diff --git a/advice.h b/advice.h index 696bf0e7d2..f875f8cd8d 100644 --- a/advice.h +++ b/advice.h @@ -9,6 +9,7 @@ extern int advice_push_non_ff_matching; extern int advice_push_already_exists; extern int advice_push_fetch_first; extern int advice_push_needs_force; +extern int advice_push_unqualified_ref_name; extern int advice_status_hints; extern int advice_status_u_option; extern int advice_commit_before_merge; diff --git a/remote.c b/remote.c index ba8abf4d32..f7477b8eb6 100644 --- a/remote.c +++ b/remote.c @@ -13,6 +13,7 @@ #include "mergesort.h" #include "argv-array.h" #include "commit-reach.h" +#include "advice.h" enum map_direction { FROM_SRC, FROM_DST }; @@ -1008,6 +1009,9 @@ static int match_explicit_lhs(struct ref *src, static void show_push_unqualified_ref_name_error(const char *dst_value, const char *matched_src_name) { + struct object_id oid; + enum object_type type; + /* * TRANSLATORS: "matches '%s'%" is the part of "git push * :" push, and "being pushed ('%s')" is @@ -1023,6 +1027,39 @@ static void show_push_unqualified_ref_name_error(const char *dst_value, "\n" "Neither worked, so we gave up. You must fully qualify the ref."), dst_value, matched_src_name); + + if (!advice_push_unqualified_ref_name) + return; + + if (get_oid(matched_src_name, &oid)) + BUG("'%s' is not a valid object, " + "match_explicit_lhs() should catch this!", + matched_src_name); + type = oid_object_info(the_repository, &oid, NULL); + if (type == OBJ_COMMIT) { + advise(_("The part of the refspec is a commit object.\n" + "Did you mean to create a new branch by pushing to\n" + "'%s:refs/heads/%s'?"), + matched_src_name, dst_value); + } else if (type == OBJ_TAG) { + advise(_("The part of the refspec is a tag object.\n" + "Did you mean to create a new tag by pushing to\n" + "'%s:refs/tags/%s'?"), + matched_src_name, dst_value); + } else if (type == OBJ_TREE) { + advise(_("The part of the refspec is a tree object.\n" + "Did you mean to tag a new tree by pushing to\n" + "'%s:refs/tags/%s'?"), + matched_src_name, dst_value); + } else if (type == OBJ_BLOB) { + advise(_("The part of the refspec is a blob object.\n" + "Did you mean to tag a new blob by pushing to\n" + "'%s:refs/tags/%s'?"), + matched_src_name, dst_value); + } else { + BUG("'%s' should be commit/tag/tree/blob, is '%d'", + matched_src_name, type); + } } static int match_explicit(struct ref *src, struct ref *dst, diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index d2a2cdd453..f069cbcc24 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -1222,4 +1222,32 @@ test_expect_success 'add remote matching the "insteadOf" URL' ' git remote add backup xyz@example.com ' +test_expect_success 'unqualified refspec DWIM and advice' ' + test_when_finished "(cd test && git tag -d some-tag)" && + ( + cd test && + git tag -a -m "Some tag" some-tag master && + exit_with=true && + for type in commit tag tree blob + do + if test "$type" = "blob" + then + oid=$(git rev-parse some-tag:file) + else + oid=$(git rev-parse some-tag^{$type}) + fi && + test_must_fail git push origin $oid:dst 2>err && + test_i18ngrep "error: The destination you" err && + test_i18ngrep "hint: Did you mean" err && + test_must_fail git -c advice.pushUnqualifiedRefName=false \ + push origin $oid:dst 2>err && + test_i18ngrep "error: The destination you" err && + test_i18ngrep ! "hint: Did you mean" err || + exit_with=false + done && + $exit_with + ) +' + + test_done From patchwork Tue Nov 13 19:52:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10681465 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F70413B5 for ; Tue, 13 Nov 2018 19:53:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7208B2B0B3 for ; Tue, 13 Nov 2018 19:53:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6627E2B0C6; Tue, 13 Nov 2018 19:53:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 069762B0C0 for ; Tue, 13 Nov 2018 19:53:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730732AbeKNFwp (ORCPT ); Wed, 14 Nov 2018 00:52:45 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41222 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730632AbeKNFwp (ORCPT ); Wed, 14 Nov 2018 00:52:45 -0500 Received: by mail-wr1-f65.google.com with SMTP id v18-v6so14697771wrt.8 for ; Tue, 13 Nov 2018 11:53:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WBOOUm3dGrk20CoAx67N32u981RlnDonF6EAWzF/7MY=; b=fLxKSewyFp07loTbHi0IuFNgSyA1w+bnYqeaO2h1UF3NT0E7dEfvqcKQOmy/B/dz3b 4agXu5OPBapvU6tgR7QLIOGJyO7oFbN9+m9YkuvnuEaVR/L2RK5Saenz7CATw7pFRBIZ HFnGDsfNeQDol2zSrCB0JLvOGjx5zHoM4sdKydcX54kiDiLKM4SWOdsZGyqLGGClxt3s B470BOAqCL/qyhKYLjYrq+0lPsRB2El5VWUJ3NSOHMKyzLEALSP4nVkqrsDo3QDNuiba Ul8lbet3g1dWOMTUr0RvZw64mqVz2zmVUWfz9iy5wd9CgfiBwQyJJI29J/ENtksGSNZz k3dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WBOOUm3dGrk20CoAx67N32u981RlnDonF6EAWzF/7MY=; b=My5YMaK96r8zln1bakSTGTAYfEeY0otfB5xbzDYNt370K8dy65+a/uAXIzma+pi5yW xaOHO71/7/m0Ibs4XSx/aNKebv94Jv8jXPAMME9JWfVl8Bd2MVIhyU2X99ZzBugDdDnq 2aXZApoOeHgfgwW81tU87euKTSRAEtSdMmfIZ37dZjosj4iWo3Gn3I4sdDLGCEVfJxLL 9b3kjuW1IWeBb951X0C0UFRO18LRkoEJ6+tGOQhohyqt1a37eoDFSKlugeYqObIinTWc 4EWSaw/cpv76tzNr5eHxWxirNiudzE3cP+rpoSUyunkBT0pxACstgXoQKNmbPnGgWWvr jrbw== X-Gm-Message-State: AGRZ1gKETe54eVB9lOBopJmEJSYrgafgsfWeQxa8fu58QxaeYTfMqi9o IgR+3zqK58wWgfGopgN3vLjmvts1HK8= X-Google-Smtp-Source: AJdET5dfDJxiGRKjv3pQdfbKt+O9bWm9yiOTqaarCzdAOyln9QjK8/FDhcSi0xBZIoeLDYdkZS8Orw== X-Received: by 2002:adf:b453:: with SMTP id v19-v6mr6294325wrd.47.1542138784568; Tue, 13 Nov 2018 11:53:04 -0800 (PST) Received: from u.nix.is ([2a01:4f8:190:5095::2]) by smtp.gmail.com with ESMTPSA id y7-v6sm13828560wmy.27.2018.11.13.11.53.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Nov 2018 11:53:03 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Stefan Beller , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 6/7] push: test that doesn't DWYM if is unqualified Date: Tue, 13 Nov 2018 19:52:44 +0000 Message-Id: <20181113195245.14296-7-avarab@gmail.com> X-Mailer: git-send-email 2.19.1.1182.g4ecb1133ce In-Reply-To: <20181026230741.23321-1-avarab@gmail.com> References: <20181026230741.23321-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a test asserting that "git push origin :" where is a branch, tag, tree or blob in refs/remotes/* doesn't DWYM when is unqualified. This has never been the case, but there haven't been any tests for this behavior. See f88395ac23 ("Renaming push.", 2005-08-03), bb9fca80ce ("git-push: Update description of refspecs and add examples", 2007-06-09) and f8aae12034 ("push: allow unqualified dest refspecs to DWIM", 2008-04-23) which are most relevant commits that have changed or documented the behavior of the DWYM feature in the past. These tests were originally meant to lead up to a patch that made refs/remotes/* on the LHS imply refs/heads/* on the RHS, see [1]. That patch proved controversial and may not ever land in git.git, but we should have the tests that remind us what the current behavior is in case it's ever changed. 1. https://public-inbox.org/git/20181026230741.23321-8-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t5505-remote.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index f069cbcc24..883b32efa0 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -1249,5 +1249,32 @@ test_expect_success 'unqualified refspec DWIM and advice' ' ) ' +test_expect_success 'refs/remotes/* refspec and unqualified DWIM and advice' ' + ( + cd two && + git tag -a -m "Some tag" my-tag master && + git update-ref refs/trees/my-head-tree HEAD^{tree} && + git update-ref refs/blobs/my-file-blob HEAD:file + ) && + ( + cd test && + git config --add remote.two.fetch "+refs/tags/*:refs/remotes/tags-from-two/*" && + git config --add remote.two.fetch "+refs/trees/*:refs/remotes/trees-from-two/*" && + git config --add remote.two.fetch "+refs/blobs/*:refs/remotes/blobs-from-two/*" && + git fetch --no-tags two && + + test_must_fail git push origin refs/remotes/two/another:dst 2>err && + test_i18ngrep "error: The destination you" err && + + test_must_fail git push origin refs/remotes/tags-from-two/my-tag:dst-tag 2>err && + test_i18ngrep "error: The destination you" err && + + test_must_fail git push origin refs/remotes/trees-from-two/my-head-tree:dst-tree 2>err && + test_i18ngrep "error: The destination you" err && + + test_must_fail git push origin refs/remotes/blobs-from-two/my-file-blob:dst-blob 2>err && + test_i18ngrep "error: The destination you" err + ) +' test_done From patchwork Tue Nov 13 19:52:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10681469 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E97DE14D6 for ; Tue, 13 Nov 2018 19:53:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCBB62B0B3 for ; Tue, 13 Nov 2018 19:53:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0CD92B0C6; Tue, 13 Nov 2018 19:53:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7000B2B0B3 for ; Tue, 13 Nov 2018 19:53:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730779AbeKNFwr (ORCPT ); Wed, 14 Nov 2018 00:52:47 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:56139 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730632AbeKNFwq (ORCPT ); Wed, 14 Nov 2018 00:52:46 -0500 Received: by mail-wm1-f66.google.com with SMTP id i73-v6so7928984wmd.5 for ; Tue, 13 Nov 2018 11:53:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1nmdYKj5JRhefeg7ptWM/GYUDy2k/RGB+OV75nbO2PE=; b=q1uukqAy7qqNLe0mA2uroGHFCxoQA6S9Fuoe6nXEvuu3ZQopVuZpB3Sn7HucDsspNp JXoKHryB/cdDSHgx9N2W7ZoqnVSmIIQwcprBk6gn9zo3YcDOfwEiVpfhw+Vk/d84zzWG aQHYbJm9VIuWtxmUcFuew1wU5CposbIR5GR1v8yHb4fik7VLG17+91q1MOj88orpZOqV JzEOJock8CHAMYbHJOuvfGwJjKGuu3VpAje4HX2pIl0a+qhUKcZujABrMbQ0oF2MyqCw pzTsovpTF3LQ3MTDZmrZ+zQosUNAD0k1u2CaBcVyiymu6Dm19Ea6sVD8Jy9Jcb+9N9PY sHCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1nmdYKj5JRhefeg7ptWM/GYUDy2k/RGB+OV75nbO2PE=; b=adz7Wpx/xhhUq5WUsgZ3GI4Kr0v9eMXeOUm44OLj7qsdCCy2G94lcAGf/hjiVHRe0u s5XuWQXOPyPb35VqL2vTK9OED4GvqL3MUOff6iUpHMtwMZlMuWhop4IC+QzSXPl2nVSf GSYzKJeu0hq6w8/a0FAnWw0mTeTD3mqE+XxindAJRMlBzTT2Pos8JzVGrQ15IU0dsIJf +8Sk93JQGp+IF+ov0cP+0Scum39OJ36R5eIGVyKs/4k1Ujkf337n1YfkMlxrBnn85g+z zUtIsIQM21MS6C2+DK2oszGsVsvfQPOIQhsJWdGlkQb4Mopj8p5rRGmijU6nE4EEIBev Wz9w== X-Gm-Message-State: AGRZ1gIy6JdyNu13uphRvKBN+g00Z3w7ywXfiW/AXxkVTNjGtRI14z1/ i8YSXGNdJ+0tbsEga+4Cy9tCyMCdXE4= X-Google-Smtp-Source: AJdET5eZ3NFZ5aGkYmN5RGf0D09BlmfNM+zctLgomSXsUMhp9DQi7pHfNBseDlB1ZYxFigBf09IeEA== X-Received: by 2002:a1c:6a01:: with SMTP id f1-v6mr4256560wmc.85.1542138786026; Tue, 13 Nov 2018 11:53:06 -0800 (PST) Received: from u.nix.is ([2a01:4f8:190:5095::2]) by smtp.gmail.com with ESMTPSA id y7-v6sm13828560wmy.27.2018.11.13.11.53.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Nov 2018 11:53:05 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Stefan Beller , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 7/7] push doc: document the DWYM behavior pushing to unqualified Date: Tue, 13 Nov 2018 19:52:45 +0000 Message-Id: <20181113195245.14296-8-avarab@gmail.com> X-Mailer: git-send-email 2.19.1.1182.g4ecb1133ce In-Reply-To: <20181026230741.23321-1-avarab@gmail.com> References: <20181026230741.23321-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Document the DWYM behavior that kicks in when pushing to an unqualified reference. This behavior was added in f88395ac23 ("Renaming push.", 2005-08-03) and f8aae12034 ("push: allow unqualified dest refspecs to DWIM", 2008-04-23), and somewhat documented in bb9fca80ce ("git-push: Update description of refspecs and add examples", 2007-06-09), but has never been fully documented. The closest we got to having documented it was the description in the commit message for f8aae12034, which I've borrowed from in writing this documentation. Let's also refer to this new documentation from the existing documentation we had (added in bb9fca80ce). Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-push.txt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index a5fc54aeab..6a8a0d958b 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -73,6 +73,26 @@ be omitted--such a push will update a ref that `` normally updates without any `` on the command line. Otherwise, missing `:` means to update the same ref as the ``. + +If doesn't start with `refs/` (e.g. `refs/heads/master`) we will +try to infer where in `refs/*` on the destination it +belongs based on the the type of being pushed and whether +is ambiguous. ++ +-- +* If unambiguously refers to a ref on the remote, + then push to that ref. + +* If resolves to a ref starting with refs/heads/ or refs/tags/, + then prepend that to . + +* Other ambiguity resolutions might be added in the future, but for + now any other cases will error out with an error indicating what we + tried, and depending on the `advice.pushUnqualifiedRefname` + configuration (see linkgit:git-config[1]) suggest what refs/ + namespace you may have wanted to push to. + +-- ++ The object referenced by is used to update the reference on the remote side. Whether this is allowed depends on where in `refs/*` the reference lives as described in detail below, in @@ -591,6 +611,9 @@ the ones in the examples below) can be configured as the default for `refs/remotes/satellite/master`) in the `mothership` repository; do the same for `dev` and `satellite/dev`. + +See the section describing `...` above for a discussion of +the matching semantics. ++ This is to emulate `git fetch` run on the `mothership` using `git push` that is run in the opposite direction in order to integrate the work done on `satellite`, and is often necessary when you can