From patchwork Tue Nov 21 20:32:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jan Alexander Steffens (heftig)" X-Patchwork-Id: 13463553 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="kQz6L6fc"; dkim=permerror (0-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="8QqIaGc5" Received: from mail.archlinux.org (mail.archlinux.org [95.216.189.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A598DD40 for ; Tue, 21 Nov 2023 12:34:23 -0800 (PST) From: "Jan Alexander Steffens (heftig)" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-rsa; t=1700598859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E1RAGbdjtZ6Mbu0Oh8J4tiEHZ9glLzoef79C0N33Vdw=; b=kQz6L6fc9/HdBQGFGl9y2EMPDT1Hgl4RULUSWZR8AV7bfHV9gYj1yDH10XvfVX99XsKvte NG4wA8Y/M6aNYmIPp/N9XZQvGSvsPn2lARiPVdw4qGMXh6Vc3gRFFY8qKfnjMWu4l0XYOE H3Qg2oIyPUQ6kEqMAdN5v6ntDv9ouYEh29y98/jlld3B9ULP/AfPEMl7o0pxXyJyprCClP tGbX8AMzbL4MG5vHqCOhc9WrEpp5a7EcFyVFdI5/9nx76iLAZUF0VMYWMsfR5LQU2WbF/O GTPsFsTZO0K0QL+YJlAY72NSsO7O0Z8nJUk7Z4FLuRMXU3ScNxzrOq9AVuVKvKRezVc56+ oJRThVLAwvNnPOlDe4sehjTL0QvDkF51+xg+A4A1waUVPE5d1Ko68kKEvibdTDP3PtIclB TexjD4G0DAw4QKZZF200VWWr0GHiR3tNxRMG0EYA+qGxRkGqpZWgGlXtpO1OptOcUz8A0y q99rODt/W7/uIpMFD2LgDYXCu/+/TtQOjiz4kZNocC01UYIPEyudoMNtOFDnnO6pS1F0k3 fL90lNByNV6IV64Prl/Q6F1scMX7uu1sDHcDRk+lC8EFYcoZkSwTJYPXSl5/C3AgeoL8vu WXV4+r3NUG9qaPx1hHP6BI+Pma124LVlYvK5OQWnq3fAvk4hR2o58= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-ed25519; t=1700598859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E1RAGbdjtZ6Mbu0Oh8J4tiEHZ9glLzoef79C0N33Vdw=; b=8QqIaGc5A8Mxfh5Ftn9+EPiQUNs2QLehwrDa2Hkd/L67dqaDAR7t0N/lEi0mwPdXKGBgIi g9kI9x5JPuiJeABg== Authentication-Results: mail.archlinux.org; auth=pass smtp.auth=heftig smtp.mailfrom=heftig@archlinux.org To: git@vger.kernel.org Cc: Junio C Hamano , Shourya Shukla , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , Denton Liu , "Jan Alexander Steffens (heftig)" Subject: [PATCH v2 1/6] submodule--helper: use submodule_from_path in set-{url,branch} Date: Tue, 21 Nov 2023 21:32:42 +0100 Message-ID: <20231121203413.176414-1-heftig@archlinux.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231003185047.2697995-1-heftig@archlinux.org> References: <20231003185047.2697995-1-heftig@archlinux.org> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The commands need a path to a submodule but treated it as the name when modifying the .gitmodules file, leading to confusion when a submodule's name does not match its path. Because calling submodule_from_path initializes the submodule cache, we need to manually trigger a reread before syncing, as the cache is missing the config change we just made. Signed-off-by: Jan Alexander Steffens (heftig) --- Notes: v2 changes: - fixed code style - replaced potentially unsafe use of `sub->path` with `path` builtin/submodule--helper.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 6f3bf33e61..af461ada8b 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2901,19 +2901,26 @@ static int module_set_url(int argc, const char **argv, const char *prefix) N_("git submodule set-url [--quiet] "), NULL }; + const struct submodule *sub; argc = parse_options(argc, argv, prefix, options, usage, 0); if (argc != 2 || !(path = argv[0]) || !(newurl = argv[1])) usage_with_options(usage, options); - config_name = xstrfmt("submodule.%s.url", path); + sub = submodule_from_path(the_repository, null_oid(), path); + if (!sub) + die(_("no submodule mapping found in .gitmodules for path '%s'"), + path); + + config_name = xstrfmt("submodule.%s.url", sub->name); config_set_in_gitmodules_file_gently(config_name, newurl); + + repo_read_gitmodules(the_repository, 0); sync_submodule(path, prefix, NULL, quiet ? OPT_QUIET : 0); free(config_name); - return 0; } @@ -2941,19 +2948,26 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) N_("git submodule set-branch [-q|--quiet] (-b|--branch) "), NULL }; + const struct submodule *sub; argc = parse_options(argc, argv, prefix, options, usage, 0); if (!opt_branch && !opt_default) die(_("--branch or --default required")); if (opt_branch && opt_default) die(_("options '%s' and '%s' cannot be used together"), "--branch", "--default"); if (argc != 1 || !(path = argv[0])) usage_with_options(usage, options); - config_name = xstrfmt("submodule.%s.branch", path); + sub = submodule_from_path(the_repository, null_oid(), path); + + if (!sub) + die(_("no submodule mapping found in .gitmodules for path '%s'"), + path); + + config_name = xstrfmt("submodule.%s.branch", sub->name); ret = config_set_in_gitmodules_file_gently(config_name, opt_branch); free(config_name); From patchwork Tue Nov 21 20:32:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jan Alexander Steffens (heftig)" X-Patchwork-Id: 13463554 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="REf2aalL"; dkim=permerror (0-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="PiD9+lpr" Received: from mail.archlinux.org (mail.archlinux.org [95.216.189.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A57AC1BC for ; Tue, 21 Nov 2023 12:34:23 -0800 (PST) From: "Jan Alexander Steffens (heftig)" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-rsa; t=1700598860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7jrCb8GTiQSGTaURsn+6LoQdF62l1/aJQJPfzMM80Wg=; b=REf2aalL/ArjYAzPydFryPUdfGZTP/JlJ68wjQDTtecd7Dax8hOMhX0pXkMSEYaKEHjkAk ob3pmphYkEsqfD8uBp4IP3TrH+Cwk6SGW/wIG3+y0d1YS56uPSC3Ll34X/zHsHnCQp8L6v KSJAzs5978aemfrg01BxFPdCtdYBOnu17hQaWxwpcPL8OMjmcqub+XA1danKreksKIaNEe yWtsYDuOVAHjrEllJbmF3lZ9Ie6M8z5d5gvidsn2KtJd250/t3td+kgeFG5XI+lfaCA+0q mjc/HLdq1piLsyNtnBMkRey7pi5td+2C7mdXVoawU1rNl2TomFfBUg70t6k4TGH3685NL6 DpjG5PijY1LV69qxjybA8LPO0b01rPejSJQpmT5Q+nfVvqcXW5XTPM8551T6Qg7HdDS5ff BapdfgE9uJLN15H4HcaWXBL5jdZxwp21zZsYGSt46cuflEovg2U3EzI2vrH8SqA3TBObti 1Q6NWB6+Fbcf1f3q6NF8EdvHBWx0q+TdPcRc+/ag0jGBrLNy1l5ElDorLn9MC3MOSowWT2 bpBApk3nOGLTuaw2o6nXHCnCkXBk3kJAfMN/Nr4k1QM4hYbCSZjEalYriOYc+4+3LhcmEn 7+TPTlhTq8YbGF7XZom+sXODSgVvxx5x3GDDdmL+h1cPAM66MiUJw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-ed25519; t=1700598860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7jrCb8GTiQSGTaURsn+6LoQdF62l1/aJQJPfzMM80Wg=; b=PiD9+lprKlWEzb1QaWcvKCi1DXdZIrWFwABT+7fe/ngIA5BVS2A5tf+Cu650nxalkuDe5N ZcKe363V1Dp/zhAg== Authentication-Results: mail.archlinux.org; auth=pass smtp.auth=heftig smtp.mailfrom=heftig@archlinux.org To: git@vger.kernel.org Cc: Junio C Hamano , Shourya Shukla , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , Denton Liu , "Jan Alexander Steffens (heftig)" Subject: [PATCH v2 2/6] submodule--helper: return error from set-url when modifying failed Date: Tue, 21 Nov 2023 21:32:43 +0100 Message-ID: <20231121203413.176414-2-heftig@archlinux.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231121203413.176414-1-heftig@archlinux.org> References: <20231003185047.2697995-1-heftig@archlinux.org> <20231121203413.176414-1-heftig@archlinux.org> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 set-branch will return an error when setting the config fails so I don't see why set-url shouldn't. Also skip the sync in this case. Signed-off-by: Jan Alexander Steffens (heftig) --- builtin/submodule--helper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index af461ada8b..0013ea1ab0 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2889,39 +2889,41 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) static int module_set_url(int argc, const char **argv, const char *prefix) { - int quiet = 0; + int quiet = 0, ret; const char *newurl; const char *path; char *config_name; struct option options[] = { OPT__QUIET(&quiet, N_("suppress output for setting url of a submodule")), OPT_END() }; const char *const usage[] = { N_("git submodule set-url [--quiet] "), NULL }; const struct submodule *sub; argc = parse_options(argc, argv, prefix, options, usage, 0); if (argc != 2 || !(path = argv[0]) || !(newurl = argv[1])) usage_with_options(usage, options); sub = submodule_from_path(the_repository, null_oid(), path); if (!sub) die(_("no submodule mapping found in .gitmodules for path '%s'"), path); config_name = xstrfmt("submodule.%s.url", sub->name); - config_set_in_gitmodules_file_gently(config_name, newurl); + ret = config_set_in_gitmodules_file_gently(config_name, newurl); - repo_read_gitmodules(the_repository, 0); - sync_submodule(path, prefix, NULL, quiet ? OPT_QUIET : 0); + if (!ret) { + repo_read_gitmodules(the_repository, 0); + sync_submodule(path, prefix, NULL, quiet ? OPT_QUIET : 0); + } free(config_name); - return 0; + return !!ret; } static int module_set_branch(int argc, const char **argv, const char *prefix) From patchwork Tue Nov 21 20:32:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jan Alexander Steffens (heftig)" X-Patchwork-Id: 13463556 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="GIVCTEjW"; dkim=permerror (0-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="Z0cWSU3p" Received: from mail.archlinux.org (mail.archlinux.org [95.216.189.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5ACED45 for ; Tue, 21 Nov 2023 12:34:23 -0800 (PST) From: "Jan Alexander Steffens (heftig)" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-rsa; t=1700598861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ogQdB7OZeVYFTrNMmrWnV7LdvywP2myruO1FDxORTCU=; b=GIVCTEjWO3mj0Bc203Fn4t8Nmk/3HMaM3KoP0OUdTY/4o2CaJMETdmDdsqztdntTFiDo41 OD8HKWGADuB5dCv/J5d4aoR89KOBRz+qI9WAchVQcNhaZtF/nlgMJS80ZK5o3vMojlt362 s81A3IL+BX45a/TOYBkkRRAwNS5T9kX9wGUWEWmNRqcE23+J4g3fFyrjx6wtWDAclobg/s Cga+NXzdKaeMFk6eGEH68J0MDP+gPtN8urTFxDUe5szTXeEKI7hPJPazoGakVH+LFZPX4q ODqPCUJ+QHewK8bnrPphWbycileLZxxCebkYyswdsazFMIl1oppRZTnJwQASmDFr3kwltd lu1xs2/ajepNj0ygjYSAFhsGy54vzhdsP9enaKLgzNhRYjzm2DoFg3k5uabEmktK1ysAep MjcrqomhQNQzrPcYykaw5fFAbxZpUIZHjsFBdpP3m8LpwDs8yNytWkSvwnAuCiv8+zm/3a m1SUoRQceShd4tlKjfnrZLEJb1BDP4hNt8z4/tWE26lzjM1vmavK4G1St4U2XNidvpb00R +nTHpE7cjkve92iupEIxm2vLVkRY+B+SwPeo7cPGi/ZkXcTbw3XcVv0GHEcbVIbQ04XRuU +9FM3g6l1a7BsPRbSXzZlpVfM8uuosXhUzNuNAZYzfnUOqgPPk4kY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-ed25519; t=1700598861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ogQdB7OZeVYFTrNMmrWnV7LdvywP2myruO1FDxORTCU=; b=Z0cWSU3pOmftOdZU0K4DMyt2yQjHVrlKDyAidvuSswVcQXqF97nVs+t9NQRwTHrYrgUzEO wiOvUv7gNzMVBSAg== Authentication-Results: mail.archlinux.org; auth=pass smtp.auth=heftig smtp.mailfrom=heftig@archlinux.org To: git@vger.kernel.org Cc: Junio C Hamano , Shourya Shukla , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , Denton Liu , "Jan Alexander Steffens (heftig)" Subject: [PATCH v2 3/6] t7419: actually test the branch switching Date: Tue, 21 Nov 2023 21:32:44 +0100 Message-ID: <20231121203413.176414-3-heftig@archlinux.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231121203413.176414-1-heftig@archlinux.org> References: <20231003185047.2697995-1-heftig@archlinux.org> <20231121203413.176414-1-heftig@archlinux.org> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The submodule repo the test set up had the 'topic' branch checked out, meaning the repo's default branch (HEAD) is the 'topic' branch. The following tests then pretended to switch between the default branch and the 'topic' branch. This was papered over by continually adding commits to the 'topic' branch and checking if the submodule gets updated to this new commit. Return the submodule repo to the 'main' branch after setup so we can actually test the switching behavior. Signed-off-by: Jan Alexander Steffens (heftig) --- Notes: v2 changes: - fixed subject t/t7419-submodule-set-branch.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/t/t7419-submodule-set-branch.sh b/t/t7419-submodule-set-branch.sh index 232065504c..5ac16d0eb7 100755 --- a/t/t7419-submodule-set-branch.sh +++ b/t/t7419-submodule-set-branch.sh @@ -11,23 +11,28 @@ as expected. TEST_PASSES_SANITIZE_LEAK=true TEST_NO_CREATE_REPO=1 + +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + . ./test-lib.sh test_expect_success 'setup' ' git config --global protocol.file.allow always ' test_expect_success 'submodule config cache setup' ' mkdir submodule && (cd submodule && git init && echo a >a && git add . && git commit -ma && git checkout -b topic && echo b >a && git add . && - git commit -mb + git commit -mb && + git checkout main ) && mkdir super && (cd super && @@ -57,41 +62,38 @@ test_expect_success 'test submodule set-branch --branch' ' ' test_expect_success 'test submodule set-branch --default' ' - test_commit -C submodule c && (cd super && git submodule set-branch --default submodule && ! grep branch .gitmodules && git submodule update --remote && cat <<-\EOF >expect && - c + a EOF git -C submodule show -s --pretty=%s >actual && test_cmp expect actual ) ' test_expect_success 'test submodule set-branch -b' ' - test_commit -C submodule b && (cd super && git submodule set-branch -b topic submodule && grep "branch = topic" .gitmodules && git submodule update --remote && cat <<-\EOF >expect && b EOF git -C submodule show -s --pretty=%s >actual && test_cmp expect actual ) ' test_expect_success 'test submodule set-branch -d' ' - test_commit -C submodule d && (cd super && git submodule set-branch -d submodule && ! grep branch .gitmodules && git submodule update --remote && cat <<-\EOF >expect && - d + a EOF git -C submodule show -s --pretty=%s >actual && test_cmp expect actual From patchwork Tue Nov 21 20:32:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jan Alexander Steffens (heftig)" X-Patchwork-Id: 13463555 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="D5QeH1om"; dkim=permerror (0-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="nfKIF2J8" Received: from mail.archlinux.org (mail.archlinux.org [95.216.189.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A497A1BB for ; Tue, 21 Nov 2023 12:34:23 -0800 (PST) From: "Jan Alexander Steffens (heftig)" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-rsa; t=1700598861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C/0cbsbQsQfiWMxFvLmpfXnoIjIAhS5qAiOzTgiyLLA=; b=D5QeH1omKZvD1kAlCMx337Q1y8xn7jkocXghUNT5jDMgyx0vfmfCvanclY0QomJPXjb4uQ uU20WPiSmJ4Opy0U9LdFSNcBFu9A/lrEh+RHs7STltwWPdEny+9kR55seUOFYGM1grBJ6s RU5Y5e5jYUOtdKxLp27Y3gxV0iSAy886VwbwUOXJhVFYz82B14/WqYpqLhbPQl7RDB+bHM eoRjw7EhIkmlDfufxJLCXNZaEbPIVpkgUUc5uZ5S/D789hzaFtAcHGcLV59BTPObXOgSo+ ObKkQtIQTnOlHaXisgSQBHMd8vwBZkxZKXTuBAlHFy/v+Tby1ISOHh5/85I4tuI+LwXNte p05Bgf0N0grDZdj4CbDrzuKUz9LFGHuaiuUxNAAufHotCg7mF+TmQM/ZjAkv1O1CzV0S/U kAQ99kh54LVfS2jhrtvsRwnGH/Tfcj3uxCiCjctb45BisAPiDIp1/l16uzP9Ai8RHr/WNn 3NPHhXuNv1THKWSCboHcYpIgXcKzedW5iGAPwv0I0u5srgasOjHw1rO9L22fCI9SEGO5Y1 ZpYkS+kQjI/H0+AlbQvAgV3jwnxLjUBZPJBzkTqIOcJ8P8yMifN5GQdYEvQWlrP4MiYeLS nug11hM0pGWPGsUVNGEAHQDq71H+Nc7U1PtbMhnu4Pd87DM3mikuA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-ed25519; t=1700598861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C/0cbsbQsQfiWMxFvLmpfXnoIjIAhS5qAiOzTgiyLLA=; b=nfKIF2J8o5f6y9YiYwz4TrPTf5BNoDupys6vO4D3Wo0J8jn8bM7xOxtjERHVhPCtuDwW+s tJhyJEt8tKi99YAQ== Authentication-Results: mail.archlinux.org; auth=pass smtp.auth=heftig smtp.mailfrom=heftig@archlinux.org To: git@vger.kernel.org Cc: Junio C Hamano , Shourya Shukla , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , Denton Liu , "Jan Alexander Steffens (heftig)" Subject: [PATCH v2 4/6] t7419, t7420: use test_cmp_config instead of grepping .gitmodules Date: Tue, 21 Nov 2023 21:32:45 +0100 Message-ID: <20231121203413.176414-4-heftig@archlinux.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231121203413.176414-1-heftig@archlinux.org> References: <20231003185047.2697995-1-heftig@archlinux.org> <20231121203413.176414-1-heftig@archlinux.org> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have a test function to verify config files. Use it as it's more precise. Signed-off-by: Jan Alexander Steffens (heftig) --- t/t7419-submodule-set-branch.sh | 10 +++++----- t/t7420-submodule-set-url.sh | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/t/t7419-submodule-set-branch.sh b/t/t7419-submodule-set-branch.sh index 5ac16d0eb7..3cd30865a7 100755 --- a/t/t7419-submodule-set-branch.sh +++ b/t/t7419-submodule-set-branch.sh @@ -44,53 +44,53 @@ test_expect_success 'submodule config cache setup' ' test_expect_success 'ensure submodule branch is unset' ' (cd super && - ! grep branch .gitmodules + test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch ) ' test_expect_success 'test submodule set-branch --branch' ' (cd super && git submodule set-branch --branch topic submodule && - grep "branch = topic" .gitmodules && + test_cmp_config topic -f .gitmodules submodule.submodule.branch && git submodule update --remote && cat <<-\EOF >expect && b EOF git -C submodule show -s --pretty=%s >actual && test_cmp expect actual ) ' test_expect_success 'test submodule set-branch --default' ' (cd super && git submodule set-branch --default submodule && - ! grep branch .gitmodules && + test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch && git submodule update --remote && cat <<-\EOF >expect && a EOF git -C submodule show -s --pretty=%s >actual && test_cmp expect actual ) ' test_expect_success 'test submodule set-branch -b' ' (cd super && git submodule set-branch -b topic submodule && - grep "branch = topic" .gitmodules && + test_cmp_config topic -f .gitmodules submodule.submodule.branch && git submodule update --remote && cat <<-\EOF >expect && b EOF git -C submodule show -s --pretty=%s >actual && test_cmp expect actual ) ' test_expect_success 'test submodule set-branch -d' ' (cd super && git submodule set-branch -d submodule && - ! grep branch .gitmodules && + test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch && git submodule update --remote && cat <<-\EOF >expect && a diff --git a/t/t7420-submodule-set-url.sh b/t/t7420-submodule-set-url.sh index d6bf62b3ac..aa63d806fe 100755 --- a/t/t7420-submodule-set-url.sh +++ b/t/t7420-submodule-set-url.sh @@ -49,7 +49,7 @@ test_expect_success 'test submodule set-url' ' cd super && test_must_fail git submodule update --remote && git submodule set-url submodule ../newsubmodule && - grep -F "url = ../newsubmodule" .gitmodules && + test_cmp_config ../newsubmodule -f .gitmodules submodule.submodule.url && git submodule update --remote ) && git -C super/submodule show >actual && From patchwork Tue Nov 21 20:32:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jan Alexander Steffens (heftig)" X-Patchwork-Id: 13463557 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="ADjwBe0u"; dkim=permerror (0-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="5ppAOcjC" Received: from mail.archlinux.org (mail.archlinux.org [95.216.189.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6C6FD47 for ; Tue, 21 Nov 2023 12:34:23 -0800 (PST) From: "Jan Alexander Steffens (heftig)" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-rsa; t=1700598862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wBM3pheqAfvIwZ94WX+6jcakvF1IDMrEpgtOY6z9ixQ=; b=ADjwBe0u1pXxp71tID5qcHh4sjigf/zT0vpv+CVeG8gplAFYxB96mIC1R2Uap8lsAkujqc OC2O0HIHGk6O2r8JaOzAXCieFwDoH3QR7Inh5Om322vc9QuTna2ffBbj6l3XsRZhysmGdp JG6ft0tJBgvjqiUFoUh03RgH7D/ZSgZ3EbBjKS7F/4FOcQ0QE9AutiEaS05AKLwlVTS6Ld 5BBfs6jvOo5dO2wOkP45C7b4TlPcHrF9ttcMnbiMnHoNQvjd7cmmBNmT2jCX6iPxOi5gg+ YioeXBHCA9xGcdhjMIH+V9Cqu/z/XKU5mtiYtv7PtTZbSwQDR98YiTjoanNQbvbhdjXE1A MAC4oYj4ESs3rpFqNf/3kbo4SOwcCuHbDG7O8nmZXKrURpwpVfEPQ9RS87b3dpieImc0r/ EnaOhn/B1Sg7yDhyirmEzU2asMkoiOo8M9w/6027ofGb3zZt+8PNAt5ejzK1zuneuRwLD+ jgTUDvusEXMOQDvkMyYYrbzd8a3ANX2UIW3SDpqWxTetdlhIQEurBsftKqPlE6wAU0LDdJ JEpyLS49Xdjenjcw3C1ozpnJuAycHq9Mz28LtHuXefzGgyZTNLxGthmTDE+d270RQ5ACRx CGKqUMjnKjZW48PjHPawCxIsmfNOqMvlWQxY75Jbluu+y3PRI8J50= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-ed25519; t=1700598862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wBM3pheqAfvIwZ94WX+6jcakvF1IDMrEpgtOY6z9ixQ=; b=5ppAOcjCB45A+KF6ZcAxsKkAtWtewq1vaxeMXVOzBfof0wGtsnrnDTxdxE2hq/aKTR9kV2 kFzj+D9wR/aFaTCA== Authentication-Results: mail.archlinux.org; auth=pass smtp.auth=heftig smtp.mailfrom=heftig@archlinux.org To: git@vger.kernel.org Cc: Junio C Hamano , Shourya Shukla , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , Denton Liu , "Jan Alexander Steffens (heftig)" Subject: [PATCH v2 5/6] t7419: test that we correctly handle renamed submodules Date: Tue, 21 Nov 2023 21:32:46 +0100 Message-ID: <20231121203413.176414-5-heftig@archlinux.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231121203413.176414-1-heftig@archlinux.org> References: <20231003185047.2697995-1-heftig@archlinux.org> <20231121203413.176414-1-heftig@archlinux.org> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the submodule again with an explicitly different name and path. Test that calling set-branch modifies the correct .gitmodules entries. Make sure we don't create a section named after the path instead of the name. Signed-off-by: Jan Alexander Steffens (heftig) --- t/t7419-submodule-set-branch.sh | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/t/t7419-submodule-set-branch.sh b/t/t7419-submodule-set-branch.sh index 3cd30865a7..a5d1bc5c54 100755 --- a/t/t7419-submodule-set-branch.sh +++ b/t/t7419-submodule-set-branch.sh @@ -38,7 +38,8 @@ test_expect_success 'submodule config cache setup' ' (cd super && git init && git submodule add ../submodule && - git commit -m "add submodule" + git submodule add --name thename ../submodule thepath && + git commit -m "add submodules" ) ' @@ -100,4 +101,31 @@ test_expect_success 'test submodule set-branch -d' ' ) ' +test_expect_success 'test submodule set-branch --branch with named submodule' ' + (cd super && + git submodule set-branch --branch topic thepath && + test_cmp_config topic -f .gitmodules submodule.thename.branch && + test_cmp_config "" -f .gitmodules --default "" submodule.thepath.branch && + git submodule update --remote && + cat <<-\EOF >expect && + b + EOF + git -C thepath show -s --pretty=%s >actual && + test_cmp expect actual + ) +' + +test_expect_success 'test submodule set-branch --default with named submodule' ' + (cd super && + git submodule set-branch --default thepath && + test_cmp_config "" -f .gitmodules --default "" submodule.thename.branch && + git submodule update --remote && + cat <<-\EOF >expect && + a + EOF + git -C thepath show -s --pretty=%s >actual && + test_cmp expect actual + ) +' + test_done From patchwork Tue Nov 21 20:32:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jan Alexander Steffens (heftig)" X-Patchwork-Id: 13463558 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="ZNt06AWC"; dkim=permerror (0-bit key) header.d=archlinux.org header.i=@archlinux.org header.b="ex/Yi4Sh" Received: from mail.archlinux.org (mail.archlinux.org [95.216.189.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B48971A3 for ; Tue, 21 Nov 2023 12:34:26 -0800 (PST) From: "Jan Alexander Steffens (heftig)" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-rsa; t=1700598862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U17eXxRTr7NJp7PzSMwWnoxspEkh00JPf6CNEyYFse4=; b=ZNt06AWC6YIomO8EFAmEqdZiTLJenr8aPG+id1WvWIh5xhRIKcuxwkmw5zAOtfbo8ocQmX p76f8lC5aoDDZh8/sKbDWkx7AbBq1wDMYdpGVZGzJQvGoN8ndqOsgrx/v2WXYgS4on4qBS BbKsNTa+DDj7FGjBJwYLza715QCUY3t/SDaQrfng2SgC6oXurnuDL0fVLl6beV7cpNVGCn WIZ06ypHwVkCkHi5Ed2/GSVgZTt16JZUq1Wl+JgZQRUpi7nf7Q1dSswTxqAJch2HA0IEbl sCDizcAncmTeFbBfq4apTP93cnkeCdvTjNG4G5GcHgVPX5uXraLq6ic/QkqvMStnGWOi+1 X3sgBbOz3cYpV7nzwf6ijjPDff4yXPOV1Y4nXlojTEhgFu1RKKY/Fw2hH4k3Uql7vXYJ0+ NqRHe5xPWbBPguoEWZyNw/SNjfi4YOiTNrpk6rw6i8C18ce1L2TS/mrJ8Jb6fwenfNXbzi 9dbU9SlhdxQo5KnsEZizfgIn7F+6CcVJbFIuuTvwM9g9wEef/5QXCrLjPUcqKDMvQDGIbO SoTlgLqjWVfb2y4UYt0MsKPXOxSRZL+HtbxlhyTrjh4k84Qt5bd0psDHemacRBXiAMDIkV P/FaNoXi6SOCkd7nsJUe56bJGeZdkLqieCyxAh9cLOAoEMSsyBpiw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=archlinux.org; s=dkim-ed25519; t=1700598862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U17eXxRTr7NJp7PzSMwWnoxspEkh00JPf6CNEyYFse4=; b=ex/Yi4ShWPrHjw3Scqbs+ImlqFdaV/wkY/qJj6dLCf6geau2sPMovYnv586hGUadpxPvHp dGe5Dpnf7R402XDA== Authentication-Results: mail.archlinux.org; auth=pass smtp.auth=heftig smtp.mailfrom=heftig@archlinux.org To: git@vger.kernel.org Cc: Junio C Hamano , Shourya Shukla , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , Denton Liu , "Jan Alexander Steffens (heftig)" Subject: [PATCH v2 6/6] t7420: test that we correctly handle renamed submodules Date: Tue, 21 Nov 2023 21:32:47 +0100 Message-ID: <20231121203413.176414-6-heftig@archlinux.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231121203413.176414-1-heftig@archlinux.org> References: <20231003185047.2697995-1-heftig@archlinux.org> <20231121203413.176414-1-heftig@archlinux.org> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Create a second submodule with a name that differs from its path. Test that calling set-url modifies the correct .gitmodules entries. Make sure we don't create a section named after the path instead of the name. Signed-off-by: Jan Alexander Steffens (heftig) --- t/t7420-submodule-set-url.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/t/t7420-submodule-set-url.sh b/t/t7420-submodule-set-url.sh index aa63d806fe..bf7f15ee79 100755 --- a/t/t7420-submodule-set-url.sh +++ b/t/t7420-submodule-set-url.sh @@ -25,34 +25,56 @@ test_expect_success 'submodule config cache setup' ' git add file && git commit -ma ) && + mkdir namedsubmodule && + ( + cd namedsubmodule && + git init && + echo 1 >file && + git add file && + git commit -m1 + ) && mkdir super && ( cd super && git init && git submodule add ../submodule && - git commit -m "add submodule" + git submodule add --name thename ../namedsubmodule thepath && + git commit -m "add submodules" ) ' test_expect_success 'test submodule set-url' ' - # add a commit and move the submodule (change the url) + # add commits and move the submodules (change the urls) ( cd submodule && echo b >>file && git add file && git commit -mb ) && mv submodule newsubmodule && + ( + cd namedsubmodule && + echo 2 >>file && + git add file && + git commit -m2 + ) && + mv namedsubmodule newnamedsubmodule && + git -C newsubmodule show >expect && + git -C newnamedsubmodule show >>expect && ( cd super && test_must_fail git submodule update --remote && git submodule set-url submodule ../newsubmodule && test_cmp_config ../newsubmodule -f .gitmodules submodule.submodule.url && + git submodule set-url thepath ../newnamedsubmodule && + test_cmp_config ../newnamedsubmodule -f .gitmodules submodule.thename.url && + test_cmp_config "" -f .gitmodules --default "" submodule.thepath.url && git submodule update --remote ) && git -C super/submodule show >actual && + git -C super/thepath show >>actual && test_cmp expect actual '