From patchwork Fri Nov 22 12:28:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13883131 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 7479A524F for ; Fri, 22 Nov 2024 12:32:39 +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=1732278761; cv=none; b=hcD+Fqrw38xp/hfldt/pfjrCVFPa3Ehyiw8CxkoTeat9lYZ+i2PS7NDVqs2iIlFAIrHYlR8HFr5UiyfjMIhqA7HByW7dhen7kdsXEbUnYSJNAFOck5Qi3BNKjoq+tRHW5g7V8xPgtAnrbHu58Nx+15nXpwJ60awHaQ5yN7bAOQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278761; c=relaxed/simple; bh=PuebsAVLrHvg+Vw5pYhATqcDI6lutIb3ycySk5pbDD8=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=NbH48UDwh5q7jVc8dvKE9ZQhaVCDF9mi+6NFPf/2HHtp/7Iu8N+8Td4LvLABHTaNh9/RVld8hJZinRHDn6eoL6tW7Fd679MPhA9Blcfz1tBYAvQfVIF+sxe/+OsCNRV3qfjRQUkR6i20Z89DvUem95rLhwTOryFTemdV5s6eIgc= 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=ieRCXP1O; 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="ieRCXP1O" 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=RKy1IRNtMiCt+0IUxnEzmDqPBmrunFkA1rXVtPYGSVY=; b=ieRCXP1OmMEV4PrA88V+G45GjFw/Gk/8jrvU0jQWv1kVSKrWlwYuq9lItf84xJPKO6DGfingIhHm qasKwFzJiMXrhmTI0vNDriTysAZ7jTnnDBG9+Kdyv/eitCqLnXJMOEUaUyIhPRM7zTgq8uJXvpIi bSd1wpB+mqpD0SZCa7m1PeKDgFr/015D/dqdjtUomtlBFrw0L9yV/UdKtH/ByP/bYdIQcsoP63ed 6gtczf4WQqOzeZcQiugL+XPXsc/I9Vdebth2fiIQATngNfYDFt6O5lVRHkGJgw9Uy+E4F4QW9Ara jiUSFJ4oaOQdkBpjLe6Np4BYvslmURphay8mpQ== Received: by omta-ad1-fd3-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241024 64bit (built Oct 24 2024)) with ESMTPS id <0SNC00NJNQUDBTC0@omta-ad1-fd3-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Fri, 22 Nov 2024 12:32:37 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Bence Ferdinandy Subject: [PATCH v15 01/10] t/t5505-remote: set default branch to main Date: Fri, 22 Nov 2024 13:28:42 +0100 Message-id: <20241122123138.66960-2-bence@ferdinandy.com> In-reply-to: <20241122123138.66960-1-bence@ferdinandy.com> References: <20241121225757.3877852-1-bence@ferdinandy.com> <20241122123138.66960-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: AAG/BPE2Gx8pkLvG8hopB4zX7FvKjrqK44Vl5GFUxSCbTi05zQ93/fmccNGAJtv9 Ul6VMUbN6v80/W7C6h4mX+CTQkZJwKy9KOV1jU7nkPrvFn1RHmRBZnjJmPE29NkG CyC+gJtQxGOSNgzJeBUHk/KfDSvDFhMHT96sK5RL2V1qe1gJlKB9qTJ1EAuKsndr JGIOReAxZszqb7kh3R50zR20F7oEmWMzxFrQpEbrPLT6dsAEnQHFZaHr7ruDcGwF 50jS7TEzD46mtJUMPSN9zJr4J/ojRfuCB6lp9CkMGotj2SD+pAyxniB43R5NM9lg FnvfNmdowIOyVP5Z/A2TBl1nxe9Z7EGUzRDiu0gOHi4/3NZqahDkx5fJhtI+7224 hD9X8xz1vJrpmeckDQYXgF0g1HjT/TlumnMCCPMJTKHgzb4GDMNRrZFXvAyDy6zf Ho3hhHyD1zyVOdQQo3I2df1KVBBd4g19hDhGVicy4MBYPGjaYu8U/yU= Consider the bare repository called "mirror" in the test. Running `git remote add --mirror -f origin ../one` will not change HEAD, consequently if init.defaultBranch is not the same as what HEAD in the remote ("one"), HEAD in "mirror" will be pointing to a non-existent reference. Hence if "mirror" is used as a remote by yet another repository, ls-remote will not show HEAD. On the other hand, if init.defaultBranch happens to match HEAD in "one", then ls-remote will show HEAD. Since the "ci/run-build-and-tests.sh" script globally exports GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main for some (but not all) jobs, there may be a drift in some tests between how the test repositories are set up in the CI and during local testing, if the test itself uses "master" as default instead of "main". In particular, this happens in t5505-remote.sh. This issue does not manifest currently, as the test does not do any remote HEAD manipulation where this would come up, but should such things be added, a locally passing test would break the CI and vice-versa. Set GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main in t5505-remote to be consistent with the CI. Signed-off-by: Bence Ferdinandy --- Notes: v9: - new patch - a bandaid for the CI issue noticed by Taylor (cf: https://lore.kernel.org/git/Zw8IKyPkG0Hr6%2F5t@nand.local/), but see https://lore.kernel.org/git/D4ZAELFWJMKN.S88LJ6YK31LZ@ferdinandy.com/ for the root cause in detail v10: no change v11: no change v12: added forgotten sign-off v13: commit message udpated to be more precise v14: made explicit in the commit message that the default branch is only set for some CI jobs v15: no change t/t5505-remote.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 532035933f..9b50276646 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -2,6 +2,9 @@ test_description='git remote porcelain-ish' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh From patchwork Fri Nov 22 12:28:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13883134 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 2EB81158848 for ; Fri, 22 Nov 2024 12:32:47 +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=1732278769; cv=none; b=IaTU8O3y9u0UaWy7OFNKfiXiUHUItrXd63dNnArJgjN3RuaSkZYLteS0es806bxWtlWNmVcPqSCIZIt730whaA3tdnUCmKNJJG8mM3i7lr4FcFInRk1UEjJdAqRnbV4/r9spGpr4lNH91s5U+CaozX4YO6Qtmw++gHHfvZO+tBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278769; c=relaxed/simple; bh=r0EhpFOX2i1klYG/AC6S4WwWU8kfogF6xeP5FZcikLw=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=EGv0sxL/W1guBE2RBUmBkGEeuvtAfo2F+j1ssN6iw31zB1KfZHKzUQCOHMnPgn9rjZ7sQejj6njksmYg7cZ6UWwHLwz952YsWf6AENNb93LuzOicQITjX/vBa3oEZXciyMzVn9MK21PDI8ge/JVL9FvM7abCU5vlJmpQMZCZuwI= 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=VFbaoo59; 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="VFbaoo59" 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=E+MOM+pOHVlonkZ/wSAer0AQTgl8WddkKS96eFU7KXM=; b=VFbaoo59Tf5km8uCDALndkNms60PNk7aett/MohF+Ht2sjq4gWRLsHx9ckgiLE6PvtBRjqn5HJJ9 t5D0qR8uEf092V1PtxrqUPsFD9+rQ7d0mk50u63YbQH6A+03aweR2aqOoocKB2dwkOEEG0e5ZBTk 8lAqVviRpspnJrYHR/cxtVDlX2y4YpLvJThodTDB1ExsZUYfnzY3BNLGwjf+I8cU6DPFROi5sWwq jVEDJxmjIUfueuXoG9c0kPrKN7G9tJLBb+ffzxZ1zkaj+BohzIJS3YqPoZkopSOjhZwPTIeDotnE 6xmAJH1W8uD/lMR5cNFeF2wCXNnfn8XTsg276A== Received: by omta-ad1-fd2-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241024 64bit (built Oct 24 2024)) with ESMTPS id <0SNC00FQ6QUMVB90@omta-ad1-fd2-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Fri, 22 Nov 2024 12:32:46 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Bence Ferdinandy Subject: [PATCH v15 02/10] t/t5505-remote: test failure of set-head Date: Fri, 22 Nov 2024 13:28:43 +0100 Message-id: <20241122123138.66960-3-bence@ferdinandy.com> In-reply-to: <20241122123138.66960-1-bence@ferdinandy.com> References: <20241121225757.3877852-1-bence@ferdinandy.com> <20241122123138.66960-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: AAHPmg53zA5rWzJswmd0gUM+aW2QZ5S71jt8DkyZjMJTtCE6MlFfLVcEzwuGFcay 04gdTC0WXFhQikV0a2whcJrH+DS0/QWikdgXqrWEUtBRvaOD3Z7Mu/WrnsAVT9WX PoYBvAVwawLMKmajYpxeWvtpUebCrR8FDu+sCfAfwp2mpzMFox3WOG/HggXTK5ud pI15C2eFW5BCp39Ei/WOJ5pSwehL3Ru8wBHowd8gCPBfDIv+yMpU57LmTGz86QkQ FNaIuExrMRn+8ajI+RdYzaqgMjXkb2DYYXHv+OngIVMxoc1fruWRzxZ5OpEW18Q0 rGPwXnv4Kbih4wOikhSRK/PDBECkG/Sv//KJdQ6bI33P96BRF/LObDUJCBaFdgrF WXD/ZMdYMkjJ61BVgZGEfgPxKOGQ8Hp1KOYhFo2pqVXlO8UN9uy4eX16vFziK8Wy ohrd+z8RXycnpwzBF7YcZip07vT6+aSlcUK8iH6xr03ZuPWKqSBKDnA= The test coverage was missing a test for the failure branch of remote set-head auto's output. Add the missing text and while we are at it, correct a small grammatical mistake in the error's output ("setup" is the noun, "set up" is the verb). Signed-off-by: Bence Ferdinandy --- Notes: v14: new patch v15: - use test_must_fail and test_when_finished builtin/remote.c | 2 +- t/t5505-remote.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/builtin/remote.c b/builtin/remote.c index 9093600965..8bca3fb04e 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1445,7 +1445,7 @@ static int set_head(int argc, const char **argv, const char *prefix) 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")) - result |= error(_("Could not setup %s"), buf.buf); + result |= error(_("Could not set up %s"), buf.buf); else if (opt_a) printf("%s/HEAD set to %s\n", argv[0], head_name); free(head_name); diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 9b50276646..61e3ecc1af 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -432,6 +432,18 @@ test_expect_success 'set-head --auto' ' ) ' +test_expect_success REFFILES 'set-head --auto failure' ' + test_when_finished "rm -f test/.git/refs/remotes/origin/HEAD.lock" && + ( + cd test && + touch .git/refs/remotes/origin/HEAD.lock && + test_must_fail git remote set-head --auto origin 2>err && + tail -n1 err >output && + echo "error: Could not set up refs/remotes/origin/HEAD" >expect && + test_cmp expect output + ) +' + test_expect_success 'set-head --auto has no problem w/multiple HEADs' ' ( cd test && From patchwork Fri Nov 22 12:28:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13883133 Received: from aib29agh124.zrh1.oracleemaildelivery.com (aib29agh124.zrh1.oracleemaildelivery.com [192.29.178.124]) (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 BE1CE282FA for ; Fri, 22 Nov 2024 12:32:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278768; cv=none; b=cJCRRYCAqpz0G+L5OtopNGymB1q000L0wxDa/EATpHFie5ppFkaiXWIkbEOBovorEtcFE37s3GDqs/b1AHYuQ/Wd7n9YI+MFjZ5wXEDbl9Rkxt6ibWU8uQhj0Is45dBvndAqfM9Baw9Pf8YGa1pMEQ7i78++HfXeH0Y4iutYyuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278768; c=relaxed/simple; bh=V5QaZS7f+Dh8E95oGg8+75OO6smeOvZljUWu0F3GrZA=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=AqRbMqCuu0ihDvQrUewxSJ7s+kNaV8eiYbZTExJbTR2cXhpwYGidHZDDwBPbTQ+lJ6qFoLIUNDhuNpWeGFfeGpGydT3NJhOq6w7OtkjafLMxs7ZGjkGUzqtoqeMEyl9CG9VH8o65aOS3sa5zNMywxJ/NQtSKkmTAPHma/9iweLQ= 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=gZFsVKkY; arc=none smtp.client-ip=192.29.178.124 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="gZFsVKkY" 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=xQ3S/doNTjnBAD1nwcpSmrKTvdm0bK0tzeTczr1J0ig=; b=gZFsVKkYGo2Sza65u3FgvAExnqBelNYIu5ju/KBtNLdz+blkQk3ZpxyOi+dQVp12BTG1W3MOOi7c qTM7WDR5lrClM+Do8rLxExesDaSQOMupO8X288OM7yUw8IanQ59mQSozUJuCug5sQCGdOc+4OZE7 1VRsHZaY+lEY0mkKkKJoWoYUZ66kSz8lSbIfQbgIoQ1myOvnciHZTIcSMiUmYb1wfjJVsIxNpE6q zoXZwf9+jx8wFAQIzt7YIm6Z/QTug9YxMi+kdMDOWCFhwp6StfD0WkDx8Aq/eW0IZORIWY7DqlGu f0+TMAIqA8zgUBgJ5Xq22EjwiSgTlKYqFQcC9A== Received: by omta-ad1-fd2-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241024 64bit (built Oct 24 2024)) with ESMTPS id <0SNC0058DQUKX060@omta-ad1-fd2-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Fri, 22 Nov 2024 12:32:45 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Bence Ferdinandy Subject: [PATCH v15 03/10] refs: standardize output of refs_read_symbolic_ref Date: Fri, 22 Nov 2024 13:28:44 +0100 Message-id: <20241122123138.66960-4-bence@ferdinandy.com> In-reply-to: <20241122123138.66960-1-bence@ferdinandy.com> References: <20241121225757.3877852-1-bence@ferdinandy.com> <20241122123138.66960-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: AAG/BPE2Gx8pkLvG8hopB4zX7FvKjrqK44Vl5GFUxSCbTi05zQ93/fmccNGAJtv9 Ul6VMUbN6v80/W7C6h44X+CTQkZJwKy9KOWNX+wXr9WE8CxwaE1C4FSIeGrHO5wx TgBUTPVJfwX9ncjjZ7K+sFjtOpHCxS9OzeaTgn8NQ0rLlRJkU6xgT5hiYzTFHIkn 5SFlpe0EFbcoY/GItcH4OTfWU9PDy2coVoDjJ+leN8WHpQ+nj1dJFFTj80HqMadv PfpnpT9DbZzwZcprq8aTiYxKbZzoHI6rQ+dpg9pIljuY1rHndMSqfUZ5addFfHLS W4NKO63zen1IxVP/K9/SclvlViUYiFxjuW8h9KKkCxAawyMpiMCs15dTpYE/A0Wx zi4vY+c2RYHyQgHnykaaAt9OazkZzLb006HTfacUmnp9oCRzT1GHAwFM8lv+gccC xw2sw4V0LDGnPV9MyPAF5xb7jSh956VgF64dfsZGJAEo5BryYps9yWA= When the symbolic reference we want to read with refs_read_symbolic_ref is actually not a symbolic reference, the files and the reftable backends return different values (1 and -1 respectively). Standardize the returned values so that 0 is success, -1 is a generic error and -2 is that the reference was actually non-symbolic. Signed-off-by: Bence Ferdinandy --- Notes: v13: new patch v14: - simplified the logic in reftables backend (thanks Junio) - update the comment in refs.h (thanks Patrick) - rewrote comment in refs-internal.h to point to the one in refs.h - created NOT_A_SYMREF=-2 constant v15: fix whitespace issues refs.h | 11 +++++++++++ refs/files-backend.c | 7 +++---- refs/refs-internal.h | 5 +++++ refs/reftable-backend.c | 6 ++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/refs.h b/refs.h index 108dfc93b3..22c2b45b8b 100644 --- a/refs.h +++ b/refs.h @@ -83,6 +83,17 @@ int refs_read_ref_full(struct ref_store *refs, const char *refname, int refs_read_ref(struct ref_store *refs, const char *refname, struct object_id *oid); +#define NOT_A_SYMREF -2 + +/* + * Read the symbolic ref named "refname" and write its immediate referent into + * the provided buffer. Referent is left empty if "refname" is not a symbolic + * ref. It does not resolve the symbolic reference recursively in case the + * target is also a symbolic ref. + * + * Returns 0 on success, -2 if the "refname" is not a symbolic ref, + * -1 otherwise. + */ int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname, struct strbuf *referent); diff --git a/refs/files-backend.c b/refs/files-backend.c index 0824c0b8a9..4cc43c32f2 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -596,10 +596,9 @@ static int files_read_symbolic_ref(struct ref_store *ref_store, const char *refn unsigned int type; ret = read_ref_internal(ref_store, refname, &oid, referent, &type, &failure_errno, 1); - if (ret) - return ret; - - return !(type & REF_ISSYMREF); + if (!ret && !(type & REF_ISSYMREF)) + return NOT_A_SYMREF; + return ret; } int parse_loose_ref_contents(const struct git_hash_algo *algop, diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 2313c830d8..1399fee61c 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -673,6 +673,11 @@ struct ref_storage_be { ref_iterator_begin_fn *iterator_begin; read_raw_ref_fn *read_raw_ref; + + /* + * Please refer to `refs_read_symbolic_ref()` for the expected + * behaviour. + */ read_symbolic_ref_fn *read_symbolic_ref; reflog_iterator_begin_fn *reflog_iterator_begin; diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 38eb14d591..e8afcda1f9 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -830,10 +830,12 @@ static int reftable_be_read_symbolic_ref(struct ref_store *ref_store, return ret; ret = reftable_stack_read_ref(stack, refname, &ref); - if (ret == 0 && ref.value_type == REFTABLE_REF_SYMREF) + if (ret) + ret = -1; + else if (ref.value_type == REFTABLE_REF_SYMREF) strbuf_addstr(referent, ref.value.symref); else - ret = -1; + ret = NOT_A_SYMREF; reftable_ref_record_release(&ref); return ret; From patchwork Fri Nov 22 12:28:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13883135 Received: from aib29agh124.zrh1.oracleemaildelivery.com (aib29agh124.zrh1.oracleemaildelivery.com [192.29.178.124]) (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 06502158848 for ; Fri, 22 Nov 2024 12:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278774; cv=none; b=eii7WnQPboAAtfNJpRZ3vLLLWCfEPBqSXMG6M6bVdUcwjs0ArhLLe/TSFwvWiVHpsyBY5s/3DJteO/DB1R2eEpb220T6rZwXRizBEOMMzW0H9suhG6kBeKksQ8r1weOR9qUpizvN4zAqLLGs4ArAHJzqfOOjrJ4UN5/AyEnlJBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278774; c=relaxed/simple; bh=zQuN69ysCiFYXIQn3U0JvmXfD7VKjFGFnnOGrZprzzg=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=MchOvrNYPZd/WBr5LXwgElqKOnorlqebZXUkdNeDcV3SoTuyjRUGzY8XekyAd6iLOrgg5XLZhF9oCBaOPkgmk9/k9AW9b3EaUMTd80KG8+fDSxj+9UhzeFz0SKoXVrIRXHG2TbBpMLvki7jd5hoL7YWJNDtp0zlle5FCJ+DuEek= 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=F4ebdduq; arc=none smtp.client-ip=192.29.178.124 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="F4ebdduq" 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=E+3ljD7glNwezg6YDAwPuf41rWAMslRBGHRyiKpaKcY=; b=F4ebdduqiBGzeVjMfONRs1JszH6wcQ1ArlVj84T5DQzWLU/E6TjDhqxrR9l1vNfkhC+GWpSyHuSO i4/K3KNhGURQ5E9h5biaCz1Hle8/hK1HDmY14Xsp1jEaHAGuBBCbPTRTZPDTIVfohRSbiSjS8N1H mk2Vdmy2cwCj1YLZl7d0prSr1dENaCN2Arl0Jf8qMQ/j+3hAlhEEFGGE8n6BGnh8TyH/qSKWI7rv JTnAgkQbqXvikb8DyL1/BEYKzNclQyAnatVbvJvlLnmppalESyBbcl7JVrlLqyTFhv1y379+/1Hg 0YrTJNgv+mdUlGt+uZfN8dkpCjwrpX/+raJQNA== Received: by omta-ad1-fd2-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241024 64bit (built Oct 24 2024)) with ESMTPS id <0SNC0058PQUQX060@omta-ad1-fd2-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Fri, 22 Nov 2024 12:32:50 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Bence Ferdinandy Subject: [PATCH v15 04/10] refs: atomically record overwritten ref in update_symref Date: Fri, 22 Nov 2024 13:28:45 +0100 Message-id: <20241122123138.66960-5-bence@ferdinandy.com> In-reply-to: <20241122123138.66960-1-bence@ferdinandy.com> References: <20241121225757.3877852-1-bence@ferdinandy.com> <20241122123138.66960-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: AAG/BPE2Gx8pkLvG8hopB4zX7FvKjrqK44Vl5GFUxSCbTi05zQ93/fmccNGAJtv9 Ul6VMUbN6v80/W7C6h5BX+CTQkZJwKy9KOVmR1yAL4tTedvDOvYhW9YVGmwpkHlg Z5NC9+812mauxyW9yWXWd8cQCl671EMjKxjC8CeghmPJnkx5VjKVH7nffhL9SASP Nv2LZAZ+SfURQ1anVfbu5d5d1BzJ8eVjoVBSRhs39ALW0FR02bEbRZJQlWuw9iur vbIOs7l9T792rtRX2PrPLBVxZZ/wrPlkHenLSF+2URqoWb3e5S02MEjFQnHOlcKb 75PWhHDSnCV9tktd9je6lTjMAk5KAgnSTCK4BGJr55UoTB9+5/vd+bNKxGCBfpDi 7Mz6T1OfDILv6J1qHEdVbuq9dI93z2fDoiQK1doIaWsnPCxeCCy+nKk9enXLrSVl GMvRfttlFFqycP6a06379oJYSvlyceom97nnuWlztbuPFi7PHJT8ivA= When updating a symref with update_symref it's currently not possible to know for sure what was the previous value that was overwritten. Extend refs_update_symref under a new function name, to record the value after the ref has been locked if the caller of refs_update_symref_extended requests it via a new variable in the function call. Make the return value of the function notify the caller, if the previous value was actually not a symbolic reference. Keep the original refs_update_symref function with the same signature, but now as a wrapper around refs_update_symref_extended. 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 v7: - remove the whole before_target concept from the backends and handle checking it in refs.c instead (thanks Karthik) - rename the before_target to referent which is how the same concept is called in the backends - change commit prefix to be more in line with project standards v8: no change v9: - instead of adding parameters to refs_update_symref, rename what was in v8 as refs_update_symref_extended and make refs_update_symref a wrapper for that. This significantly reduces the number of files that need to be touched, and avoids adding a lot of dummy NULL-s in unrelated places. v10: no change v11: no change v12: no change v13: if referent is a non-symbolic ref, record the hash in referent and signal this with a return value of -1 v14: - mistakes were made: trying to read the referent should NOT lead to an actual error, even if it doesn't work out in the end, that part of the code should only set the return to -2 or not touch it - the returned error code by the above was also incorrect and now is -2 (and uses NOT_A_SYMREF now) v15: no change refs.c | 22 ++++++++++++++++++++-- refs.h | 4 ++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/refs.c b/refs.c index 5f729ed412..d80efd58f0 100644 --- a/refs.c +++ b/refs.c @@ -2115,6 +2115,13 @@ 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) +{ + return refs_update_symref_extended(refs, ref, target, logmsg, NULL); +} + +int refs_update_symref_extended(struct ref_store *refs, const char *ref, + const char *target, const char *logmsg, + struct strbuf *referent) { struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; @@ -2125,10 +2132,22 @@ int refs_update_symref(struct ref_store *refs, const char *ref, ref_transaction_update(transaction, ref, NULL, NULL, target, NULL, REF_NO_DEREF, logmsg, &err) || - ref_transaction_commit(transaction, &err)) { + ref_transaction_prepare(transaction, &err)) { ret = error("%s", err.buf); + goto cleanup; } + if (referent && refs_read_symbolic_ref(refs, ref, referent) == NOT_A_SYMREF) { + struct object_id oid; + if (!refs_read_ref(refs, ref, &oid)) { + strbuf_addstr(referent, oid_to_hex(&oid)); + ret = NOT_A_SYMREF; + } + } + + if (ref_transaction_commit(transaction, &err)) + ret = error("%s", err.buf); +cleanup: strbuf_release(&err); if (transaction) ref_transaction_free(transaction); @@ -2948,4 +2967,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 22c2b45b8b..5c46ac9f34 100644 --- a/refs.h +++ b/refs.h @@ -584,6 +584,10 @@ 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); +int refs_update_symref_extended(struct ref_store *refs, const char *refname, + const char *target, const char *logmsg, + struct strbuf *referent); + enum action_on_err { UPDATE_REFS_MSG_ON_ERR, UPDATE_REFS_DIE_ON_ERR, From patchwork Fri Nov 22 12:28:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13883136 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 5F9FF1DE882 for ; Fri, 22 Nov 2024 12:32:53 +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=1732278775; cv=none; b=uzhlWyBtSOjw4ijs6JGmcLoJ/fh0thAq/rxJsX6gtQTWKPFFkwoadYIEROrf2tinftWutM8reSbNs03KfJAgMn47W+LChtDfpQ/dgU/hZAnz1ACxK3JTjSiNOIrPlDDeFY26FaRvmymlDgFmBYKLRo7u7wFVOERr1ePbS6uA8IY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278775; c=relaxed/simple; bh=rXbchmTmY3jCahx7i+deCMtNn8+ZuWCFspEQ9lixr48=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=nRVkqxHZHN7Nvux3TkIyNse4pZ9LiKEkYCNcSsprTa4/tjEsRKgfLvb9sm7hLRg/mKNLgTF9HGRK5hXup5K30JhkmMbHWC/sX+KdJFJ8TNjapDwjWAkt0bixqK06M/t080nyu6cPBtlM/VLANCFricEIczarwewaCEH7hhWrvRA= 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=a4RDGXHB; 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="a4RDGXHB" 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=jmY+Y0f5ynAegZpHkOwNewLJGIIb4XxIgR6u0bwpYp0=; b=a4RDGXHBX5SZqDKHCCi5ztGWqjqKrCb+FMHUxG9cWtC/cTSUH0dtt8IIrBuUtEwZxGUsOcjQ6sal qacqORPuYvTdAXFGzwt9rkzX7WuO1UyRoOIy9gqgLGJUuP+l3WodzeWg7a6qP7ccA/sP4Ggjhsz1 ubH6q0IzyCMF+ltkmsyQBtpd4gEnCq15KYy3R/FFfDsrmC0nGk30IjjQPuLP3+C3FH2HiadXUAQ+ KziZCDQjud4/+UY1QC09slGnvOiaKjhCTg2YjvxdEplNbRVCzX6GRHxAalaM93RsHuibUCmZfBg3 nv/FQEhVMNIRJ9MqrQOGKPX1TcWP5hpqCuJSOg== Received: by omta-ad1-fd1-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241024 64bit (built Oct 24 2024)) with ESMTPS id <0SNC00LQIQUR6PB0@omta-ad1-fd1-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Fri, 22 Nov 2024 12:32:51 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Bence Ferdinandy Subject: [PATCH v15 05/10] remote set-head: refactor for readability Date: Fri, 22 Nov 2024 13:28:46 +0100 Message-id: <20241122123138.66960-6-bence@ferdinandy.com> In-reply-to: <20241122123138.66960-1-bence@ferdinandy.com> References: <20241121225757.3877852-1-bence@ferdinandy.com> <20241122123138.66960-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: AAHPmg53zA5rWzJswmd0gUM+aW2QZ5S71jt8DkyZjMJTtCE6MlFfLVcEzwuGFcay 04gdTC0WXFhQikV0a2wpcJrH+DS0/QWikdh5lx22DPqVIjurJm/mtCZ15Jyer+8L nP7edMe12zevqeacfpK58DBxvHUC7mmsGptlLNis5FQXBsWpAEi6UzMCQd4Id0AX MmizGES23NoD2ba0eaJC+AwSIXL471ML+4vL1xsJ2in8VCrhmOxLgems7MsWY0Yk 4E3IZqwrAS9fW7ozJPWT31tDsAsJwHTSxiOyQeyJuQpKD8KvS0LH1Nk0ejpzpaPK 3uOnWFIE/H95v+8/vnblYSGpib6wkXJeRGZzNh7ohg3hCPnvaZV8MzWOSSvSVlbb VlCZ+6f7ecPMurEWWoCKXt3TSf5z1ugQWCWIfKbHX2l+yootn8xaoOUtqjdcWuvI eria9mVOh5INbYkhqVLCwo3/cg+7gK1QmlgIpG9A579hyW7T9ubnyuQ= Make two different readability refactors: Rename strbufs "buf" and "buf2" to something more explanatory. Instead of calling get_main_ref_store(the_repository) multiple times, call it once and store the result 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. Signed-off-by: Bence Ferdinandy --- Notes: v5: new patch (split from the next patch as a preparatory step) v6: no change v7: - change commit prefix to be more in line with project standards v8: no change v9: - further improve readability by renaming buf, and buf2 consistently with how patch 6 was already done v10: no change v11: no change v12: no change v13: more precise wording for commit message v14: no change v15: no change builtin/remote.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 8bca3fb04e..47ca650de8 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1402,8 +1402,9 @@ static int show(int argc, const char **argv, const char *prefix) 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 b_head = STRBUF_INIT, b_remote_head = 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, @@ -1415,7 +1416,7 @@ static int set_head(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, builtin_remote_sethead_usage, 0); if (argc) - strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]); + strbuf_addf(&b_head, "refs/remotes/%s/HEAD", argv[0]); if (!opt_a && !opt_d && argc == 2) { head_name = xstrdup(argv[1]); @@ -1434,25 +1435,25 @@ 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)) - result |= error(_("Could not delete %s"), buf.buf); + if (refs_delete_ref(refs, NULL, b_head.buf, NULL, REF_NO_DEREF)) + result |= error(_("Could not delete %s"), b_head.buf); } else usage_with_options(builtin_remote_sethead_usage, options); if (head_name) { - strbuf_addf(&buf2, "refs/remotes/%s/%s", argv[0], head_name); + strbuf_addf(&b_remote_head, "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)) - 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")) - result |= error(_("Could not set up %s"), buf.buf); + if (!refs_ref_exists(refs, b_remote_head.buf)) + result |= error(_("Not a valid ref: %s"), b_remote_head.buf); + else if (refs_update_symref(refs, b_head.buf, b_remote_head.buf, "remote set-head")) + result |= error(_("Could not set up %s"), b_head.buf); else if (opt_a) printf("%s/HEAD set to %s\n", argv[0], head_name); free(head_name); } - strbuf_release(&buf); - strbuf_release(&buf2); + strbuf_release(&b_head); + strbuf_release(&b_remote_head); return result; } From patchwork Fri Nov 22 12:28:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13883138 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 4DEE4171088 for ; Fri, 22 Nov 2024 12:33:00 +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=1732278782; cv=none; b=HiKiO5FExHo4EHZqgNEo2Z67gGMUJkSlNDzvq1LmDn6vkjWImDflWqV08wFe5j3X9OHyiqODL9DE0WqnCN4GX23ShAY8LSOvX3SsMNXpGwJX21A82D8LppGiHzZwgvoiMbRKblJzPmZ7uP2q3SsMWwmKHeLQp+1AQ//r+eH8nCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278782; c=relaxed/simple; bh=uOiFThTXmBuQlkaFYZ3JcNtAmXJSSw4seb5EGtE667c=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=tW4pD00Q10L9C5VVn596koD2pjlpDcnW4DIbJvL8S1Iz+wv5GXHinuKgmXQ8BNMI39DdgRwUCBfJlCVRCFqIiIT+T8QImBTo6kbJR1UKFPkS0DYB/S9RJzHvWXIdCTeOQbHQWjQOx3pTLkYunu8MasvkDNFAbEjgF0piHVhBClM= 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=FgJw+vQD; 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="FgJw+vQD" 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=pW155Tyzkw1hfbQWTBK2wqhAjVlNE0gEixj3aPmAk70=; b=FgJw+vQDAvEnan8ij9LVohj5K9HoKIr7ijFj5RkSy3fWqEuzcB7Z4/QoZ+Z606jYrzljBSAjOIsd TbRMZ3LV2T9yaS4qxRlNR1NGe+aGNolttn9eUSkEQPq/b+RdPNRdf/CAV2HrxETr3AoEmo+okz5G Hv83GmQp/HNVOwFiBDWuNUJqXIVAbQgDXamDeCr1rCyg6HgxfTIrgMljRdP+XKQ/uxXRRybqCG2S QN8PYkhFDdyivIbtfQ8f+3WeKlgyXO7HTXa1Ij4hhPsM4opj3wMs0hdAxD8Rh18YHLy8CxsFcXly O1eGg+VXS/giCc1RdX+yNk9Qaut9N5tPGiz/og== Received: by omta-ad1-fd1-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241024 64bit (built Oct 24 2024)) with ESMTPS id <0SNC00IH3QUYOC70@omta-ad1-fd1-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Fri, 22 Nov 2024 12:32:58 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Bence Ferdinandy Subject: [PATCH v15 06/10] remote set-head: better output for --auto Date: Fri, 22 Nov 2024 13:28:47 +0100 Message-id: <20241122123138.66960-7-bence@ferdinandy.com> In-reply-to: <20241122123138.66960-1-bence@ferdinandy.com> References: <20241121225757.3877852-1-bence@ferdinandy.com> <20241122123138.66960-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: AAG/BPE2Gx8pkLvG8hopB4zX7FvKjrqK44Vl5GFUxSCbTi05zQ93/fmccNGAJtv9 Ul6VMUbN6v80/W7C6h5WX+CTQkZJwKy9KOV3NdVvKrD9FxlxKp9azPJhkvXrj8sE 37GkXMKmJR2z3znPgZ6uhiKvRf0HbZMgMxA5GPWNlGLgIIuG540SfcbmLwW53Gh2 vB601eYn0eol+K42QDebTtQqMGXFBTcWA3wEbzUcRsOtE3nbW4AmX+40z9B50g1q GNNwFwFCjcwSbO65sCk/hoFYHu8WH9GPA0OoHstEu8nj3DaZXzK5ka9VgWTJJzpE hZEKzs5IxbIV/gdz+GhYJEdx6bQvlEvxnmWHIbD8CSm+odzJz8pux2SJoqyGqgDZ JXWlGzBg6wOFRx+jYj14cKFpdKIv0jhMtBc7QPsSSg3TTl2T5KJr3XaWFZhhG4gr UIg4H0NPboOod4407nNPR5f6ieeSawx8ptQYMowGGGEhhMuEhy88G8M= 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 edge cases, if HEAD is changed from a previous symbolic reference that was not a remote branch, explicitly call attention to this fact, and also notify the user if the previous reference was not a symbolic reference. 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 v7: - change commit prefix to be more in line with project standards - fixed tests to also work with the reftable backend - renamed report function, fixed style issue with checking buf len - fixed not releasing an strbuf v8: no change v9: - mark output strings in report_set_head_auto as translatable - rename buf_prev to b_local_head for consistency - use ${SQ} in tests instead of '\'' v10: no change v11: no change v12: no change v13: added handling the edge case of previous remote/HEAD being a detached HEAD v14: - fixed badly named variable - fixed not reporting errors correctly v15: no change builtin/remote.c | 59 +++++++++++++++++++++++++++++++++++--------- t/t5505-remote.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 109 insertions(+), 13 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 47ca650de8..e1f15e68f4 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1399,10 +1399,38 @@ static int show(int argc, const char **argv, const char *prefix) return result; } +static void report_set_head_auto(const char *remote, const char *head_name, + struct strbuf *b_local_head, int was_detached) { + struct strbuf buf_prefix = STRBUF_INIT; + const char *prev_head = NULL; + + strbuf_addf(&buf_prefix, "refs/remotes/%s/", remote); + skip_prefix(b_local_head->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 (!b_local_head->len) + printf(_("'%s/HEAD' is now created and points to '%s'\n"), + remote, head_name); + else if (was_detached && b_local_head->len) + printf(_("'%s/HEAD' was detached at '%s' and now points to '%s'\n"), + remote, b_local_head->buf, head_name); + else + printf(_("'%s/HEAD' used to point to '%s' " + "(which is not a remote branch), but now points to '%s'\n"), + remote, b_local_head->buf, head_name); + strbuf_release(&buf_prefix); +} + static int set_head(int argc, const char **argv, const char *prefix) { - int i, opt_a = 0, opt_d = 0, result = 0; - struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT; + int i, opt_a = 0, opt_d = 0, result = 0, was_detached; + struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT, + b_local_head = STRBUF_INIT; char *head_name = NULL; struct ref_store *refs = get_main_ref_store(the_repository); @@ -1440,20 +1468,27 @@ static int set_head(int argc, const char **argv, const char *prefix) } else usage_with_options(builtin_remote_sethead_usage, options); - if (head_name) { - strbuf_addf(&b_remote_head, "refs/remotes/%s/%s", argv[0], head_name); - /* make sure it's valid */ - if (!refs_ref_exists(refs, b_remote_head.buf)) - result |= error(_("Not a valid ref: %s"), b_remote_head.buf); - else if (refs_update_symref(refs, b_head.buf, b_remote_head.buf, "remote set-head")) - result |= error(_("Could not set up %s"), b_head.buf); - else if (opt_a) - printf("%s/HEAD set to %s\n", argv[0], head_name); - free(head_name); + if (!head_name) + goto cleanup; + strbuf_addf(&b_remote_head, "refs/remotes/%s/%s", argv[0], head_name); + if (!refs_ref_exists(refs, b_remote_head.buf)) { + result |= error(_("Not a valid ref: %s"), b_remote_head.buf); + goto cleanup; + } + was_detached = refs_update_symref_extended(refs, b_head.buf, b_remote_head.buf, + "remote set-head", &b_local_head); + if (was_detached == -1) { + result |= error(_("Could not set up %s"), b_head.buf); + goto cleanup; } + if (opt_a) + report_set_head_auto(argv[0], head_name, &b_local_head, was_detached); +cleanup: + free(head_name); strbuf_release(&b_head); strbuf_release(&b_remote_head); + strbuf_release(&b_local_head); return result; } diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 61e3ecc1af..d15b579c95 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -444,12 +444,63 @@ test_expect_success REFFILES 'set-head --auto failure' ' ) ' +test_expect_success 'set-head --auto detects creation' ' + ( + cd test && + git update-ref --no-deref -d refs/remotes/origin/HEAD && + git remote set-head --auto origin >output && + echo "${SQ}origin/HEAD${SQ} is now created and points to ${SQ}main${SQ}" >expect && + test_cmp expect output + ) +' + +test_expect_success 'set-head --auto to update a non symbolic ref' ' + ( + cd test && + git update-ref --no-deref -d refs/remotes/origin/HEAD && + git update-ref refs/remotes/origin/HEAD HEAD && + HEAD=$(git log --pretty="%H") && + git remote set-head --auto origin >output && + echo "${SQ}origin/HEAD${SQ} was detached at ${SQ}${HEAD}${SQ} and now points to ${SQ}main${SQ}" >expect && + test_cmp expect output + ) +' + +test_expect_success 'set-head --auto detects no change' ' + ( + cd test && + git remote set-head --auto origin >output && + echo "${SQ}origin/HEAD${SQ} is unchanged and points to ${SQ}main${SQ}" >expect && + test_cmp expect output + ) +' + +test_expect_success 'set-head --auto detects change' ' + ( + cd test && + git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/ahead && + git remote set-head --auto origin >output && + echo "${SQ}origin/HEAD${SQ} has changed from ${SQ}ahead${SQ} and now points to ${SQ}main${SQ}" >expect && + test_cmp expect output + ) +' + +test_expect_success 'set-head --auto detects strange ref' ' + ( + cd test && + git symbolic-ref refs/remotes/origin/HEAD refs/heads/main && + git remote set-head --auto origin >output && + echo "${SQ}origin/HEAD${SQ} used to point to ${SQ}refs/heads/main${SQ} (which is not a remote branch), but now points to ${SQ}main${SQ}" >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 "${SQ}two/HEAD${SQ} is now created and points to ${SQ}main${SQ}" >expect && test_cmp expect output ) ' @@ -468,6 +519,16 @@ 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 "${SQ}origin/HEAD${SQ} has changed from ${SQ}side2${SQ} and now points to ${SQ}main${SQ}" >expect && + test_cmp expect output + ) +' + cat >test/expect < X-Patchwork-Id: 13883137 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 C873B1DE882 for ; Fri, 22 Nov 2024 12:32:58 +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=1732278780; cv=none; b=BgPMiyq9iLc9X5JAs8YRWkcjergqGC5yYIku6MADhklIk1jBkbN511Ba4IioM/AY1tMEB5scnOwlxuZSOOTv4sXelg61ZCOszH8sL8ptzX7cHInMVp/bwZcBLp2f3e9vwl1TMKCtzECwNs6aNukO4/xQAb2JGOjeGstUovbWkaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278780; c=relaxed/simple; bh=wL1B3kE/YKcW02mzD8J/E6BsYujyTItoEWojtjYowV8=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=nPP1Pndldpc+Y8JZylmOtSTD0DwLDNubqO+vc18YaTe84V8eYkSqUY5HVEBHt/NNpBwe5Iy4vvcekasX9qc5j72da3ajBMmmB3KhkACmSBOTHHwIoqm7meKF1BAWjiKNtXdbWW1LR1bgH6v3RHrN+S+qEIRoPF7+hnUbHp4a2n4= 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=O2QHHwxV; 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="O2QHHwxV" 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=DLz1OJc5jAvqKMGIAjYA8wHl5npMYB3PQ15RurI1HuQ=; b=O2QHHwxVir7lDFVezbj8jlTSD6g+17HHNaiC/0HBq/sr22eiHpmfdFbim+tfNPQYFJMjXkAcXd2l N/aPW/ExPefVOjSQQz8OSQJdxJcLRZKCtu71/9KFQti4YTArbZbFY2YNt6AHZHv3IYu6bo0uE70r fShFT89ien7klYOo0se78jC1qL70Cq3ZR7kp4tfYU0BU3fd0pEgqYI1iLjhhXV4bezcm4tAKAa0U rqveZ1tYPu0nWt7S+i052slCVHGyaBR8iAPfcMaahJGDcZE+lqfWVfM8A7f9UIueVqo7km8tZYl9 MRFw+tkHgtKop28pOGZUOIMYQTaCE/5rl4EKyQ== Received: by omta-ad1-fd2-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241024 64bit (built Oct 24 2024)) with ESMTPS id <0SNC00FQJQUXVB90@omta-ad1-fd2-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Fri, 22 Nov 2024 12:32:57 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Bence Ferdinandy Subject: [PATCH v15 07/10] refs: add TRANSACTION_CREATE_EXISTS error Date: Fri, 22 Nov 2024 13:28:48 +0100 Message-id: <20241122123138.66960-8-bence@ferdinandy.com> In-reply-to: <20241122123138.66960-1-bence@ferdinandy.com> References: <20241121225757.3877852-1-bence@ferdinandy.com> <20241122123138.66960-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: AAG/BPE2Gx8pkLvG8hopB4zX7FvKjrqK44Vl5GFUxSCbTi05zQ93/fmccNGAJtv9 Ul6VMUbN6v80/W7C6h5NX+CTQkZJwKy9KOWUNNN+u0V+6WFXKKwoNDDmKiRS7JGU 5CXMEv2CEtYhCPtdgKXfev+D4ujTrXSPR2t8Q0ynuy0YufPbgeyIWczK/hkKrdF3 TGRoZ3u+UPnQJzw0Nkpyn4NX2JukD3dyCKfqAPUWF9rcQjvdXoYKru4y1YX8AQY3 oUJlNfB8AVh4wG95Ta21P3VjtZgTzigTARF3/2TekfRM8rlTyoIeLpvBJbhPJku9 Nt5EGLMW407RpMZAv13CC71Gs7mBUcZyDNfIvuuLIu9fu5Y2c1Esx3WF5rf9SOWD W6LJ+g6BgynH6XZBpNKVHP5zO/1hcEYATt94aLq2PQ3Lo1jzkpQc20wBk0R0NtUj zs96tQ/GpsRZ7BGCGB+isZLwUxHGpXGhs2MVqqoT1ApZOlDOgMWJxMsW 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 v7: - change commit prefix to be more in line with project standards - changed error checking to Karthik's suggestion v8: no change v9: - no change v10: no change v11: no change v12: no change v13: no change v14: no change v15: no change refs.h | 4 +++- refs/files-backend.c | 24 ++++++++++++++++-------- refs/reftable-backend.c | 6 ++++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/refs.h b/refs.h index 5c46ac9f34..b243739e4b 100644 --- a/refs.h +++ b/refs.h @@ -773,8 +773,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 4cc43c32f2..23ae74089d 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -2501,14 +2501,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", @@ -2521,7 +2525,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; } /* @@ -2601,9 +2605,11 @@ 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 { + ret = check_old_oid(update, &lock->old_oid, err); + if (ret) { + goto out; + } } } else { /* @@ -2634,9 +2640,11 @@ 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 { + ret = check_old_oid(update, &lock->old_oid, err); + if (ret) { + goto out; + } } /* diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index e8afcda1f9..965c17d795 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -1208,10 +1208,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"), @@ -1223,7 +1226,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 Fri Nov 22 12:28:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13883139 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 71107171088 for ; Fri, 22 Nov 2024 12:33:05 +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=1732278787; cv=none; b=bNyvuifY8vJva/v8mckQ1zKLcymLrcE1chq3poELAB+SkeUjA1tf9De1nSCjs8FV0J5+51joaAYL62f+4kVeviLNZ9FXAk2eplBbXd+P7NtQ7FRwhm+/tYtHj8OYNg1cZXXbZQ9PPfhaXraL1rNXgya3PLlYR1BbuqnVoJrm79Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278787; c=relaxed/simple; bh=YJJNr41+sGGAgAE7ic//1sXvJ9lK/ef/V5AI46RTdmE=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=ku7PTKj4GOUdtlGnY9G5jWrUu8U0i7hGmZlFfeCyHiWFtply2YGT1MDs9X2DEncTaVKt2aDIJb/KY/QHMOWsMYDqRt/QyopeGf3YrUw7CmnXiF3XlrAlSiyUvL0jE+kvxbraleTBJb7OzCTrbxC5lwTx4X2QJanWsj15xmhfzH8= 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=o1hDcCL0; 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="o1hDcCL0" 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=ZwjOTSGd7MdY4McZ4kjRjEkoxDK2c4FLBNvSn5YBaJg=; b=o1hDcCL0weCOXSIhp/QPiHAYK9Plhp2RjBY5LEV+lwpJz3iY6xAhFwKPhwtb1kmkB8kCXhNc46Qg sPb5nE6q+Kh26h4TXof3Cl2wrCq2WmDyQnGweZ2ptsETNxDH/A3ahxznp4WAKxSeXmrqoT7VxcoS kmpvIwuTsJZqx8Wkd0KDgLG4dV3wlnscjARV2zPWSke79DKouE9kiPmkz80VJQJRAv7yy5aBUFTT bpdGkLok1x6H3lYKw+Yurhk8zA52gLAhcuI4S2inrI50XraJeFgjXg5/DGVTBcMukjMjZK/gxXIO 8JsrVxFs01y94P/BeCIq+vtLw+EaeIn+GAhLTQ== Received: by omta-ad1-fd3-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241024 64bit (built Oct 24 2024)) with ESMTPS id <0SNC00NK2QV3BTC0@omta-ad1-fd3-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Fri, 22 Nov 2024 12:33:03 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Bence Ferdinandy Subject: [PATCH v15 08/10] refs: add create_only option to refs_update_symref_extended Date: Fri, 22 Nov 2024 13:28:49 +0100 Message-id: <20241122123138.66960-9-bence@ferdinandy.com> In-reply-to: <20241122123138.66960-1-bence@ferdinandy.com> References: <20241121225757.3877852-1-bence@ferdinandy.com> <20241122123138.66960-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: AAHPmg53zA5rWzJswmd0gUM+aW2QZ5S71jt8DkyZjMJTtCE6MlFfLVcEzwuGFcay 04gdTC0WXFhQikV0a2w0cJrH+DS0/QWikdhykXHipalKBUcO5WLeNHqmMTjKhktM fDoGw6/Wvlem/yeCjxF+CoSr9xPEBr++NELK62jXofDZ8g8UYOjpBjkjtOsn6OGp 6XzQ4e1o3II2T6AP7CVXbCg4muYUhioG+2WQt5OfZdvkK2cKc3bPlVOW8xRE8QFH Q/50vPiJ2epE5pTGPxYJ9NaQnFHSh5jOKHYo8mYZ+uxTHmKlssOY7QlZPwJx6MwF TBKMx4HXPG6MYrxW3K8o2niERWNQU+iaK4pnbbvvRYK9rn6RJOZaoyEZ8aYwlJ19 jcskgE8y8CcrDvIE+VhFRiGIAZfgthtX1YqWY5rgviX5W68Ss7l+y91vYs1qbAUA /Ssfy5tA8c1i60G3C/ru/UBKb5F5ffLoyhl7n+Jc81vKNolSYIPMED8= 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 v7: - change commit prefix to be more in line with project standards - refactored code to accommodate changes in the first patch, but otherwise no change v8: no change v9: - no change (except for following through the refs_update_symref_extended refactoring) v10: no change v11: no change v12: no change v13: changes only due to changes in previous patch v14: no change v15: no change builtin/remote.c | 2 +- refs.c | 33 ++++++++++++++++++++++++--------- refs.h | 2 +- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index e1f15e68f4..4a8b2ef678 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1476,7 +1476,7 @@ static int set_head(int argc, const char **argv, const char *prefix) goto cleanup; } was_detached = refs_update_symref_extended(refs, b_head.buf, b_remote_head.buf, - "remote set-head", &b_local_head); + "remote set-head", &b_local_head, 0); if (was_detached == -1) { result |= error(_("Could not set up %s"), b_head.buf); goto cleanup; diff --git a/refs.c b/refs.c index d80efd58f0..2efa6bcc5c 100644 --- a/refs.c +++ b/refs.c @@ -2116,26 +2116,38 @@ 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) { - return refs_update_symref_extended(refs, ref, target, logmsg, NULL); + return refs_update_symref_extended(refs, ref, target, logmsg, NULL, 0); } int refs_update_symref_extended(struct ref_store *refs, const char *ref, const char *target, const char *logmsg, - struct strbuf *referent) + struct strbuf *referent, int create_only) { struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; - int ret = 0; + int ret = 0, prepret = 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_prepare(transaction, &err)) { + if (!transaction) { + error_return: ret = error("%s", err.buf); goto cleanup; } + if (create_only) { + if (ref_transaction_create(transaction, ref, NULL, target, + REF_NO_DEREF, logmsg, &err)) + goto error_return; + prepret = ref_transaction_prepare(transaction, &err); + if (prepret && prepret != TRANSACTION_CREATE_EXISTS) + goto error_return; + } else { + if (ref_transaction_update(transaction, ref, NULL, NULL, + target, NULL, REF_NO_DEREF, + logmsg, &err) || + ref_transaction_prepare(transaction, &err)) + goto error_return; + } + if (referent && refs_read_symbolic_ref(refs, ref, referent) == NOT_A_SYMREF) { struct object_id oid; if (!refs_read_ref(refs, ref, &oid)) { @@ -2144,8 +2156,11 @@ int refs_update_symref_extended(struct ref_store *refs, const char *ref, } } + if (prepret == TRANSACTION_CREATE_EXISTS) + goto cleanup; + if (ref_transaction_commit(transaction, &err)) - ret = error("%s", err.buf); + goto error_return; cleanup: strbuf_release(&err); diff --git a/refs.h b/refs.h index b243739e4b..be38377b1f 100644 --- a/refs.h +++ b/refs.h @@ -586,7 +586,7 @@ int refs_update_symref(struct ref_store *refs, const char *refname, int refs_update_symref_extended(struct ref_store *refs, const char *refname, const char *target, const char *logmsg, - struct strbuf *referent); + struct strbuf *referent, int create_only); enum action_on_err { UPDATE_REFS_MSG_ON_ERR, From patchwork Fri Nov 22 12:28:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13883141 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 D78B5524F for ; Fri, 22 Nov 2024 12:33:22 +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=1732278805; cv=none; b=SrR2dHlzDf2bnt2qJDaHfaKVDcqV6s8A9jyFJb3EvEWbdj+TPfyaoQdgoUrr2H1x0zia1BN7f5KZAbsNprUPTo+PTeJSluknI19Z9lx/iPuE3m0XismDh4A0ksWACAIy8eAY7ceF8XSDRTcrDcZxrrQc453/vtMmxOiSVw07jI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278805; c=relaxed/simple; bh=wWW6zxMezTlV8Jba6GMreKWz+K7YBWgvNRNCQ1VRWQo=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=SfTQrmVkavzWs/5E8hB7OQKrvVbAfVf/PmN84jw1srRrYqxG8j+UxMTL/NbU9zKV8WZ4EF2jmvoGgx6wnQP+Nlzxwss4FOv2b7rKkG451VLEmMTBUHu0cgzD+wW5L3rCJaJJaMPmKEVQXfSF9aBTlimEzZ/uTejW/KHwo4Rug18= 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=nyhOr0Ns; 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="nyhOr0Ns" 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=kcPrBHe/NoT5HLaSM5qkxeKZ+lgGXDN372LH0LifvyQ=; b=nyhOr0Nsq1yQ0wLdnyEU11QJdZ5rciwjtLd3zzRaPMUOCfzdDq/2+udsIHNn+f6cAlqPCOVRS6Wu hSbj9hRVcvwB+/3HEngMCdY4DIIel1/yXEcD9yw4DDrq+E+xm9kOioWKXrb/BJwpMguP4IeNFJrp HyMzZ75uhWMCcoOXFTgyx9CSt1AzYsmRXww4RwKW7L53dap+s2UAH3qNR0ssLKGMa+BaeLoUm8HI i+QmU5u4m8eBgv8060joXPNto82K4nYXpTQ0t/6rWHYvYyYW1+Aj/gaeiwOyGyTVViyqaQPkGSqP ARejCFkZnuH4b3w9TF+9vPcnGt5DSHL4mpJ92g== Received: by omta-ad1-fd3-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241024 64bit (built Oct 24 2024)) with ESMTPS id <0SNC00NKIQVLBTC0@omta-ad1-fd3-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Fri, 22 Nov 2024 12: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, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Bence Ferdinandy Subject: [PATCH v15 09/10] fetch: set remote/HEAD if it does not exist Date: Fri, 22 Nov 2024 13:28:50 +0100 Message-id: <20241122123138.66960-10-bence@ferdinandy.com> In-reply-to: <20241122123138.66960-1-bence@ferdinandy.com> References: <20241121225757.3877852-1-bence@ferdinandy.com> <20241122123138.66960-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: AAHPmg53zA5rWzJswmd0gUM+aW2QZ5S71jt8DkyZjMJTtCE6MlFfLVcEzwuGFcay 04gdTC0WXFhQikV0a2w+cJrH+DS0/QWikdjS8i+l0IksSL8Fn4i0S/IcfyiV2k8W 3ljGGEOmqpgGiMcLz7XBd2oX21fwcanHQztVJfZGzade7ssPdS3M7rWhBL6jddRh w9M/+7ohRofKQhHHc3B94HsLD9pyrvzc9vjENXQ1+eAOsIjzzzRpuctYvAow33qB F8IVIFk/hpcTRELTAbegbQS03oYN76yS42L4AuMm/K5f95BjKC2Ttv2UIbq2ilTP MmvVNeEGKwVok3E91QAaKwVFz23UkEcRLN+YIk03+4fUWyvBHwc8joQjHo53Yu6m SB6mDLaFWrjJxU99NCstfad4Bgd5xwQlBgeplSi6DMwdsRAq1YusgZOF/OP6eHu/ Dkww/idW1KfBfncJAdZm5g+utHicTFLX/URSIAcXjj4de27bfPNi+ue5 When cloning a repository remote/HEAD is created, but when the user creates a repository with git init, and later adds a remote, remote/HEAD is only created if the user explicitly runs a variant of "remote set-head". Attempt to set remote/HEAD during fetch, if the user does not have it already set. Silently ignore any errors. 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 v7: - no change v8: - changed logmsg in call to refs_update_symref from "remote set-head" to "fetch" v9: - follow through with refs_update_symref_extended - fix test errors uncovered by the new patch v10: no change v11: fixed some memory leaks v12: no change v13: - fix printed information if the local HEAD is detached - remove accidental formatting noise in a test v14: remove report_set_head_auto: as discussed, any noise should only be created with an opt out, and the configuration for this will be added in a later patch v15: no change builtin/fetch.c | 68 ++++++++++++++++++++++++++++++++ t/t4207-log-decoration-colors.sh | 3 +- t/t5505-remote.sh | 21 +++++++--- t/t5510-fetch.sh | 24 +++++++++++ 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, 203 insertions(+), 17 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 06b4611958..bbfaf50b63 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1574,6 +1574,66 @@ static int backfill_tags(struct display_state *display_state, return retcode; } +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; + 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) + goto cleanup; + 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; + goto cleanup; + } + if (refs_update_symref_extended(refs, b_head.buf, b_remote_head.buf, + "fetch", NULL, 1)) + result = 1; + +cleanup: + free(head_name); + free_refs(fetch_map); + free_refs(matches); + string_list_clear(&heads, 0); + strbuf_release(&b_head); + strbuf_release(&b_remote_head); + return result; +} + static int do_fetch(struct transport *transport, struct refspec *rs, const struct fetch_config *config) @@ -1643,6 +1703,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, @@ -1787,6 +1849,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 d15b579c95..afa261409f 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -74,7 +74,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 && @@ -500,7 +500,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 "${SQ}two/HEAD${SQ} is now created and points to ${SQ}main${SQ}" >expect && + echo "${SQ}two/HEAD${SQ} is unchanged and points to ${SQ}main${SQ}" >expect && test_cmp expect output ) ' @@ -788,8 +788,10 @@ test_expect_success 'reject --no-no-tags' ' ' cat >one/expect <<\EOF + apis/HEAD -> apis/main apis/main apis/side + drosophila/HEAD -> drosophila/main drosophila/another drosophila/main drosophila/side @@ -807,11 +809,14 @@ test_expect_success 'update' ' ' cat >one/expect <<\EOF + drosophila/HEAD -> drosophila/main drosophila/another drosophila/main drosophila/side + manduca/HEAD -> manduca/main manduca/main manduca/side + megaloprepus/HEAD -> megaloprepus/main megaloprepus/main megaloprepus/side EOF @@ -819,7 +824,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 && @@ -851,10 +856,13 @@ test_expect_success 'update --prune' ' ' cat >one/expect <<-\EOF + apis/HEAD -> apis/main apis/main apis/side + manduca/HEAD -> manduca/main manduca/main manduca/side + megaloprepus/HEAD -> megaloprepus/main megaloprepus/main megaloprepus/side EOF @@ -862,7 +870,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 && @@ -874,6 +882,7 @@ test_expect_success 'update default' ' ' cat >one/expect <<\EOF + drosophila/HEAD -> drosophila/main drosophila/another drosophila/main drosophila/side @@ -882,7 +891,7 @@ EOF test_expect_success 'update default (overridden, with funny whitespace)' ' ( 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 && @@ -896,7 +905,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..87698341f5 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 && 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 c224c8450c..edb85b7145 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 && @@ -220,7 +221,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 c16ea67c1d..d9cb6b9a3e 100755 --- a/t/t9211-scalar-clone.sh +++ b/t/t9211-scalar-clone.sh @@ -32,7 +32,7 @@ test_expect_success 'set up repository to clone' ' ) ' -cleanup_clone () { +cleanup_clone() { rm -rf "$1" } @@ -128,7 +128,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 ) && @@ -142,7 +142,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 From patchwork Fri Nov 22 12:28:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13883140 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 A5F781DE4D4 for ; Fri, 22 Nov 2024 12:33:16 +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=1732278798; cv=none; b=mzgJSHqI7qlCaORETyxnb7e4VzA+ykjHxDK8nIlaimA3xjh+t+RFvjFJ68vZL/+GM3t04Px3moqfhcivOlsE64ZPMi5S/d5SlJvGTVdqapJbvokChfiqgOEUt5PMpcckIACFeyVldFbcoBI89fj/158xB93502WYv9aVWGc8+IE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278798; c=relaxed/simple; bh=NIzhe3GNwxA6+Bz0XXmvfKxtHdtoegtDw0FbPtrgPxs=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=MUPUVd+0OZZHDOagp067NNjipbP2QQrfccrSp4LKvyyWb7LPHFPbhabGNF6HX9FsNi+oQczbIV3ukX20wAyJgroXUxQfo+Ao4UzAGu1MBnR2oMIRSKEkYKXgTqUKD4l3A3oyz7K3RF1JA+BxVBkZGruGR8wJeHt/nchd8ghlzl4= 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=P9fU15Sp; 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="P9fU15Sp" 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=XcUBfQlZoeLA6U4LwXNxK1hrg8YgLlKQa5XU+x1Ub8A=; b=P9fU15Spd9oLYrK0CETpeMiVQwZiBFTyptofouDxuenPwswFvEaLwemxjXMTh0CBQITZh+2QNftY bwuLXzQ0sD0ggnbYEDOwZN9nEC7AhoRj9d3nDTQAe6+iVHC7VEkQ0kmrH8gzjCvufGi/SdEtKtzw pd9Akncu1ysMbt0l2Vka6gyql2Ah7dfynO/G8Suy8w8WGZepaPILQmYLTHbXU488R/PP4HxDY7u5 Vd5A+R2FhnMbcsDV5tXBHOckwUE9cgoCSb5dr6sJaKTGjEfDQrGnK1zL8xqV3Iu+/jcKIWYa+vGQ /kHhOK7ouLVw6uar5Bzq5+ayGybfOFDAgW5gRw== Received: by omta-ad1-fd2-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241024 64bit (built Oct 24 2024)) with ESMTPS id <0SNC00FQYQVFVB90@omta-ad1-fd2-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Fri, 22 Nov 2024 12:33:15 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Junio C Hamano , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Bence Ferdinandy Subject: [PATCH v15 10/10] fetch set_head: handle mirrored bare repositories Date: Fri, 22 Nov 2024 13:28:51 +0100 Message-id: <20241122123138.66960-11-bence@ferdinandy.com> In-reply-to: <20241122123138.66960-1-bence@ferdinandy.com> References: <20241121225757.3877852-1-bence@ferdinandy.com> <20241122123138.66960-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: AAG/BPE2Gx8pkLvG8hopB4zX7FvKjrqK44Vl5GFUxSCbTi05zQ93/fmccNGAJtv9 Ul6VMUbN6v80/W7C6h5nX+CTQkZJwKy9KOWZK3z2POyo1gmkj1TWhvpDr45n8J9E Fz8Lo1Z+0bNu20pt5kR6Yirqg5uyqnnM0GQKIf3iiRvTkDj/dePP5ToPVX07zqwD Oun5K74/46SvsJ/pj4TtUr5072ANTtfc+w15zhqVEP3YF5ElTr82Vmm10yzMIz9Q Z5mgSfdqApiaq6pPsMTxNdC28GtOdWapz7n3c9lMEEADO+tRZfmgfvFZT7LsFZcD 4ePhGv2mM0eQKv3uxC/w6ompfdNwo8zf0WpFXfEIhtv961LAkuYSMTOMmclNVhfa mBsW5wdUYmOHr8xhdGbZKirQZh6GiGf+78UXZBYPF+hLesi8yVIaNgZ045T5tESV Fh+XsZOMYaBqDlfToBMTfZv8d7UtLO+MAR/7WwJzmy2kdUAnL6tvl0zG When adding a remote to bare repository with "git remote add --mirror", running fetch will fail to update HEAD to the remote's HEAD, since it does not know how to handle bare repositories. On the other hand HEAD already has content, since "git init --bare" has already set HEAD to whatever is the default branch set for the user. Unless this - by chance - is the same as the remote's HEAD, HEAD will be pointing to a bad symref. Teach set_head to handle bare repositories, by overwriting HEAD so it mirrors the remote's HEAD. Note, that in this case overriding the local HEAD reference is necessary, since HEAD will exist before fetch can be run, but this should not be an issue, since the whole purpose of --mirror is to be an exact mirror of the remote, so following any changes to HEAD makes sense. Also note, that although "git remote set-head" also fails when trying to update the remote's locally tracked HEAD in a mirrored bare repository, the usage of the command does not make much sense after this patch: fetch will update the remote HEAD correctly, and setting it manually to something else is antithetical to the concept of mirroring. Signed-off-by: Bence Ferdinandy --- Notes: state: * last review: none v10: - new patch - handles the issue discovered in https://lore.kernel.org/git/D4ZAELFWJMKN.S88LJ6YK31LZ@ferdinandy.com/T/ v11: no change v12: no change v13: properly print the previous head if it was detached v14: no change v15: no change builtin/fetch.c | 16 +++++++++++----- t/t5505-remote.sh | 10 ++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index bbfaf50b63..2f416cf867 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1581,7 +1581,7 @@ static const char *strip_refshead(const char *name){ static int set_head(const struct ref *remote_refs) { - int result = 0; + int result = 0, is_bare; struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT; const char *remote = gtransport->remote->name; char *head_name = NULL; @@ -1613,15 +1613,21 @@ static int set_head(const struct ref *remote_refs) if (!head_name) goto cleanup; - strbuf_addf(&b_head, "refs/remotes/%s/HEAD", remote); - strbuf_addf(&b_remote_head, "refs/remotes/%s/%s", remote, head_name); + is_bare = is_bare_repository(); + if (is_bare) { + strbuf_addstr(&b_head, "HEAD"); + strbuf_addf(&b_remote_head, "refs/heads/%s", head_name); + } else { + 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)) { + if (!is_bare && !refs_ref_exists(refs, b_remote_head.buf)) { result = 1; goto cleanup; } if (refs_update_symref_extended(refs, b_head.buf, b_remote_head.buf, - "fetch", NULL, 1)) + "fetch", NULL, !is_bare)) result = 1; cleanup: diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index afa261409f..2600add82a 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -569,6 +569,16 @@ test_expect_success 'add --mirror && prune' ' ) ' +test_expect_success 'add --mirror setting HEAD' ' + mkdir headmirror && + ( + cd headmirror && + git init --bare -b notmain && + git remote add --mirror -f origin ../one && + test "$(git symbolic-ref HEAD)" = "refs/heads/main" + ) +' + test_expect_success 'add --mirror=fetch' ' mkdir mirror-fetch && git init -b main mirror-fetch/parent &&