From patchwork Thu Oct 10 13:29:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13830127 Received: from aib29agh122.zrh1.oracleemaildelivery.com (aib29agh122.zrh1.oracleemaildelivery.com [192.29.178.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CFF91C9B93 for ; Thu, 10 Oct 2024 13:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567091; cv=none; b=aP6LHFBT0EiRRYawuCVNTg0+IdwuUZT7/fW2VmEi7CUHVT/eRUNaAmlINgnlsV9bPXrlXq7tyUZpO79KRFBLaRxN1pO4I4Hl7HvoRmPu/N0sWn6tbtVUP+Ii0p53vFwjj0lBSndktQFHJfhujISwkEsRHM4fqc9L9fVEz8F0HXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567091; c=relaxed/simple; bh=U/5oeToM9iLpNWNd2s7yuT9IoNDke6srUUe5eW6gh6s=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=iygxm8o9znY71PkSauX6ujMEA19y0KSCIBgF9OtqL+8ZeecpkmhbL6+Ai5RW7UiuFGR8FQO4IeKLfzPazEzZ09lzrpfQ+G4ucKIAkKCfUrTJj/f+PVnOKR4EGdSpyQ8CLDPgkA3pZ7T944e+jAkIWDpWx14+4C9aQZHHv1MfxbI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b=YVkfPl5J; arc=none smtp.client-ip=192.29.178.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b="YVkfPl5J" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=prod-zrh-20200406; d=zrh1.rp.oracleemaildelivery.com; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender:List-Unsubscribe:List-Unsubscribe-Post; bh=rRqhB6izGJR0ZHPbbCVXyQhurHTEKik3tXV75NIM4Mw=; b=YVkfPl5J+kkIZODYnSIRPz6xKawtbzvLhc4wZLT6mSs0gl3XHbuGpHi3JS9xwN8QUUigaE7UVlUU ZatE2RICXx+xK6/83wgAbjzN1EMnSErRj4GumwJXOHc4ZQJgTS9tVvu/DyTuhfHXP60sXHFtbe9W 6Dwhf+L9IQUHpDc/aHLECf7UyJjEIB3s28SFzuBn6UCfS6NwEm59CcLle7vff4HwidspcqBNqMCE 59y5CCmY2rRPKfRe0XqVcD2vouoUjL4/nranfdSXdt7xOzJDRC4QmpeefyY8sWdSqQ/inB4nZt2R 9B0jP4pYp5r3ocRUibobF++lUCKVn9d3t+STsg== Received: by omta-ad1-fd1-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20240911 64bit (built Sep 11 2024)) with ESMTPS id <0SL500I2L6WAFMD0@omta-ad1-fd1-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Thu, 10 Oct 2024 13:31:22 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, Taylor Blau , =?utf-8?q?Ren?= =?utf-8?q?=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , Bence Ferdinandy Subject: [PATCH v6 1/6] refs_update_symref: atomically record overwritten ref Date: Thu, 10 Oct 2024 15:29:56 +0200 Message-id: <20241010133022.1733542-1-bence@ferdinandy.com> In-reply-to: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-transfer-encoding: 8bit Reporting-Meta: AAFYTbWyjGb9yUF5xbtDw9zkPnsxLZJUATDZgLb0C7HxB7jf8X+HY+16Fs59wBRn XB0CFIAggFeYyDhoeApoE5oDtcrcitFKjrSOrvBgrwuK6O65jJ6mM55L7tv23bOt MmmMEiIQRIfhuxqBsgruUPWkux3vRMbbvDPAEK+ELAFYniZbwkR2JC9GAdOvz/xZ lEpc5uQANZKGLE+QI8A+eStosn9VwJOnn257uv8csdzXT8J39rO64h9MHIkL7oCT MG0I+i4iTCSOm8mhin8kVoQrvgP1S2XuoptBS30pDNZDfgQQL1Dq1T2AgIgKO331 PqpVa8bZzfNri8Vq5IZ8jRcIa6P6uUFsuVGne7p3paRGe0gnoCzkHGmu+wwANVJw K2PIkSLzPu94U+PvHDKXwhAvRZHu4Yq1jhCgEzxOZaAxB6znWU65Sb3l1LQ8vRZj wNM0VVrCWA8zgk3brhZD7XfU0i54owgcmLjsurKu1uaJYhiHkmxc48sb When updating a symref it's currently not possible to know for sure what was the previous value that was overwritten. Make use of ref_transaction's atomicity and record the previous value there. Add a new variable to refs_update_symref's signature to be able to pass this information back up to callers. Signed-off-by: Bence Ferdinandy --- Notes: v4: new patch v5: - added before_target to reftables backend - added an extra safety check for transaction's existence in refs.c v6: - no change builtin/branch.c | 2 +- builtin/checkout.c | 4 ++-- builtin/clone.c | 6 +++--- builtin/notes.c | 2 +- builtin/remote.c | 6 +++--- builtin/symbolic-ref.c | 2 +- builtin/worktree.c | 2 +- refs.c | 8 ++++++-- refs.h | 3 ++- refs/files-backend.c | 1 + refs/refs-internal.h | 8 ++++++++ refs/reftable-backend.c | 1 + reset.c | 2 +- sequencer.c | 2 +- setup.c | 2 +- t/helper/test-ref-store.c | 2 +- 16 files changed, 34 insertions(+), 19 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index fd1611ebf5..6c87690b58 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -559,7 +559,7 @@ static int replace_each_worktree_head_symref(struct worktree **worktrees, continue; refs = get_worktree_ref_store(worktrees[i]); - if (refs_update_symref(refs, "HEAD", newref, logmsg)) + if (refs_update_symref(refs, "HEAD", newref, logmsg, NULL)) ret = error(_("HEAD of working tree %s is not updated"), worktrees[i]->path); } diff --git a/builtin/checkout.c b/builtin/checkout.c index 9c30000d3a..356ee9bcde 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1015,7 +1015,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, describe_detached_head(_("HEAD is now at"), new_branch_info->commit); } } else if (new_branch_info->path) { /* Switch branches. */ - if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", new_branch_info->path, msg.buf) < 0) + if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", new_branch_info->path, msg.buf, NULL) < 0) die(_("unable to update HEAD")); if (!opts->quiet) { if (old_branch_info->path && !strcmp(new_branch_info->path, old_branch_info->path)) { @@ -1479,7 +1479,7 @@ static int switch_unborn_to_new_branch(const struct checkout_opts *opts) die(_("You are on a branch yet to be born")); strbuf_addf(&branch_ref, "refs/heads/%s", opts->new_branch); status = refs_update_symref(get_main_ref_store(the_repository), - "HEAD", branch_ref.buf, "checkout -b"); + "HEAD", branch_ref.buf, "checkout -b", NULL); strbuf_release(&branch_ref); if (!opts->quiet) fprintf(stderr, _("Switched to a new branch '%s'\n"), diff --git a/builtin/clone.c b/builtin/clone.c index e77339c847..ead2af20ea 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -661,7 +661,7 @@ static void update_remote_refs(const struct ref *refs, strbuf_addstr(&head_ref, "HEAD"); if (refs_update_symref(get_main_ref_store(the_repository), head_ref.buf, remote_head_points_at->peer_ref->name, - msg) < 0) + msg, NULL) < 0) die(_("unable to update %s"), head_ref.buf); strbuf_release(&head_ref); } @@ -673,7 +673,7 @@ static void update_head(const struct ref *our, const struct ref *remote, const char *head; if (our && skip_prefix(our->name, "refs/heads/", &head)) { /* Local default branch link */ - if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", our->name, NULL) < 0) + if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", our->name, NULL, NULL) < 0) die(_("unable to update HEAD")); if (!option_bare) { refs_update_ref(get_main_ref_store(the_repository), @@ -702,7 +702,7 @@ static void update_head(const struct ref *our, const struct ref *remote, * Unborn head from remote; same as "our" case above except * that we have no ref to update. */ - if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", unborn, NULL) < 0) + if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", unborn, NULL, NULL) < 0) die(_("unable to update HEAD")); if (!option_bare) install_branch_config(0, head, remote_name, unborn); diff --git a/builtin/notes.c b/builtin/notes.c index 8c26e45526..ba646f06ff 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -980,7 +980,7 @@ static int merge(int argc, const char **argv, const char *prefix) die(_("a notes merge into %s is already in-progress at %s"), notes_ref, wt->path); free_worktrees(worktrees); - if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", notes_ref, NULL)) + if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", notes_ref, NULL, NULL)) die(_("failed to store link to current notes ref (%s)"), notes_ref); fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s " diff --git a/builtin/remote.c b/builtin/remote.c index 76670ddd8b..d8ff440027 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -244,7 +244,7 @@ static int add(int argc, const char **argv, const char *prefix) strbuf_reset(&buf2); strbuf_addf(&buf2, "refs/remotes/%s/%s", name, master); - if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote add")) + if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote add", NULL)) result = error(_("Could not setup master '%s'"), master); } @@ -864,7 +864,7 @@ static int mv(int argc, const char **argv, const char *prefix) strbuf_reset(&buf3); strbuf_addf(&buf3, "remote: renamed %s to %s", item->string, buf.buf); - if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, buf3.buf)) + if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, buf3.buf, NULL)) die(_("creating '%s' failed"), buf.buf); display_progress(progress, ++refs_renamed_nr); } @@ -1444,7 +1444,7 @@ static int set_head(int argc, const char **argv, const char *prefix) /* make sure it's valid */ if (!refs_ref_exists(get_main_ref_store(the_repository), buf2.buf)) result |= error(_("Not a valid ref: %s"), buf2.buf); - else if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote set-head")) + else if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote set-head", NULL)) result |= error(_("Could not setup %s"), buf.buf); else if (opt_a) printf("%s/HEAD set to %s\n", argv[0], head_name); diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c index 299d23d76a..7728fbc3c1 100644 --- a/builtin/symbolic-ref.c +++ b/builtin/symbolic-ref.c @@ -88,7 +88,7 @@ int cmd_symbolic_ref(int argc, if (check_refname_format(argv[1], REFNAME_ALLOW_ONELEVEL) < 0) die("Refusing to set '%s' to invalid ref '%s'", argv[0], argv[1]); ret = !!refs_update_symref(get_main_ref_store(the_repository), - argv[0], argv[1], msg); + argv[0], argv[1], msg, NULL); break; default: usage_with_options(git_symbolic_ref_usage, options); diff --git a/builtin/worktree.c b/builtin/worktree.c index fc31d072a6..a7ab4193c1 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -517,7 +517,7 @@ static int add_worktree(const char *path, const char *refname, ret = refs_update_ref(wt_refs, NULL, "HEAD", &commit->object.oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR); else - ret = refs_update_symref(wt_refs, "HEAD", symref.buf, NULL); + ret = refs_update_symref(wt_refs, "HEAD", symref.buf, NULL, NULL); if (ret) goto done; diff --git a/refs.c b/refs.c index 5f729ed412..91cacee6f9 100644 --- a/refs.c +++ b/refs.c @@ -2114,7 +2114,8 @@ int peel_iterated_oid(struct repository *r, const struct object_id *base, struct } int refs_update_symref(struct ref_store *refs, const char *ref, - const char *target, const char *logmsg) + const char *target, const char *logmsg, + struct strbuf *before_target) { struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; @@ -2130,6 +2131,10 @@ int refs_update_symref(struct ref_store *refs, const char *ref, } strbuf_release(&err); + + if (transaction && before_target && transaction->updates[0]->before_target) + strbuf_addstr(before_target, transaction->updates[0]->before_target); + if (transaction) ref_transaction_free(transaction); @@ -2948,4 +2953,3 @@ int ref_update_expects_existing_old_ref(struct ref_update *update) return (update->flags & REF_HAVE_OLD) && (!is_null_oid(&update->old_oid) || update->old_target); } - diff --git a/refs.h b/refs.h index 108dfc93b3..f38616db84 100644 --- a/refs.h +++ b/refs.h @@ -571,7 +571,8 @@ int refs_copy_existing_ref(struct ref_store *refs, const char *oldref, const char *newref, const char *logmsg); int refs_update_symref(struct ref_store *refs, const char *refname, - const char *target, const char *logmsg); + const char *target, const char *logmsg, + struct strbuf *before_target); enum action_on_err { UPDATE_REFS_MSG_ON_ERR, diff --git a/refs/files-backend.c b/refs/files-backend.c index 0824c0b8a9..8415f2d020 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -2577,6 +2577,7 @@ static int lock_ref_for_update(struct files_ref_store *refs, } update->backend_data = lock; + update->before_target = xstrdup_or_null(referent.buf); if (update->type & REF_ISSYMREF) { if (update->flags & REF_NO_DEREF) { diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 2313c830d8..7df3e6271e 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -104,6 +104,14 @@ struct ref_update { */ const char *old_target; + /* + * The previous target before applying new_target will be + * written here, to be used by callers when they do not want to + * check old_target during the transaction, but do want to know + * what it was. + */ + const char *before_target; + /* * One or more of REF_NO_DEREF, REF_FORCE_CREATE_REFLOG, * REF_HAVE_NEW, REF_HAVE_OLD, or backend-specific flags. diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 3c96fbf66f..32330b6bc6 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -1244,6 +1244,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, if (ret) goto done; } + u->before_target = xstrdup_or_null(referent.buf); } transaction->backend_data = tx_data; diff --git a/reset.c b/reset.c index b22b1be792..cc36a9ed56 100644 --- a/reset.c +++ b/reset.c @@ -76,7 +76,7 @@ static int update_refs(const struct reset_head_opts *opts, if (!ret) ret = refs_update_symref(get_main_ref_store(the_repository), "HEAD", switch_to_branch, - reflog_head); + reflog_head, NULL); } if (!ret && run_hook) run_hooks_l(the_repository, "post-checkout", diff --git a/sequencer.c b/sequencer.c index 8d01cd50ac..23b162924c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -5107,7 +5107,7 @@ static int pick_commits(struct repository *r, } msg = reflog_message(opts, "finish", "returning to %s", head_ref.buf); - if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", head_ref.buf, msg)) { + if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", head_ref.buf, msg, NULL)) { res = error(_("could not update HEAD to %s"), head_ref.buf); goto cleanup_head_ref; diff --git a/setup.c b/setup.c index 94e79b2e48..d95f051465 100644 --- a/setup.c +++ b/setup.c @@ -2275,7 +2275,7 @@ void create_reference_database(enum ref_storage_format ref_storage_format, die(_("invalid initial branch name: '%s'"), initial_branch); - if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", ref, NULL) < 0) + if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", ref, NULL, NULL) < 0) exit(1); free(ref); } diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index 65346dee55..a911302bea 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -120,7 +120,7 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv) const char *target = notnull(*argv++, "target"); const char *logmsg = *argv++; - return refs_update_symref(refs, refname, target, logmsg); + return refs_update_symref(refs, refname, target, logmsg, NULL); } static struct flag_definition transaction_flags[] = { From patchwork Thu Oct 10 13:29:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13830126 Received: from aib29agh126.zrh1.oracleemaildelivery.com (aib29agh126.zrh1.oracleemaildelivery.com [192.29.178.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82CD41BC9EE for ; Thu, 10 Oct 2024 13:31:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.126 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567091; cv=none; b=TeDuwipkb8kAvr03fGJEMfWzXTHVwY0WBH3ws78ItLadUsIpVyhSieSwbPLBAEZTyDHGuMlPPeBrbBCeALjxgJbJF4xYLyqDNIbzNCx/N9+1ggvnU2JMYsKw1japsE2GqKOjTUlIuLmKv6WQeMK4A3n83Ad0mo5XEuuELH2HV0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567091; c=relaxed/simple; bh=KjLrT6AtkPAaW/T4+4fKwyhi9iL8bnzuiatHCasR57M=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=Q8YLKmoWlsYAcDePJmfRNfKF9lOGeqOEhHnxuZpOZET+YnUoB4aSG5YeI61hGPA1pd2Gm+ACgveYWdki/esbKn8XaJqmdLjOfpyIWlguIWzCU7F1sMTlH95mCAZTg6E9ooXbIB6Yf/hhY1k0PbPPwONCutQJ0BRcOUjWmp8YNLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b=YtwxTyCH; arc=none smtp.client-ip=192.29.178.126 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b="YtwxTyCH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=prod-zrh-20200406; d=zrh1.rp.oracleemaildelivery.com; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender:List-Unsubscribe:List-Unsubscribe-Post; bh=E4jh3raTHhR1HY2eZIFVgcPEBvjlZZxGN7Ryaj9pfww=; b=YtwxTyCHZMqN0ugK4E/u4/Bz4+I36EkJOru22Sl6JXa7quU8JB041JTBrt3HUjzqAh1PmjbdaDSD YyVW8PClI6T7RBVQTGaslsZTgDkWqGDN82Tk5ORjqm2ozjd8ZBowjBOMKXkMN+d+dpNEXBLF4M02 lVPaXK3UqRBhf1T5FS3Uf0UP5JvZLjMJj5vlyNZfNOcw66min4M/xwT7snaxHIsA9mY8zocL5yZU yp0pjQGGN/bXh5Fly8fdVx9VmKstn1wncztg6aqp+kjo8C316VwfA42AHEoLRsaCnnUoIdzIyjjv r3PivtLCK6EL7Wu9yqCtpCbeyHVgFyQ4CfWFvQ== Received: by omta-ad1-fd3-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20240911 64bit (built Sep 11 2024)) with ESMTPS id <0SL500HWI6WAMCB0@omta-ad1-fd3-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Thu, 10 Oct 2024 13:31:22 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, Taylor Blau , =?utf-8?q?Ren?= =?utf-8?q?=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , Bence Ferdinandy Subject: [PATCH v6 2/6] set-head: add new variable for readability Date: Thu, 10 Oct 2024 15:29:57 +0200 Message-id: <20241010133022.1733542-2-bence@ferdinandy.com> In-reply-to: <20241010133022.1733542-1-bence@ferdinandy.com> References: <20241010133022.1733542-1-bence@ferdinandy.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-transfer-encoding: 8bit Reporting-Meta: AAFkClu7NkgDEEonQIdFjym5PUIXUg+VdM8Ay2cp+dCBY9xLP4cUVO/XMVf0/mOI U+17Ngn0FwXy+vKWWKc6Fb+bdkNajqEU0GQyBNntafcINY7bVXWrZ9CAdA5WzP3H leLdmCMuJaeCj2G2ySwBLD7yboqXRvrmXqNNM+5GBfMuC71QNyBe/1r858ibfSNu 0m/fLDOXkzB4fhfaKSYn+2B5/ln9xrENKSq1ARx/746nd+JRZhaBoooBMSCEFqAE 3SG+wCKM4J8Jz8PTOBwJyJGaqH4ICduULnkz2LY0eXuXa3emymrZekJbHM6PpzXF xXPmXJZBfJ0ViDjbGcCSLPlBm8KjD6286YxIcNfeqrvpKg80tD0ojmFbXpk0qmKV ZZq/FpSY0u4Fw7rjCNB5eDzZ3HZHd7aaZCvPCz4SEkSxhqgSePhOopWaLbT1bbZw EIlvzTm4z+i1mY6h2LEbl2OHufKF6yo6iX3n6U2XHLj9+IikuT8hyjM= Instead of calling get_main_ref_store(the_repository) multiple times, call it once and store in a new refs variable. Although this change probably offers some performance benefits, the main purpose is to shorten the line lengths of function calls using this variable for better readability. Signed-off-by: Bence Ferdinandy --- Notes: v5: new patch (split from the next patch as a preparatory step) v6: no change builtin/remote.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index d8ff440027..353ffd2c43 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1404,6 +1404,7 @@ static int set_head(int argc, const char **argv, const char *prefix) int i, opt_a = 0, opt_d = 0, result = 0; struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; char *head_name = NULL; + struct ref_store *refs = get_main_ref_store(the_repository); struct option options[] = { OPT_BOOL('a', "auto", &opt_a, @@ -1434,7 +1435,7 @@ static int set_head(int argc, const char **argv, const char *prefix) head_name = xstrdup(states.heads.items[0].string); free_remote_ref_states(&states); } else if (opt_d && !opt_a && argc == 1) { - if (refs_delete_ref(get_main_ref_store(the_repository), NULL, buf.buf, NULL, REF_NO_DEREF)) + if (refs_delete_ref(refs, NULL, buf.buf, NULL, REF_NO_DEREF)) result |= error(_("Could not delete %s"), buf.buf); } else usage_with_options(builtin_remote_sethead_usage, options); @@ -1442,9 +1443,9 @@ static int set_head(int argc, const char **argv, const char *prefix) if (head_name) { strbuf_addf(&buf2, "refs/remotes/%s/%s", argv[0], head_name); /* make sure it's valid */ - if (!refs_ref_exists(get_main_ref_store(the_repository), buf2.buf)) + if (!refs_ref_exists(refs, buf2.buf)) result |= error(_("Not a valid ref: %s"), buf2.buf); - else if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote set-head", NULL)) + else if (refs_update_symref(refs, buf.buf, buf2.buf, "remote set-head", NULL)) result |= error(_("Could not setup %s"), buf.buf); else if (opt_a) printf("%s/HEAD set to %s\n", argv[0], head_name); From patchwork Thu Oct 10 13:29:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13830129 Received: from aib29agh127.zrh1.oracleemaildelivery.com (aib29agh127.zrh1.oracleemaildelivery.com [192.29.178.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 808B51C9DC1 for ; Thu, 10 Oct 2024 13:32:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.127 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567137; cv=none; b=XWMGVFnhGS6yYVFY/4T08rte2MVrT0gFlUarV0uM2WfQqqta0j5LaNbeOk26gLo/FQVFAA0icmC5EYU+EbsJLOqgLd/8saTsbxBZdA0eWU4qTmY7/XiGV420mR4pKKRBVAa11KP3aPBNtKaUfshAeYcnBqbNOPh7h+nJZgfH4No= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567137; c=relaxed/simple; bh=G5QjMlw6P5uTFXX21zjsHM0s6NANM6A5C6jtJJcONvQ=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=khJIVfRGqf7TjGMIiwzeCis3j3oMEkIsxvA9Hn7ozLomKDdfM80spUs5ZLj4Fp/HiMvVPDcUvSG8qbFocrdHJtY3Usq6erFfrcXmIwU60KzuEXCq8Wk6oulVIyQMxNTybThhj9dbh0vCjdKr0eMm55IDfh0x8Yq2CFXZk5//5as= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b=bhlRoJQd; arc=none smtp.client-ip=192.29.178.127 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b="bhlRoJQd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=prod-zrh-20200406; d=zrh1.rp.oracleemaildelivery.com; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender:List-Unsubscribe:List-Unsubscribe-Post; bh=+YJrJT1CSa7WJg5lwQrwdQfMqp1FFNeOPktQR2I1Ips=; b=bhlRoJQdUguVtUP7XlssjlxlQpaZHXw7eX4o57r/KsfdYszsSRBA5IvCIinPdo2IXmuah0+/3lw6 f/CBkKmMp6aPuLXal64QCttPZnF1kpXQX5sz8pzEXTmJhibigiZGGnu+t4U/1vR4P8hfo8ES6xXb LqDTnDNHus66KyipvCoeMoeArEqpGS0m9He6Ey9E8dXYXCk33qRMRI/M7Wtrvz1kvuzx+qVIeNDk yhqLTmLHU71wV+obz7mHtkptd0Stk54GdA74B7W6WQ4gPVfulv89ejdCgIDeIvV71uBjMVAQOwiW 5J/MsHhQOiA8DEU1pW7zdTRndDbyiX9+HGaIbw== Received: by omta-ad1-fd3-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20240911 64bit (built Sep 11 2024)) with ESMTPS id <0SL500AXS6XPVA30@omta-ad1-fd3-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Thu, 10 Oct 2024 13:32:13 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, Taylor Blau , =?utf-8?q?Ren?= =?utf-8?q?=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , Bence Ferdinandy Subject: [PATCH v6 3/6] set-head: better output for --auto Date: Thu, 10 Oct 2024 15:29:58 +0200 Message-id: <20241010133022.1733542-3-bence@ferdinandy.com> In-reply-to: <20241010133022.1733542-1-bence@ferdinandy.com> References: <20241010133022.1733542-1-bence@ferdinandy.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-transfer-encoding: 8bit Reporting-Meta: AAFYTbWyjGb9yUF5xbtDw9zkPnsxLZJUATDZgLb0C7HxB7jf8X+HY+16Fs59wBRn XB0CFIAggFeYyDhoeAqFE5oDtcrcitFKjrTVc9TCd7VjCgM5GzJntUi3841OES5A mRySKYXnQIva8+ge9EVOV8tL89aWvQ4z12aMY6HXml8Kd1d0ohtT9mmNRkT8yLr5 l+4ZWp1ipLqCYGELfdtTkp7noc4hzYlC6VJjAAsskK2wWpT0uY1TU77DUQ7qhQHD WGh63hNmt5kf1QY5r4+xrYOS+GrG6IPspFTVYCIZMX6hiQK2VxW2nG8x3aMyPOf+ HXZSoQtMYhec76zRKrpn41hGfXDgAMOF9BQLqrToFikuuGM26kbk99KHHw5AEAPe 4JHkjlcLnaYdwOJIIArRQl/z9/M1b6DH3nYyBfUNGAKZj2yGvOSH7MUD9LwKTfIs 9KwXTktRCseesWCRuhZVaGdbaZd2fUbPp2y7cApmMExOsLMDy7uRU9c= Currently, set-head --auto will print a message saying "remote/HEAD set to branch", which implies something was changed. Change the output of --auto, so the output actually reflects what was done: a) set a previously unset HEAD, b) change HEAD because remote changed or c) no updates. As a fourth output, if HEAD is changed from a previous value that was not a remote branch, explicitly call attention to this fact. Signed-off-by: Bence Ferdinandy --- Notes: v1-v2: was RFC in https://lore.kernel.org/git/20240910203835.2288291-1-bence@ferdinandy.com/ v3: This patch was originally sent along when I thought set-head was going to be invoked by fetch, but the discussion on the RFC concluded that it should be not. This opened the possibility to make it more explicit. Note: although I feel both things the patch does are really just cosmetic, an argument could be made for breaking it into two, one for the no-op part and one for the --auto print update. Was sent in: https://lore.kernel.org/git/20240915221055.904107-1-bence@ferdinandy.com/ v4: - changes are now handled atomically via the ref update transaction - outputs have changed along the lines of Junio's suggestion - minor refactor to set_head for improved legibility v5: - the minor refactor has been split out into its own patch v6: - fixed uninitialized prev_head - fixed case of unusual previous target - fixed a test that would have been actually broken at this patch (the output was only correct with the later update to fetch) - added 4 tests for the 4 output cases builtin/remote.c | 34 +++++++++++++++++++++++++++---- t/t5505-remote.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 353ffd2c43..24f9caf149 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1399,10 +1399,34 @@ static int show(int argc, const char **argv, const char *prefix) return result; } +static void report_auto(const char *remote, const char *head_name, + struct strbuf *buf_prev) { + struct strbuf buf_prefix = STRBUF_INIT; + const char *prev_head = NULL; + + strbuf_addf(&buf_prefix, "refs/remotes/%s/", remote); + skip_prefix(buf_prev->buf, buf_prefix.buf, &prev_head); + + if (prev_head && !strcmp(prev_head, head_name)) + printf("'%s/HEAD' is unchanged and points to '%s'\n", + remote, head_name); + else if (prev_head) + printf("'%s/HEAD' has changed from '%s' and now points to '%s'\n", + remote, prev_head, head_name); + else if (buf_prev->len == 0) + printf("'%s/HEAD' is now created and points to '%s'\n", + remote, head_name); + else + printf("'%s/HEAD' used to point to '%s' " + "(which is unusual), but now points to '%s'\n", + remote, buf_prev->buf, head_name); +} + static int set_head(int argc, const char **argv, const char *prefix) { int i, opt_a = 0, opt_d = 0, result = 0; - struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; + struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, + buf_prev = STRBUF_INIT; char *head_name = NULL; struct ref_store *refs = get_main_ref_store(the_repository); @@ -1445,15 +1469,17 @@ static int set_head(int argc, const char **argv, const char *prefix) /* make sure it's valid */ if (!refs_ref_exists(refs, buf2.buf)) result |= error(_("Not a valid ref: %s"), buf2.buf); - else if (refs_update_symref(refs, buf.buf, buf2.buf, "remote set-head", NULL)) + else if (refs_update_symref(refs, buf.buf, buf2.buf, "remote set-head", &buf_prev)) result |= error(_("Could not setup %s"), buf.buf); - else if (opt_a) - printf("%s/HEAD set to %s\n", argv[0], head_name); + else if (opt_a) { + report_auto(argv[0], head_name, &buf_prev); + } free(head_name); } strbuf_release(&buf); strbuf_release(&buf2); + strbuf_release(&buf_prev); return result; } diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 532035933f..77c12b8709 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -429,12 +429,51 @@ test_expect_success 'set-head --auto' ' ) ' +test_expect_success 'set-head --auto detects creation' ' + ( + cd test && + rm .git/refs/remotes/origin/HEAD && + git remote set-head --auto origin >output && + echo "'\''origin/HEAD'\'' is now created and points to '\''main'\''" >expect && + test_cmp expect output + ) +' + +test_expect_success 'set-head --auto detects no change' ' + ( + cd test && + git remote set-head --auto origin >output && + echo "'\''origin/HEAD'\'' is unchanged and points to '\''main'\''" >expect && + test_cmp expect output + ) +' + +test_expect_success 'set-head --auto detects change' ' + ( + cd test && + echo "ref: refs/remotes/origin/ahead" >.git/refs/remotes/origin/HEAD && + git remote set-head --auto origin >output && + echo "'\''origin/HEAD'\'' has changed from '\''ahead'\'' and now points to '\''main'\''" >expect && + test_cmp expect output + ) +' + +test_expect_success 'set-head --auto detects strange ref' ' + ( + cd test && + echo "ref: refs/heads/main" >.git/refs/remotes/origin/HEAD && + git remote set-head --auto origin >output && + echo "'\''origin/HEAD'\'' used to point to '\''refs/heads/main'\'' (which is unusual), but now points to '\''main'\''" >expect && + test_cmp expect output + ) +' + test_expect_success 'set-head --auto has no problem w/multiple HEADs' ' ( cd test && git fetch two "refs/heads/*:refs/remotes/two/*" && git remote set-head --auto two >output 2>&1 && - echo "two/HEAD set to main" >expect && + echo "'\''two/HEAD'\'' is now created and points to '\''main'\''" >expect && test_cmp expect output ) ' @@ -453,6 +492,17 @@ test_expect_success 'set-head explicit' ' ) ' + +test_expect_success 'set-head --auto reports change' ' + ( + cd test && + git remote set-head origin side2 && + git remote set-head --auto origin >output 2>&1 && + echo "'\''origin/HEAD'\'' has changed from '\''side2'\'' and now points to '\''main'\''" >expect && + test_cmp expect output + ) +' + cat >test/expect < X-Patchwork-Id: 13830128 Received: from aib29agh125.zrh1.oracleemaildelivery.com (aib29agh125.zrh1.oracleemaildelivery.com [192.29.178.125]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E8401C9B93 for ; Thu, 10 Oct 2024 13:32:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.125 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567137; cv=none; b=RAkyijAjxthQbFaWDuQ7cn5PLTsZCCVEFseNisTAUp0ykGzCeUiz5cdx9HmM/pU8JqpxDBfbIosi3TuYgFHQ4ClgNxPOCyUwP0fFxYnbTo6ttSFlbjuYO6mXKhxokNElD5f7Wdap6Qef98K3dxHjDxe7HKPRRyD0Rqmn3r6w3Vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567137; c=relaxed/simple; bh=43xQxz1mRyqodKszddgcIkO9uzCg+2dEQ4wqrzU25Ks=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=n9PtLPkkx25pPRsde+G8a2tKv4JwXm0O98n5iW7NvYFwFu/OBObLCJGccmksH9VChClXpwJjoUeUgmeWIh4yM81lQS+kdL7v3AZGr8W4szaize7hpq10Z9LKQBt6m3nt2vK4f2SjLo5iuQTKLvG7F3B90oaKucdfOt1GHQLWwNg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b=IYmfSmWj; arc=none smtp.client-ip=192.29.178.125 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b="IYmfSmWj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=prod-zrh-20200406; d=zrh1.rp.oracleemaildelivery.com; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender:List-Unsubscribe:List-Unsubscribe-Post; bh=waFNkvwRYA1coPqM/A4ZDfVLvvFkqO9yLi0FgXp178Q=; b=IYmfSmWjdAY9IADNseuV5mbS4SeWqTkytKOH8Omys6+aZGlnDhLMW1ne44xhPUjv4DBvSSMcMtxM 55kDip/YxdQzSDHAku59nGTZUYYqChoVZ8Cm0gBkJ2FMzN7vhGpJ35UH9dRHoxPLEZNS8/qpQVll 8Fy+Hxg4Nm9a0hFNpWyRM1oC7TNF0UpyW021c7DWgOv/Y3y+Ykg0qY5LC83/HQtuqRFdsp4qgJVW b+/y3AXIF4Bcc+0e7ghMqIlfBRtuVmakqU30gTUALKy9EnnpFDgWTiQtfmLdpvhZMg81r+3RjVQJ eNvMDTfS4F51IssIJh5Bh5lwHwdIOGTMwSb5uw== Received: by omta-ad1-fd2-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20240911 64bit (built Sep 11 2024)) with ESMTPS id <0SL50074Y6XPUMD0@omta-ad1-fd2-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Thu, 10 Oct 2024 13:32:13 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, Taylor Blau , =?utf-8?q?Ren?= =?utf-8?q?=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , Bence Ferdinandy Subject: [PATCH v6 4/6] transaction: add TRANSACTION_CREATE_EXISTS error Date: Thu, 10 Oct 2024 15:29:59 +0200 Message-id: <20241010133022.1733542-4-bence@ferdinandy.com> In-reply-to: <20241010133022.1733542-1-bence@ferdinandy.com> References: <20241010133022.1733542-1-bence@ferdinandy.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-transfer-encoding: 8bit Reporting-Meta: AAFkClu7NkgDEEonQIdFjym5PUIXUg+VdM8Ay2cp+dCBY9xLP4cUVO/XMVf0/mOI U+17Ngn0FwXy+vKWWKdEFb+bdkNajqEU0GSe+pPEmrNYkM1cjbuxIVszbzUk6d9Q 8MyIgi42rl2UyFugOA+jlvtLfg4PiZfVkPKY+3hEHo2CqG3H5teSvBIu+zTrsYPA 09DJ+tNX/AhOwsQ8l8A8xKPq2uFwMFI2nIvOtHyPkmLFp9/9LDpQTUVZXpxwCB7D xvxBQ4hzgQkZ0bFvAqDXfyJjN4ElhGWGgi1HoTjUOQvR2ae9IlCwXujmm62RcWzN r0yWr9k/9DoxmgSsMCw9OrGo8H1rWh8s1jv6CApIU441u7d/5968xfGoYAA0wYsH RpHdNLWorkvZbItqaPxldgpFos3fYUhwGZKzVPhk5NcxEQvOWIeSW7+qtTWR8hJp 2w8BZp7CA/rOqzL/fsxJUOP1aZ3CiLj6AtvSv3c0hWkzXksGjganVtM= Currently there is only one special error for transaction, for when there is a naming conflict, all other errors are dumped under a generic error. Add a new special error case for when the caller requests the reference to be updated only when it does not yet exist and the reference actually does exist. Signed-off-by: Bence Ferdinandy --- Notes: v4: new patch v5: no change v6: no change refs.h | 4 +++- refs/files-backend.c | 28 ++++++++++++++++++++-------- refs/reftable-backend.c | 6 ++++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/refs.h b/refs.h index f38616db84..166affbc89 100644 --- a/refs.h +++ b/refs.h @@ -759,8 +759,10 @@ int ref_transaction_verify(struct ref_transaction *transaction, /* Naming conflict (for example, the ref names A and A/B conflict). */ #define TRANSACTION_NAME_CONFLICT -1 +/* When only creation was requested, but the ref already exists. */ +#define TRANSACTION_CREATE_EXISTS -2 /* All other errors. */ -#define TRANSACTION_GENERIC_ERROR -2 +#define TRANSACTION_GENERIC_ERROR -3 /* * Perform the preparatory stages of committing `transaction`. Acquire diff --git a/refs/files-backend.c b/refs/files-backend.c index 8415f2d020..272ad81315 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -2502,14 +2502,18 @@ static int split_symref_update(struct ref_update *update, static int check_old_oid(struct ref_update *update, struct object_id *oid, struct strbuf *err) { + int ret = TRANSACTION_GENERIC_ERROR; + if (!(update->flags & REF_HAVE_OLD) || oideq(oid, &update->old_oid)) return 0; - if (is_null_oid(&update->old_oid)) + if (is_null_oid(&update->old_oid)) { strbuf_addf(err, "cannot lock ref '%s': " "reference already exists", ref_update_original_update_refname(update)); + ret = TRANSACTION_CREATE_EXISTS; + } else if (is_null_oid(oid)) strbuf_addf(err, "cannot lock ref '%s': " "reference is missing but expected %s", @@ -2522,7 +2526,7 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid, oid_to_hex(oid), oid_to_hex(&update->old_oid)); - return -1; + return ret; } /* @@ -2603,9 +2607,13 @@ static int lock_ref_for_update(struct files_ref_store *refs, ret = TRANSACTION_GENERIC_ERROR; goto out; } - } else if (check_old_oid(update, &lock->old_oid, err)) { - ret = TRANSACTION_GENERIC_ERROR; - goto out; + } else { + int checkret; + checkret = check_old_oid(update, &lock->old_oid, err); + if (checkret) { + ret = checkret; + goto out; + } } } else { /* @@ -2636,9 +2644,13 @@ static int lock_ref_for_update(struct files_ref_store *refs, update->old_target); ret = TRANSACTION_GENERIC_ERROR; goto out; - } else if (check_old_oid(update, &lock->old_oid, err)) { - ret = TRANSACTION_GENERIC_ERROR; - goto out; + } else { + int checkret; + checkret = check_old_oid(update, &lock->old_oid, err); + if (checkret) { + ret = checkret; + goto out; + } } /* diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 32330b6bc6..c6b25ebac4 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -1206,10 +1206,13 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, goto done; } } else if ((u->flags & REF_HAVE_OLD) && !oideq(¤t_oid, &u->old_oid)) { - if (is_null_oid(&u->old_oid)) + ret = TRANSACTION_NAME_CONFLICT; + if (is_null_oid(&u->old_oid)) { strbuf_addf(err, _("cannot lock ref '%s': " "reference already exists"), ref_update_original_update_refname(u)); + ret = TRANSACTION_CREATE_EXISTS; + } else if (is_null_oid(¤t_oid)) strbuf_addf(err, _("cannot lock ref '%s': " "reference is missing but expected %s"), @@ -1221,7 +1224,6 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, ref_update_original_update_refname(u), oid_to_hex(¤t_oid), oid_to_hex(&u->old_oid)); - ret = -1; goto done; } From patchwork Thu Oct 10 13:30:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13830130 Received: from aib29agh123.zrh1.oracleemaildelivery.com (aib29agh123.zrh1.oracleemaildelivery.com [192.29.178.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4345F1BC9EE for ; Thu, 10 Oct 2024 13:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567205; cv=none; b=YELQ5VJ5hJrrcV9lCdSPObfxt8y3VSRK5dwboZNTRQtvNeC2r5+70SCk9E7Y6aq9L7Ei2WbvMf4hurTzOWY87cyUVQV3flpwkNZbiOWTQEL9IS5J+YraylH7ZRhQJB6QS/it0ucyA3nnN7oYJQUdnjqUCpSm+2oligbaUWt+s44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567205; c=relaxed/simple; bh=jQvoiAN2vpzAfr13/DXF1fzootMxKajiEkfEsNmD2HM=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=qHicV16JHgY5lbboKaFoRbOGq7xbRqn4aabWLM8am5YBGMjGn6M8Up/oslGPExb8CpheUr57F0zN2TkqeA0RpoJF6HDyNJKVKX3WBuC8ncaA2aIgTGxTwErKBgs4xggYKGuT+wIl9l5qqbxw1zGbyCeAs0KL8e+3bOGtP623lBo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b=JhzMb542; arc=none smtp.client-ip=192.29.178.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b="JhzMb542" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=prod-zrh-20200406; d=zrh1.rp.oracleemaildelivery.com; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender:List-Unsubscribe:List-Unsubscribe-Post; bh=S0ne6qec74gVBvz33MpZXW9lLh8B7Nj53EodC8Jo/KQ=; b=JhzMb5421o5xrrDmyVzJ2/mF2VWKO1yTn71qqR69w7w9BZCS1d391Qtwy76bs4N+AJAIEZ3Iu4ac GcQQpnVW7BYFdnN2rFPYN8BGT/ld8pYXd7FNxNGzcVoNE/Ux4SXLhBFrN3XMvFZz6aUDdueRAJCm x3fLg4nXEvjnWqptNaBnlqTssRmZCkNtlf8vjR3H3ujf+IJgWtusYPEHtSPq17ZfZtX+jIU37hQQ 8uIfKCPtYJN3FoYe+M9GWt2rn1vkbD+3QNmcQaQQPmswfeP9ePdS3wKCqvK2S4S05YQNw4fV66oT Y9ZPDGr4WKN8pUmNTExf0BPV2TqPK6pCvx7TjA== Received: by omta-ad1-fd1-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20240911 64bit (built Sep 11 2024)) with ESMTPS id <0SL500JYH6ZKZ150@omta-ad1-fd1-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Thu, 10 Oct 2024 13:33:20 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, Taylor Blau , =?utf-8?q?Ren?= =?utf-8?q?=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , Bence Ferdinandy Subject: [PATCH v6 5/6] refs_update_symref: add create_only option Date: Thu, 10 Oct 2024 15:30:00 +0200 Message-id: <20241010133022.1733542-5-bence@ferdinandy.com> In-reply-to: <20241010133022.1733542-1-bence@ferdinandy.com> References: <20241010133022.1733542-1-bence@ferdinandy.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-transfer-encoding: 8bit Reporting-Meta: AAFkClu7NkgDEEonQIdFjym5PUIXUg+VdM8Ay2cp+dCBY9xLP4cUVO/XMVf0/mOI U+17Ngn0FwXy+vKWWKeOFb+bdkNajqEU0GTCmXJMsnUwzkhT5v/xmTqXFaSXh3QX VlhP6nGuTzkj17zDEm+RJXX+tqDWnt2B7tgkYj6cZvBox+3rscc8II5glRS1GzqL AEkQC6g3/I1jpapMaKDtp6Vk6JzDw2ws/1svnbUWM1aO1NapTOgGp2aWK4hIqtBA m0SIvzYth/c47SuFPjrizGoiok7aE1F0bFP1qwy0iXPaGyeLQisvfl4K1lkY2M3B N854MlS8PVvcdlQmEDXsPd5t1EiYY0dWrgUO8WqyBUgyHSyE9k/4mC1TedyuKudV XoEMpxQeKnTCXqkmvsi6X+rFtULnX28sskXYHzaw/J+uogqNX50ak/L9Zi/CNMdC V6u0mM/92jBx2LdKL8FBna+AQgO64DDRNhzd7tpEdK8lIOfemEJplxDk Allow the caller to specify that it only wants to update the symref if it does not already exist. Silently ignore the error from the transaction API if the symref already exists. Signed-off-by: Bence Ferdinandy --- Notes: v4: new patch v5: no change v6: - switched from bool to int for create_only - refactored logic in refs_update_symref with goto as layed out by Junio builtin/branch.c | 2 +- builtin/checkout.c | 5 +++-- builtin/clone.c | 8 +++++--- builtin/notes.c | 3 ++- builtin/remote.c | 9 ++++++--- builtin/symbolic-ref.c | 2 +- builtin/worktree.c | 2 +- refs.c | 36 +++++++++++++++++++++++++----------- refs.h | 2 +- reset.c | 2 +- sequencer.c | 3 ++- setup.c | 3 ++- t/helper/test-ref-store.c | 2 +- 13 files changed, 51 insertions(+), 28 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index 6c87690b58..2fcbcbfd59 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -559,7 +559,7 @@ static int replace_each_worktree_head_symref(struct worktree **worktrees, continue; refs = get_worktree_ref_store(worktrees[i]); - if (refs_update_symref(refs, "HEAD", newref, logmsg, NULL)) + if (refs_update_symref(refs, "HEAD", newref, logmsg, NULL, 0)) ret = error(_("HEAD of working tree %s is not updated"), worktrees[i]->path); } diff --git a/builtin/checkout.c b/builtin/checkout.c index 356ee9bcde..9abb71dc07 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1015,7 +1015,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts, describe_detached_head(_("HEAD is now at"), new_branch_info->commit); } } else if (new_branch_info->path) { /* Switch branches. */ - if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", new_branch_info->path, msg.buf, NULL) < 0) + if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", new_branch_info->path, + msg.buf, NULL, 0) < 0) die(_("unable to update HEAD")); if (!opts->quiet) { if (old_branch_info->path && !strcmp(new_branch_info->path, old_branch_info->path)) { @@ -1479,7 +1480,7 @@ static int switch_unborn_to_new_branch(const struct checkout_opts *opts) die(_("You are on a branch yet to be born")); strbuf_addf(&branch_ref, "refs/heads/%s", opts->new_branch); status = refs_update_symref(get_main_ref_store(the_repository), - "HEAD", branch_ref.buf, "checkout -b", NULL); + "HEAD", branch_ref.buf, "checkout -b", NULL, 0); strbuf_release(&branch_ref); if (!opts->quiet) fprintf(stderr, _("Switched to a new branch '%s'\n"), diff --git a/builtin/clone.c b/builtin/clone.c index ead2af20ea..87e8f1421a 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -661,7 +661,7 @@ static void update_remote_refs(const struct ref *refs, strbuf_addstr(&head_ref, "HEAD"); if (refs_update_symref(get_main_ref_store(the_repository), head_ref.buf, remote_head_points_at->peer_ref->name, - msg, NULL) < 0) + msg, NULL, 0) < 0) die(_("unable to update %s"), head_ref.buf); strbuf_release(&head_ref); } @@ -673,7 +673,8 @@ static void update_head(const struct ref *our, const struct ref *remote, const char *head; if (our && skip_prefix(our->name, "refs/heads/", &head)) { /* Local default branch link */ - if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", our->name, NULL, NULL) < 0) + if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", our->name, + NULL, NULL, 0) < 0) die(_("unable to update HEAD")); if (!option_bare) { refs_update_ref(get_main_ref_store(the_repository), @@ -702,7 +703,8 @@ static void update_head(const struct ref *our, const struct ref *remote, * Unborn head from remote; same as "our" case above except * that we have no ref to update. */ - if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", unborn, NULL, NULL) < 0) + if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", unborn, + NULL, NULL, 0) < 0) die(_("unable to update HEAD")); if (!option_bare) install_branch_config(0, head, remote_name, unborn); diff --git a/builtin/notes.c b/builtin/notes.c index ba646f06ff..7b3138e3c3 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -980,7 +980,8 @@ static int merge(int argc, const char **argv, const char *prefix) die(_("a notes merge into %s is already in-progress at %s"), notes_ref, wt->path); free_worktrees(worktrees); - if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", notes_ref, NULL, NULL)) + if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", notes_ref, + NULL, NULL, 0)) die(_("failed to store link to current notes ref (%s)"), notes_ref); fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s " diff --git a/builtin/remote.c b/builtin/remote.c index 24f9caf149..9774d8ffe3 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -244,7 +244,8 @@ static int add(int argc, const char **argv, const char *prefix) strbuf_reset(&buf2); strbuf_addf(&buf2, "refs/remotes/%s/%s", name, master); - if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote add", NULL)) + if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, + "remote add", NULL, 0)) result = error(_("Could not setup master '%s'"), master); } @@ -864,7 +865,8 @@ static int mv(int argc, const char **argv, const char *prefix) strbuf_reset(&buf3); strbuf_addf(&buf3, "remote: renamed %s to %s", item->string, buf.buf); - if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, buf3.buf, NULL)) + if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, + buf3.buf, NULL, 0)) die(_("creating '%s' failed"), buf.buf); display_progress(progress, ++refs_renamed_nr); } @@ -1469,7 +1471,8 @@ static int set_head(int argc, const char **argv, const char *prefix) /* make sure it's valid */ if (!refs_ref_exists(refs, buf2.buf)) result |= error(_("Not a valid ref: %s"), buf2.buf); - else if (refs_update_symref(refs, buf.buf, buf2.buf, "remote set-head", &buf_prev)) + else if (refs_update_symref(refs, buf.buf, buf2.buf, + "remote set-head", &buf_prev, 0)) result |= error(_("Could not setup %s"), buf.buf); else if (opt_a) { report_auto(argv[0], head_name, &buf_prev); diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c index 7728fbc3c1..cfbb53b30c 100644 --- a/builtin/symbolic-ref.c +++ b/builtin/symbolic-ref.c @@ -88,7 +88,7 @@ int cmd_symbolic_ref(int argc, if (check_refname_format(argv[1], REFNAME_ALLOW_ONELEVEL) < 0) die("Refusing to set '%s' to invalid ref '%s'", argv[0], argv[1]); ret = !!refs_update_symref(get_main_ref_store(the_repository), - argv[0], argv[1], msg, NULL); + argv[0], argv[1], msg, NULL, 0); break; default: usage_with_options(git_symbolic_ref_usage, options); diff --git a/builtin/worktree.c b/builtin/worktree.c index a7ab4193c1..2e95367235 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -517,7 +517,7 @@ static int add_worktree(const char *path, const char *refname, ret = refs_update_ref(wt_refs, NULL, "HEAD", &commit->object.oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR); else - ret = refs_update_symref(wt_refs, "HEAD", symref.buf, NULL, NULL); + ret = refs_update_symref(wt_refs, "HEAD", symref.buf, NULL, NULL, 0); if (ret) goto done; diff --git a/refs.c b/refs.c index 91cacee6f9..e23288b817 100644 --- a/refs.c +++ b/refs.c @@ -2115,29 +2115,43 @@ int peel_iterated_oid(struct repository *r, const struct object_id *base, struct int refs_update_symref(struct ref_store *refs, const char *ref, const char *target, const char *logmsg, - struct strbuf *before_target) + struct strbuf *before_target, int create_only) { struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; int ret = 0; transaction = ref_store_transaction_begin(refs, &err); - if (!transaction || - ref_transaction_update(transaction, ref, NULL, NULL, - target, NULL, REF_NO_DEREF, - logmsg, &err) || - ref_transaction_commit(transaction, &err)) { + if (!transaction) { + error_return: ret = error("%s", err.buf); + goto cleanup; } + if (create_only) { + int create_ret = 0; + if (ref_transaction_create(transaction, ref, NULL, target, + REF_NO_DEREF, logmsg, &err)) + goto error_return; + create_ret = ref_transaction_commit(transaction, &err); + if (create_ret && create_ret != TRANSACTION_CREATE_EXISTS) + ret = error("%s", err.buf); - strbuf_release(&err); + } else { + if (ref_transaction_update(transaction, ref, NULL, NULL, + target, NULL, REF_NO_DEREF, + logmsg, &err) || + ref_transaction_commit(transaction, &err)) + goto error_return; + } - if (transaction && before_target && transaction->updates[0]->before_target) - strbuf_addstr(before_target, transaction->updates[0]->before_target); +cleanup: + strbuf_release(&err); - if (transaction) + if (transaction) { + if (before_target && transaction->updates[0]->before_target) + strbuf_addstr(before_target, transaction->updates[0]->before_target); ref_transaction_free(transaction); - + } return ret; } diff --git a/refs.h b/refs.h index 166affbc89..35f5439cd1 100644 --- a/refs.h +++ b/refs.h @@ -572,7 +572,7 @@ int refs_copy_existing_ref(struct ref_store *refs, const char *oldref, int refs_update_symref(struct ref_store *refs, const char *refname, const char *target, const char *logmsg, - struct strbuf *before_target); + struct strbuf *before_target, int create_only); enum action_on_err { UPDATE_REFS_MSG_ON_ERR, diff --git a/reset.c b/reset.c index cc36a9ed56..919fb84f5f 100644 --- a/reset.c +++ b/reset.c @@ -76,7 +76,7 @@ static int update_refs(const struct reset_head_opts *opts, if (!ret) ret = refs_update_symref(get_main_ref_store(the_repository), "HEAD", switch_to_branch, - reflog_head, NULL); + reflog_head, NULL, 0); } if (!ret && run_hook) run_hooks_l(the_repository, "post-checkout", diff --git a/sequencer.c b/sequencer.c index 23b162924c..103d0ddfb2 100644 --- a/sequencer.c +++ b/sequencer.c @@ -5107,7 +5107,8 @@ static int pick_commits(struct repository *r, } msg = reflog_message(opts, "finish", "returning to %s", head_ref.buf); - if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", head_ref.buf, msg, NULL)) { + if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", head_ref.buf, + msg, NULL, 0)) { res = error(_("could not update HEAD to %s"), head_ref.buf); goto cleanup_head_ref; diff --git a/setup.c b/setup.c index d95f051465..9bbc655ee4 100644 --- a/setup.c +++ b/setup.c @@ -2275,7 +2275,8 @@ void create_reference_database(enum ref_storage_format ref_storage_format, die(_("invalid initial branch name: '%s'"), initial_branch); - if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", ref, NULL, NULL) < 0) + if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", ref, + NULL, NULL, 0) < 0) exit(1); free(ref); } diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index a911302bea..f72b029e51 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -120,7 +120,7 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv) const char *target = notnull(*argv++, "target"); const char *logmsg = *argv++; - return refs_update_symref(refs, refname, target, logmsg, NULL); + return refs_update_symref(refs, refname, target, logmsg, NULL, 0); } static struct flag_definition transaction_flags[] = { From patchwork Thu Oct 10 13:30:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13830131 Received: from aib29agh125.zrh1.oracleemaildelivery.com (aib29agh125.zrh1.oracleemaildelivery.com [192.29.178.125]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1FF580035 for ; Thu, 10 Oct 2024 13:33:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.125 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567206; cv=none; b=GOZ5UaKBHQOu8Qx2KoARYSzqC2aj0mF+tYJ4jSwoO0tiiSK/OXgPbQVI2IH9QNmrSmOMKHnNLJw76q2tlIbFtnfi2WAJ/D8MvUjIq97CzoWQbFHZp1V1EizRPW5s/20jJoioXtMzcVM4/f228hh+VonXOuXPyMQLhx83u9nf+1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728567206; c=relaxed/simple; bh=nrFPO3bmOBhG/derwv/05BCbiiyMm4w0i0DVq7k8d5U=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=bmZHFq3ClRR+cugKRTjvWRjM14dA8TUURYRN1KEP9ZpzhPDKt+H6clzrgQ6zS9q9d6M6EQZk71i3qPWcKeVgpRxRIYgKS+CZ8nIXqZ3GVvHbe0VvMoF1LlthK0+jRFm6pZsfJnKkOY9EuUkgiGQXqlGCL2FxbRE8I5rJ1rknAso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b=GECoNlLA; arc=none smtp.client-ip=192.29.178.125 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b="GECoNlLA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=prod-zrh-20200406; d=zrh1.rp.oracleemaildelivery.com; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender:List-Unsubscribe:List-Unsubscribe-Post; bh=I9JnTqYHsLxzy73xhuUX9WOY9nYFPoadMnL1qRZrvlU=; b=GECoNlLAWIN5+xsfw29+t7DlW6J8VSZPzDE5Qnzg5IJ5LhOTo4f1QHbMqmNqrT5+DdpkMM54E2nX BhqGkMzj/Oaa+3qjmgs98DVHTTEPmknV4pSGV+/VbV6FWNjUYCrf8lh5I6eQLimjGB1LeFRfphK0 VjlI8SVCmLrHvoGQqah4m1+d/sHOrj+LSSmYyPO8I7iarwZjqbMG5jYvHsrRAju7S36fiDVL7TRj c3CT6yO1Y3AorCXlesWCgdkdUrogDGvSCYGp3JrjSP36j0JBXOOC01lFl8N7/cW/NXr/zQBUf46C YZ/gfpj74jVC5NQdlI5i4PNdfD4/nYTst6gdYA== Received: by omta-ad1-fd2-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20240911 64bit (built Sep 11 2024)) with ESMTPS id <0SL500IIL6ZLRAC0@omta-ad1-fd2-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Thu, 10 Oct 2024 13:33:21 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, Taylor Blau , =?utf-8?q?Ren?= =?utf-8?q?=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , Bence Ferdinandy Subject: [PATCH v6 6/6] fetch: set remote/HEAD if it does not exist Date: Thu, 10 Oct 2024 15:30:01 +0200 Message-id: <20241010133022.1733542-6-bence@ferdinandy.com> In-reply-to: <20241010133022.1733542-1-bence@ferdinandy.com> References: <20241010133022.1733542-1-bence@ferdinandy.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-transfer-encoding: 8bit Reporting-Meta: AAFYTbWyjGb9yUF5xbtDw9zkPnsxLZJUATDZgLb0C7HxB7jf8X+HY+16Fs59wBRn XB0CFIAggFeYyDhoeArqE5oDtcrcitFKjrR/XsoXN2KjbjnlOuA4/xAHpfZ/oXKu A4TueYcHDz5yt3S9fbVQtREx+XHQQi8ofV303YqIZOAng48vpAl/0dUplR+jfMQE cLpS1v/AmjhbK0rlq3ZQFbt5DJsSAbwtoxnLA6fRIYpj2tYT+2m4Mff4OdCoS0kL yd1OsCn/t3TwmSjNQm9bStxEzY+u2JfTJGBkQDCS+9ucAegcfL1TdLzgmKP1D4a5 gavMjMwaK1kW1UFLgoa8zT+hB8qdHLcQkR4Pfc9CZJ+zezUHMLzlj8ROesi9EGoP DaZ2W4uTA9se2j0LNwsuLlSf5pHkuYHMnu/jEkFaI9GxdFY/S4uNxOk1tyeqzYYY cgC9uLZqgplkdBvO/CBu7haT3YAweD856bCv1nRX733Azw8gFO2sFrZi If the user has remote/HEAD set already and it looks like it has changed on the server, then print a message, otherwise set it if we can. Silently pass if the user already has the same remote/HEAD set as reported by the server or if we encounter any errors along the way. Signed-off-by: Bence Ferdinandy --- Notes: v3: - does not rely on remote set-head anymore so it only authenticates once - uses the new REF_CREATE_ONLY to atomically check if the ref exists and only write it if it doesn't - in all other cases the maximum it does is print a warning v4: - instead of the discarded REF_CREATE_ONLY, it uses the existing, but updated transaction api to request a silent create only - it now uses the atomic before_target to determine reporting - refactored for legibility v5: - instead of printing a not too useful message, it now fails silently, this in line with the objective to only set up remote/HEAD automatically if the right thing is trivial, for everything else there is remote set-head - fixed all failing tests - added two new tests, one for checking if remote/HEAD is set to the correct one, and one to test that we do not override remote/HEAD if it has changed on the server from what we have locally v6: - fixed style issues and unintended extra empty line - updated function call with bool to int from previous patch's change - removed calls to error(...) inherited from builtin/remote.c so we actually fail silently - set the test for remote set-head --auto to the correct value here, which was previously erronously set in the remote set-head patch builtin/fetch.c | 82 +++++++++++ t/t4207-log-decoration-colors.sh | 3 +- t/t5505-remote.sh | 13 +- t/t5510-fetch.sh | 229 ++++++++++++++++--------------- t/t5512-ls-remote.sh | 2 + t/t5514-fetch-multiple.sh | 17 ++- t/t5516-fetch-push.sh | 3 +- t/t5527-fetch-odd-refs.sh | 3 +- t/t7900-maintenance.sh | 3 +- t/t9210-scalar.sh | 5 +- t/t9211-scalar-clone.sh | 6 +- t/t9902-completion.sh | 65 +++++++++ 12 files changed, 308 insertions(+), 123 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 80a64d0d26..4c68f21be1 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1578,6 +1578,80 @@ static int backfill_tags(struct display_state *display_state, return retcode; } +static void report_set_head(const char *remote, const char *head_name, + struct strbuf *buf_prev) { + struct strbuf buf_prefix = STRBUF_INIT; + const char *prev_head = NULL; + + strbuf_addf(&buf_prefix, "refs/remotes/%s/", remote); + skip_prefix(buf_prev->buf, buf_prefix.buf, &prev_head); + + if (prev_head && strcmp(prev_head, head_name)) { + printf("'HEAD' at '%s' has changed from '%s' to '%s'\n", + remote, prev_head, head_name); + printf("Run 'git remote set-head %s %s' to follow the change.\n", + remote, head_name); + } +} + +static const char *strip_refshead(const char *name){ + skip_prefix(name, "refs/heads/", &name); + return name; +} + +static int set_head(const struct ref *remote_refs) +{ + int result = 0; + struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT, + b_local_head = STRBUF_INIT; + const char *remote = gtransport->remote->name; + char *head_name = NULL; + struct ref *ref, *matches; + struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map; + struct refspec_item refspec = { + .force = 0, + .pattern = 1, + .src = (char *) "refs/heads/*", + .dst = (char *) "refs/heads/*", + }; + struct string_list heads = STRING_LIST_INIT_DUP; + struct ref_store *refs = get_main_ref_store(the_repository); + + get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0); + matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"), + fetch_map, 1); + for (ref = matches; ref; ref = ref->next) { + string_list_append(&heads, strip_refshead(ref->name)); + } + + + if (!heads.nr) + result = 1; + else if (heads.nr > 1) + result = 1; + else + head_name = xstrdup(heads.items[0].string); + if (head_name) { + strbuf_addf(&b_head, "refs/remotes/%s/HEAD", remote); + strbuf_addf(&b_remote_head, "refs/remotes/%s/%s", remote, head_name); + /* make sure it's valid */ + if (!refs_ref_exists(refs, b_remote_head.buf)) + result = 1; + else if (refs_update_symref(refs, b_head.buf, b_remote_head.buf, + "remote set-head", &b_local_head, 1)) + result = 1; + else + report_set_head(remote, head_name, &b_local_head); + + free(head_name); + } + + strbuf_release(&b_head); + strbuf_release(&b_local_head); + strbuf_release(&b_remote_head); + return result; +} + static int do_fetch(struct transport *transport, struct refspec *rs, const struct fetch_config *config) @@ -1647,6 +1721,8 @@ static int do_fetch(struct transport *transport, "refs/tags/"); } + strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD"); + if (must_list_refs) { trace2_region_enter("fetch", "remote_refs", the_repository); remote_refs = transport_get_remote_refs(transport, @@ -1791,6 +1867,12 @@ static int do_fetch(struct transport *transport, "you need to specify exactly one branch with the --set-upstream option")); } } + if (set_head(remote_refs)) + ; + /* + * Way too many cases where this can go wrong + * so let's just fail silently for now. + */ cleanup: if (retcode) { diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index 73ea9e5155..d55d22cb2f 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -59,7 +59,8 @@ ${c_reset}${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_commit}, \ ${c_reset}${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_commit})${c_reset} B ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ ${c_tag}tag: ${c_reset}${c_tag}A1${c_reset}${c_commit}, \ -${c_reset}${c_remoteBranch}other/main${c_reset}${c_commit})${c_reset} A1 +${c_reset}${c_remoteBranch}other/main${c_reset}${c_commit}, \ +${c_reset}${c_remoteBranch}other/HEAD${c_reset}${c_commit})${c_reset} A1 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ ${c_stash}refs/stash${c_reset}${c_commit})${c_reset} On main: Changes to A.t ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 77c12b8709..4a62753af3 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -71,7 +71,7 @@ test_expect_success 'add another remote' ' cd test && git remote add -f second ../two && tokens_match "origin second" "$(git remote)" && - check_tracking_branch second main side another && + check_tracking_branch second main side another HEAD && git for-each-ref "--format=%(refname)" refs/remotes | sed -e "/^refs\/remotes\/origin\//d" \ -e "/^refs\/remotes\/second\//d" >actual && @@ -473,7 +473,7 @@ test_expect_success 'set-head --auto has no problem w/multiple HEADs' ' cd test && git fetch two "refs/heads/*:refs/remotes/two/*" && git remote set-head --auto two >output 2>&1 && - echo "'\''two/HEAD'\'' is now created and points to '\''main'\''" >expect && + echo "'\''two/HEAD'\'' is unchanged and points to '\''main'\''" >expect && test_cmp expect output ) ' @@ -764,6 +764,7 @@ test_expect_success 'reject --no-no-tags' ' cat >one/expect <<\EOF apis/main apis/side + drosophila/HEAD -> drosophila/main drosophila/another drosophila/main drosophila/side @@ -781,6 +782,7 @@ test_expect_success 'update' ' ' cat >one/expect <<\EOF + drosophila/HEAD -> drosophila/main drosophila/another drosophila/main drosophila/side @@ -793,7 +795,7 @@ EOF test_expect_success 'update with arguments' ' ( cd one && - for b in $(git branch -r) + for b in $(git branch -r | grep -v HEAD) do git branch -r -d $b || exit 1 done && @@ -836,7 +838,7 @@ EOF test_expect_success 'update default' ' ( cd one && - for b in $(git branch -r) + for b in $(git branch -r | grep -v HEAD) do git branch -r -d $b || exit 1 done && @@ -848,6 +850,7 @@ test_expect_success 'update default' ' ' cat >one/expect <<\EOF + drosophila/HEAD -> drosophila/main drosophila/another drosophila/main drosophila/side @@ -870,7 +873,7 @@ test_expect_success 'update default (overridden, with funny whitespace)' ' test_expect_success 'update (with remotes.default defined)' ' ( cd one && - for b in $(git branch -r) + for b in $(git branch -r | grep -v HEAD) do git branch -r -d $b || exit 1 done && diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 0890b9f61c..dfc8d748ba 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -75,6 +75,30 @@ test_expect_success "fetch test for-merge" ' cut -f -2 .git/FETCH_HEAD >actual && test_cmp expected actual' +test_expect_success "fetch test remote HEAD" ' + cd "$D" && + cd two && + git fetch && + git rev-parse --verify refs/remotes/origin/HEAD && + git rev-parse --verify refs/remotes/origin/main && + head=$(git rev-parse refs/remotes/origin/HEAD) && + branch=$(git rev-parse refs/remotes/origin/main) && + test "z$head" = "z$branch"' + +test_expect_success "fetch test remote HEAD change" ' + cd "$D" && + cd two && + git switch -c other && + git push -u origin other && + git rev-parse --verify refs/remotes/origin/HEAD && + git rev-parse --verify refs/remotes/origin/main && + git rev-parse --verify refs/remotes/origin/other && + git remote set-head origin other && + git fetch && + head=$(git rev-parse refs/remotes/origin/HEAD) && + branch=$(git rev-parse refs/remotes/origin/other) && + test "z$head" = "z$branch"' + test_expect_success 'fetch --prune on its own works as expected' ' cd "$D" && git clone . prune && @@ -478,7 +502,6 @@ test_expect_success 'unbundle 1' ' test_must_fail git fetch "$D/bundle1" main:main ' - test_expect_success 'bundle 1 has only 3 files ' ' cd "$D" && test_bundle_object_count bundle1 3 @@ -819,7 +842,7 @@ test_expect_success 'fetch from multiple configured URLs in single remote' ' # configured prune tests -set_config_tristate () { +set_config_tristate() { # var=$1 val=$2 case "$2" in unset) @@ -833,12 +856,12 @@ set_config_tristate () { esac } -test_configured_prune () { +test_configured_prune() { test_configured_prune_type "$@" "name" test_configured_prune_type "$@" "link" } -test_configured_prune_type () { +test_configured_prune_type() { fetch_prune=$1 remote_origin_prune=$2 fetch_prune_tags=$3 @@ -848,8 +871,7 @@ test_configured_prune_type () { cmdline=$7 mode=$8 - if test -z "$cmdline_setup" - then + if test -z "$cmdline_setup"; then test_expect_success 'setup cmdline_setup variable for subsequent test' ' remote_url="file://$(git -C one config remote.origin.url)" && remote_fetch="$(git -C one config remote.origin.fetch)" && @@ -857,12 +879,10 @@ test_configured_prune_type () { ' fi - if test "$mode" = 'link' - then + if test "$mode" = 'link'; then new_cmdline="" - if test "$cmdline" = "" - then + if test "$cmdline" = ""; then new_cmdline=$cmdline_setup else new_cmdline=$(perl -e ' @@ -873,10 +893,8 @@ test_configured_prune_type () { fi if test "$fetch_prune_tags" = 'true' || - test "$remote_origin_prune_tags" = 'true' - then - if ! printf '%s' "$cmdline\n" | grep -q refs/remotes/origin/ - then + test "$remote_origin_prune_tags" = 'true'; then + if ! printf '%s' "$cmdline\n" | grep -q refs/remotes/origin/; then new_cmdline="$new_cmdline refs/tags/*:refs/tags/*" fi fi @@ -946,100 +964,100 @@ test_configured_prune_type () { # $7 git-fetch $cmdline: # # $1 $2 $3 $4 $5 $6 $7 -test_configured_prune unset unset unset unset kept kept "" -test_configured_prune unset unset unset unset kept kept "--no-prune" -test_configured_prune unset unset unset unset pruned kept "--prune" -test_configured_prune unset unset unset unset kept pruned \ +test_configured_prune unset unset unset unset kept kept "" +test_configured_prune unset unset unset unset kept kept "--no-prune" +test_configured_prune unset unset unset unset pruned kept "--prune" +test_configured_prune unset unset unset unset kept pruned \ "--prune origin refs/tags/*:refs/tags/*" test_configured_prune unset unset unset unset pruned pruned \ "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*" -test_configured_prune false unset unset unset kept kept "" -test_configured_prune false unset unset unset kept kept "--no-prune" -test_configured_prune false unset unset unset pruned kept "--prune" +test_configured_prune false unset unset unset kept kept "" +test_configured_prune false unset unset unset kept kept "--no-prune" +test_configured_prune false unset unset unset pruned kept "--prune" -test_configured_prune true unset unset unset pruned kept "" -test_configured_prune true unset unset unset pruned kept "--prune" -test_configured_prune true unset unset unset kept kept "--no-prune" +test_configured_prune true unset unset unset pruned kept "" +test_configured_prune true unset unset unset pruned kept "--prune" +test_configured_prune true unset unset unset kept kept "--no-prune" -test_configured_prune unset false unset unset kept kept "" -test_configured_prune unset false unset unset kept kept "--no-prune" -test_configured_prune unset false unset unset pruned kept "--prune" +test_configured_prune unset false unset unset kept kept "" +test_configured_prune unset false unset unset kept kept "--no-prune" +test_configured_prune unset false unset unset pruned kept "--prune" -test_configured_prune false false unset unset kept kept "" -test_configured_prune false false unset unset kept kept "--no-prune" -test_configured_prune false false unset unset pruned kept "--prune" -test_configured_prune false false unset unset kept pruned \ +test_configured_prune false false unset unset kept kept "" +test_configured_prune false false unset unset kept kept "--no-prune" +test_configured_prune false false unset unset pruned kept "--prune" +test_configured_prune false false unset unset kept pruned \ "--prune origin refs/tags/*:refs/tags/*" test_configured_prune false false unset unset pruned pruned \ "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*" -test_configured_prune true false unset unset kept kept "" -test_configured_prune true false unset unset pruned kept "--prune" -test_configured_prune true false unset unset kept kept "--no-prune" +test_configured_prune true false unset unset kept kept "" +test_configured_prune true false unset unset pruned kept "--prune" +test_configured_prune true false unset unset kept kept "--no-prune" -test_configured_prune unset true unset unset pruned kept "" -test_configured_prune unset true unset unset kept kept "--no-prune" -test_configured_prune unset true unset unset pruned kept "--prune" +test_configured_prune unset true unset unset pruned kept "" +test_configured_prune unset true unset unset kept kept "--no-prune" +test_configured_prune unset true unset unset pruned kept "--prune" -test_configured_prune false true unset unset pruned kept "" -test_configured_prune false true unset unset kept kept "--no-prune" -test_configured_prune false true unset unset pruned kept "--prune" +test_configured_prune false true unset unset pruned kept "" +test_configured_prune false true unset unset kept kept "--no-prune" +test_configured_prune false true unset unset pruned kept "--prune" -test_configured_prune true true unset unset pruned kept "" -test_configured_prune true true unset unset pruned kept "--prune" -test_configured_prune true true unset unset kept kept "--no-prune" -test_configured_prune true true unset unset kept pruned \ +test_configured_prune true true unset unset pruned kept "" +test_configured_prune true true unset unset pruned kept "--prune" +test_configured_prune true true unset unset kept kept "--no-prune" +test_configured_prune true true unset unset kept pruned \ "--prune origin refs/tags/*:refs/tags/*" -test_configured_prune true true unset unset pruned pruned \ +test_configured_prune true true unset unset pruned pruned \ "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*" # --prune-tags on its own does nothing, needs --prune as well, same # for fetch.pruneTags without fetch.prune -test_configured_prune unset unset unset unset kept kept "--prune-tags" -test_configured_prune unset unset true unset kept kept "" -test_configured_prune unset unset unset true kept kept "" +test_configured_prune unset unset unset unset kept kept "--prune-tags" +test_configured_prune unset unset true unset kept kept "" +test_configured_prune unset unset unset true kept kept "" # These will prune the tags test_configured_prune unset unset unset unset pruned pruned "--prune --prune-tags" -test_configured_prune true unset true unset pruned pruned "" -test_configured_prune unset true unset true pruned pruned "" +test_configured_prune true unset true unset pruned pruned "" +test_configured_prune unset true unset true pruned pruned "" # remote..pruneTags overrides fetch.pruneTags, just like # remote..prune overrides fetch.prune if set. -test_configured_prune true unset true unset pruned pruned "" -test_configured_prune false true false true pruned pruned "" -test_configured_prune true false true false kept kept "" +test_configured_prune true unset true unset pruned pruned "" +test_configured_prune false true false true pruned pruned "" +test_configured_prune true false true false kept kept "" # When --prune-tags is supplied it's ignored if an explicit refspec is # given, same for the configuration options. test_configured_prune unset unset unset unset pruned kept \ "--prune --prune-tags origin +refs/heads/*:refs/remotes/origin/*" -test_configured_prune unset unset true unset pruned kept \ +test_configured_prune unset unset true unset pruned kept \ "--prune origin +refs/heads/*:refs/remotes/origin/*" -test_configured_prune unset unset unset true pruned kept \ +test_configured_prune unset unset unset true pruned kept \ "--prune origin +refs/heads/*:refs/remotes/origin/*" # Pruning that also takes place if a file:// url replaces a named # remote. However, because there's no implicit # +refs/heads/*:refs/remotes/origin/* refspec and supplying it on the # command-line negates --prune-tags, the branches will not be pruned. -test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "name" -test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "link" +test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "name" +test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "link" test_configured_prune_type unset unset unset unset pruned pruned "origin --prune --prune-tags" "name" -test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "link" +test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "link" test_configured_prune_type unset unset unset unset pruned pruned "--prune --prune-tags origin" "name" -test_configured_prune_type unset unset unset unset kept pruned "--prune --prune-tags origin" "link" -test_configured_prune_type unset unset true unset pruned pruned "--prune origin" "name" -test_configured_prune_type unset unset true unset kept pruned "--prune origin" "link" -test_configured_prune_type unset unset unset true pruned pruned "--prune origin" "name" -test_configured_prune_type unset unset unset true kept pruned "--prune origin" "link" -test_configured_prune_type true unset true unset pruned pruned "origin" "name" -test_configured_prune_type true unset true unset kept pruned "origin" "link" -test_configured_prune_type unset true true unset pruned pruned "origin" "name" -test_configured_prune_type unset true true unset kept pruned "origin" "link" -test_configured_prune_type unset true unset true pruned pruned "origin" "name" -test_configured_prune_type unset true unset true kept pruned "origin" "link" +test_configured_prune_type unset unset unset unset kept pruned "--prune --prune-tags origin" "link" +test_configured_prune_type unset unset true unset pruned pruned "--prune origin" "name" +test_configured_prune_type unset unset true unset kept pruned "--prune origin" "link" +test_configured_prune_type unset unset unset true pruned pruned "--prune origin" "name" +test_configured_prune_type unset unset unset true kept pruned "--prune origin" "link" +test_configured_prune_type true unset true unset pruned pruned "origin" "name" +test_configured_prune_type true unset true unset kept pruned "origin" "link" +test_configured_prune_type unset true true unset pruned pruned "origin" "name" +test_configured_prune_type unset true true unset kept pruned "origin" "link" +test_configured_prune_type unset true unset true pruned pruned "origin" "name" +test_configured_prune_type unset true unset true kept pruned "origin" "link" # When all remote.origin.fetch settings are deleted a --prune # --prune-tags still implicitly supplies refs/tags/*:refs/tags/* so @@ -1137,8 +1155,7 @@ test_expect_success 'fetching with auto-gc does not lock up' ' ) ' -for section in fetch transfer -do +for section in fetch transfer; do test_expect_success "$section.hideRefs affects connectivity check" ' GIT_TRACE="$PWD"/trace git -c $section.hideRefs=refs -c \ $section.hideRefs="!refs/tags/" fetch && @@ -1157,21 +1174,23 @@ test_expect_success 'prepare source branch' ' test 3 -le $(wc -l actual && - case "$store_type" in - packed) - grep "^count: 0$" actual ;; - loose) - grep "^packs: 0$" actual ;; - esac || { + case "$store_type" in + packed) + grep "^count: 0$" actual + ;; + loose) + grep "^packs: 0$" actual + ;; + esac || { echo "store_type is $store_type" cat actual false } } -test_unpack_limit () { +test_unpack_limit() { store_type=$1 case "$store_type" in @@ -1192,43 +1211,39 @@ test_unpack_limit () { test_unpack_limit packed test_unpack_limit loose -setup_negotiation_tip () { +setup_negotiation_tip() { SERVER="$1" URL="$2" USE_PROTOCOL_V2="$3" rm -rf "$SERVER" client trace && - git init -b main "$SERVER" && - test_commit -C "$SERVER" alpha_1 && - test_commit -C "$SERVER" alpha_2 && - git -C "$SERVER" checkout --orphan beta && - test_commit -C "$SERVER" beta_1 && - test_commit -C "$SERVER" beta_2 && - - git clone "$URL" client && - - if test "$USE_PROTOCOL_V2" -eq 1 - then - git -C "$SERVER" config protocol.version 2 && - git -C client config protocol.version 2 - fi && - - test_commit -C "$SERVER" beta_s && - git -C "$SERVER" checkout main && - test_commit -C "$SERVER" alpha_s && - git -C "$SERVER" tag -d alpha_1 alpha_2 beta_1 beta_2 + git init -b main "$SERVER" && + test_commit -C "$SERVER" alpha_1 && + test_commit -C "$SERVER" alpha_2 && + git -C "$SERVER" checkout --orphan beta && + test_commit -C "$SERVER" beta_1 && + test_commit -C "$SERVER" beta_2 && + git clone "$URL" client && + if test "$USE_PROTOCOL_V2" -eq 1; then + git -C "$SERVER" config protocol.version 2 && + git -C client config protocol.version 2 + fi && + test_commit -C "$SERVER" beta_s && + git -C "$SERVER" checkout main && + test_commit -C "$SERVER" alpha_s && + git -C "$SERVER" tag -d alpha_1 alpha_2 beta_1 beta_2 } -check_negotiation_tip () { +check_negotiation_tip() { # Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2 ALPHA_1=$(git -C client rev-parse alpha_1) && - grep "fetch> have $ALPHA_1" trace && - BETA_1=$(git -C client rev-parse beta_1) && - grep "fetch> have $BETA_1" trace && - ALPHA_2=$(git -C client rev-parse alpha_2) && - ! grep "fetch> have $ALPHA_2" trace && - BETA_2=$(git -C client rev-parse beta_2) && - ! grep "fetch> have $BETA_2" trace + grep "fetch> have $ALPHA_1" trace && + BETA_1=$(git -C client rev-parse beta_1) && + grep "fetch> have $BETA_1" trace && + ALPHA_2=$(git -C client rev-parse alpha_2) && + ! grep "fetch> have $ALPHA_2" trace && + BETA_2=$(git -C client rev-parse beta_2) && + ! grep "fetch> have $BETA_2" trace } test_expect_success '--negotiation-tip limits "have" lines sent' ' diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh index 64b3491e4e..1b3865e154 100755 --- a/t/t5512-ls-remote.sh +++ b/t/t5512-ls-remote.sh @@ -293,6 +293,8 @@ test_expect_success 'ls-remote with filtered symref (refname)' ' cat >expect <<-EOF && ref: refs/heads/main HEAD $rev HEAD + ref: refs/remotes/origin/main refs/remotes/origin/HEAD + $rev refs/remotes/origin/HEAD EOF git ls-remote --symref . HEAD >actual && test_cmp expect actual diff --git a/t/t5514-fetch-multiple.sh b/t/t5514-fetch-multiple.sh index 579872c258..e3482b27b2 100755 --- a/t/t5514-fetch-multiple.sh +++ b/t/t5514-fetch-multiple.sh @@ -45,14 +45,17 @@ test_expect_success setup ' ' cat > test/expect << EOF + one/HEAD -> one/main one/main one/side origin/HEAD -> origin/main origin/main origin/side + three/HEAD -> three/main three/another three/main three/side + two/HEAD -> two/main two/another two/main two/side @@ -97,6 +100,7 @@ cat > expect << EOF origin/HEAD -> origin/main origin/main origin/side + three/HEAD -> three/main three/another three/main three/side @@ -112,8 +116,10 @@ test_expect_success 'git fetch --multiple (but only one remote)' ' ' cat > expect << EOF + one/HEAD -> one/main one/main one/side + two/HEAD -> two/main two/another two/main two/side @@ -141,7 +147,7 @@ test_expect_success 'git fetch --multiple (bad remote names)' ' test_expect_success 'git fetch --all (skipFetchAll)' ' (cd test4 && - for b in $(git branch -r) + for b in $(git branch -r | grep -v HEAD) do git branch -r -d $b || exit 1 done && @@ -153,11 +159,14 @@ test_expect_success 'git fetch --all (skipFetchAll)' ' ' cat > expect << EOF + one/HEAD -> one/main one/main one/side + three/HEAD -> three/main three/another three/main three/side + two/HEAD -> two/main two/another two/main two/side @@ -165,7 +174,7 @@ EOF test_expect_success 'git fetch --multiple (ignoring skipFetchAll)' ' (cd test4 && - for b in $(git branch -r) + for b in $(git branch -r | grep -v HEAD) do git branch -r -d $b || exit 1 done && @@ -221,14 +230,17 @@ test_expect_success 'git fetch --multiple --jobs=0 picks a default' ' create_fetch_all_expect () { cat >expect <<-\EOF + one/HEAD -> one/main one/main one/side origin/HEAD -> origin/main origin/main origin/side + three/HEAD -> three/main three/another three/main three/side + two/HEAD -> two/main two/another two/main two/side @@ -265,6 +277,7 @@ test_expect_success 'git fetch (fetch all remotes with fetch.all = true)' ' create_fetch_one_expect () { cat >expect <<-\EOF + one/HEAD -> one/main one/main one/side origin/HEAD -> origin/main diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 331778bd42..5a051aa0c7 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -1395,7 +1395,8 @@ test_expect_success 'fetch follows tags by default' ' git tag -m "annotated" tag && git for-each-ref >tmp1 && sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 | - sort -k 3 >../expect + sed -n "p; s|refs/heads/main$|refs/remotes/origin/HEAD|p" | + sort -k 4 >../expect ) && test_when_finished "rm -rf dst" && git init dst && diff --git a/t/t5527-fetch-odd-refs.sh b/t/t5527-fetch-odd-refs.sh index 98ece27c6a..d3996af6ee 100755 --- a/t/t5527-fetch-odd-refs.sh +++ b/t/t5527-fetch-odd-refs.sh @@ -52,7 +52,8 @@ test_expect_success LONG_REF 'fetch handles extremely long refname' ' long main EOF - git for-each-ref --format="%(subject)" refs/remotes/long >actual && + git for-each-ref --format="%(subject)" refs/remotes/long \ + --exclude=refs/remotes/long/HEAD >actual && test_cmp expect actual ' diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index a66d0e089d..88331d1ceb 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -329,7 +329,8 @@ test_expect_success 'incremental-repack task' ' # Delete refs that have not been repacked in these packs. git for-each-ref --format="delete %(refname)" \ - refs/prefetch refs/tags refs/remotes >refs && + refs/prefetch refs/tags refs/remotes \ + --exclude=refs/remotes/*/HEAD >refs && git update-ref --stdin actual && - echo "refs/remotes/origin/parallel" >expect && + echo "refs/remotes/origin/HEAD" >>expect && + echo "refs/remotes/origin/parallel" >>expect && test_cmp expect actual && test_path_is_missing 1/2 && @@ -219,7 +220,7 @@ test_expect_success 'scalar reconfigure --all with includeIf.onbranch' ' done ' - test_expect_success 'scalar reconfigure --all with detached HEADs' ' +test_expect_success 'scalar reconfigure --all with detached HEADs' ' repos="two three four" && for num in $repos do diff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh index 7869f45ee6..01f71910f5 100755 --- a/t/t9211-scalar-clone.sh +++ b/t/t9211-scalar-clone.sh @@ -31,7 +31,7 @@ test_expect_success 'set up repository to clone' ' ) ' -cleanup_clone () { +cleanup_clone() { rm -rf "$1" } @@ -127,7 +127,7 @@ test_expect_success '--single-branch clones HEAD only' ' ( cd $enlistment/src && git for-each-ref refs/remotes/origin >out && - test_line_count = 1 out && + test_line_count = 2 out && grep "refs/remotes/origin/base" out ) && @@ -141,7 +141,7 @@ test_expect_success '--no-single-branch clones all branches' ' ( cd $enlistment/src && git for-each-ref refs/remotes/origin >out && - test_line_count = 2 out && + test_line_count = 3 out && grep "refs/remotes/origin/base" out && grep "refs/remotes/origin/parallel" out ) && diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index cc6aa9f0cd..b663c4609e 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -658,6 +658,7 @@ test_expect_success '__git_refs - simple' ' HEAD main matching-branch + other/HEAD other/branch-in-other other/main-in-other matching-tag @@ -673,6 +674,7 @@ test_expect_success '__git_refs - full refs' ' cat >expected <<-EOF && refs/heads/main refs/heads/matching-branch + refs/remotes/other/HEAD refs/remotes/other/branch-in-other refs/remotes/other/main-in-other refs/tags/matching-tag @@ -729,6 +731,7 @@ test_expect_success '__git_refs - remote on local file system - full refs' ' test_expect_success '__git_refs - configured remote' ' cat >expected <<-EOF && HEAD + HEAD branch-in-other main-in-other EOF @@ -756,6 +759,7 @@ test_expect_success '__git_refs - configured remote - full refs' ' test_expect_success '__git_refs - configured remote - repo given on the command line' ' cat >expected <<-EOF && HEAD + HEAD branch-in-other main-in-other EOF @@ -787,6 +791,7 @@ test_expect_success '__git_refs - configured remote - full refs - repo given on test_expect_success '__git_refs - configured remote - remote name matches a directory' ' cat >expected <<-EOF && HEAD + HEAD branch-in-other main-in-other EOF @@ -875,12 +880,14 @@ test_expect_success '__git_refs - unique remote branches for git checkout DWIMer HEAD main matching-branch + other/HEAD other/ambiguous other/branch-in-other other/main-in-other remote/ambiguous remote/branch-in-remote matching-tag + HEAD branch-in-other branch-in-remote main-in-other @@ -904,6 +911,7 @@ test_expect_success '__git_refs - after --opt=' ' HEAD main matching-branch + other/HEAD other/branch-in-other other/main-in-other matching-tag @@ -919,6 +927,7 @@ test_expect_success '__git_refs - after --opt= - full refs' ' cat >expected <<-EOF && refs/heads/main refs/heads/matching-branch + refs/remotes/other/HEAD refs/remotes/other/branch-in-other refs/remotes/other/main-in-other refs/tags/matching-tag @@ -935,6 +944,7 @@ test_expect_success '__git refs - excluding refs' ' ^HEAD ^main ^matching-branch + ^other/HEAD ^other/branch-in-other ^other/main-in-other ^matching-tag @@ -950,6 +960,7 @@ test_expect_success '__git refs - excluding full refs' ' cat >expected <<-EOF && ^refs/heads/main ^refs/heads/matching-branch + ^refs/remotes/other/HEAD ^refs/remotes/other/branch-in-other ^refs/remotes/other/main-in-other ^refs/tags/matching-tag @@ -975,6 +986,7 @@ test_expect_success '__git_refs - do not filter refs unless told so' ' main matching-branch matching/branch + other/HEAD other/branch-in-other other/main-in-other other/matching/branch-in-other @@ -1095,6 +1107,7 @@ test_expect_success '__git_complete_refs - simple' ' HEAD Z main Z matching-branch Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z matching-tag Z @@ -1123,6 +1136,7 @@ test_expect_success '__git_complete_refs - matching' ' test_expect_success '__git_complete_refs - remote' ' sed -e "s/Z$//" >expected <<-EOF && HEAD Z + HEAD Z branch-in-other Z main-in-other Z EOF @@ -1139,9 +1153,11 @@ test_expect_success '__git_complete_refs - track' ' HEAD Z main Z matching-branch Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z matching-tag Z + HEAD Z branch-in-other Z main-in-other Z EOF @@ -1184,6 +1200,7 @@ test_expect_success '__git_complete_refs - suffix' ' HEAD. main. matching-branch. + other/HEAD. other/branch-in-other. other/main-in-other. matching-tag. @@ -1199,6 +1216,7 @@ test_expect_success '__git_complete_refs - suffix' ' test_expect_success '__git_complete_fetch_refspecs - simple' ' sed -e "s/Z$//" >expected <<-EOF && HEAD:HEAD Z + HEAD:HEAD Z branch-in-other:branch-in-other Z main-in-other:main-in-other Z EOF @@ -1225,6 +1243,7 @@ test_expect_success '__git_complete_fetch_refspecs - matching' ' test_expect_success '__git_complete_fetch_refspecs - prefix' ' sed -e "s/Z$//" >expected <<-EOF && +HEAD:HEAD Z + +HEAD:HEAD Z +branch-in-other:branch-in-other Z +main-in-other:main-in-other Z EOF @@ -1289,6 +1308,7 @@ test_expect_success '__git_complete_worktree_paths with -C' ' test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' ' test_completion "git switch " <<-\EOF + HEAD Z branch-in-other Z main Z main-in-other Z @@ -1435,11 +1455,13 @@ test_expect_success 'git-bisect - existing view subcommand is recognized and ena test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' ' test_completion "git checkout " <<-\EOF HEAD Z + HEAD Z branch-in-other Z main Z main-in-other Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1461,6 +1483,7 @@ test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, compl test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' ' GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF + HEAD Z branch-in-other Z main Z main-in-other Z @@ -1470,6 +1493,7 @@ test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_G test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' ' test_completion "git switch --no-guess --guess " <<-\EOF + HEAD Z branch-in-other Z main Z main-in-other Z @@ -1490,6 +1514,7 @@ test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only complete main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1498,11 +1523,13 @@ test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only complete test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' ' GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF HEAD Z + HEAD Z branch-in-other Z main Z main-in-other Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1514,6 +1541,7 @@ test_expect_success 'git checkout - with --no-guess, only completes refs' ' main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1522,11 +1550,13 @@ test_expect_success 'git checkout - with --no-guess, only completes refs' ' test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' ' test_completion "git checkout --no-guess --guess " <<-\EOF HEAD Z + HEAD Z branch-in-other Z main Z main-in-other Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1538,6 +1568,7 @@ test_expect_success 'git checkout - a later --no-guess overrides previous --gues main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1550,6 +1581,7 @@ test_expect_success 'git checkout - with checkout.guess = false, only completes main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1559,11 +1591,13 @@ test_expect_success 'git checkout - with checkout.guess = true, completes refs a test_config checkout.guess true && test_completion "git checkout " <<-\EOF HEAD Z + HEAD Z branch-in-other Z main Z main-in-other Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1573,11 +1607,13 @@ test_expect_success 'git checkout - a later --guess overrides previous checkout. test_config checkout.guess false && test_completion "git checkout --guess " <<-\EOF HEAD Z + HEAD Z branch-in-other Z main Z main-in-other Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1590,6 +1626,7 @@ test_expect_success 'git checkout - a later --no-guess overrides previous checko main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1601,6 +1638,7 @@ test_expect_success 'git switch - with --detach, complete all references' ' main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1612,6 +1650,7 @@ test_expect_success 'git checkout - with --detach, complete only references' ' main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1783,6 +1822,7 @@ test_expect_success 'git switch - with -d, complete all references' ' main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1794,6 +1834,7 @@ test_expect_success 'git checkout - with -d, complete only references' ' main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1801,10 +1842,12 @@ test_expect_success 'git checkout - with -d, complete only references' ' test_expect_success 'git switch - with --track, complete only remote branches' ' test_completion "git switch --track " <<-\EOF && + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF test_completion "git switch -t " <<-\EOF + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1812,10 +1855,12 @@ test_expect_success 'git switch - with --track, complete only remote branches' ' test_expect_success 'git checkout - with --track, complete only remote branches' ' test_completion "git checkout --track " <<-\EOF && + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF test_completion "git checkout -t " <<-\EOF + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1834,6 +1879,7 @@ test_expect_success 'git checkout - with --no-track, complete only local referen main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1845,6 +1891,7 @@ test_expect_success 'git switch - with -c, complete all references' ' main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1856,6 +1903,7 @@ test_expect_success 'git switch - with -C, complete all references' ' main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1867,6 +1915,7 @@ test_expect_success 'git switch - with -c and --track, complete all references' main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1878,6 +1927,7 @@ test_expect_success 'git switch - with -C and --track, complete all references' main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1889,6 +1939,7 @@ test_expect_success 'git switch - with -c and --no-track, complete all reference main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1900,6 +1951,7 @@ test_expect_success 'git switch - with -C and --no-track, complete all reference main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1911,6 +1963,7 @@ test_expect_success 'git checkout - with -b, complete all references' ' main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1922,6 +1975,7 @@ test_expect_success 'git checkout - with -B, complete all references' ' main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1933,6 +1987,7 @@ test_expect_success 'git checkout - with -b and --track, complete all references main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1944,6 +1999,7 @@ test_expect_success 'git checkout - with -B and --track, complete all references main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1955,6 +2011,7 @@ test_expect_success 'git checkout - with -b and --no-track, complete all referen main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1966,6 +2023,7 @@ test_expect_success 'git checkout - with -B and --no-track, complete all referen main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF @@ -1973,6 +2031,7 @@ test_expect_success 'git checkout - with -B and --no-track, complete all referen test_expect_success 'git switch - for -c, complete local branches and unique remote branches' ' test_completion "git switch -c " <<-\EOF + HEAD Z branch-in-other Z main Z main-in-other Z @@ -1982,6 +2041,7 @@ test_expect_success 'git switch - for -c, complete local branches and unique rem test_expect_success 'git switch - for -C, complete local branches and unique remote branches' ' test_completion "git switch -C " <<-\EOF + HEAD Z branch-in-other Z main Z main-in-other Z @@ -2019,6 +2079,7 @@ test_expect_success 'git switch - for -C with --no-track, complete local branche test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' ' test_completion "git checkout -b " <<-\EOF + HEAD Z branch-in-other Z main Z main-in-other Z @@ -2028,6 +2089,7 @@ test_expect_success 'git checkout - for -b, complete local branches and unique r test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' ' test_completion "git checkout -B " <<-\EOF + HEAD Z branch-in-other Z main Z main-in-other Z @@ -2065,6 +2127,7 @@ test_expect_success 'git checkout - for -B with --no-track, complete local branc test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' ' test_completion "git switch --orphan " <<-\EOF + HEAD Z branch-in-other Z main Z main-in-other Z @@ -2080,6 +2143,7 @@ test_expect_success 'git switch - --orphan with branch already provided complete test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' ' test_completion "git checkout --orphan " <<-\EOF + HEAD Z branch-in-other Z main Z main-in-other Z @@ -2093,6 +2157,7 @@ test_expect_success 'git checkout - --orphan with branch already provided comple main Z matching-branch Z matching-tag Z + other/HEAD Z other/branch-in-other Z other/main-in-other Z EOF