From patchwork Fri Apr 23 19:42:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55F5FC433B4 for ; Fri, 23 Apr 2021 19:42:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 344B36113B for ; Fri, 23 Apr 2021 19:42:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232211AbhDWTnT (ORCPT ); Fri, 23 Apr 2021 15:43:19 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35084 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbhDWTnT (ORCPT ); Fri, 23 Apr 2021 15:43:19 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 2F7FC80591; Fri, 23 Apr 2021 15:42:42 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 01/30] .gitignore: Ignore /git-subtree Date: Fri, 23 Apr 2021 13:42:01 -0600 Message-Id: <20210423194230.1388945-2-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Running `make -C contrib/subtree/ test` creates a `git-subtree` executable in the root of the repo. Add it to the .gitignore so that anyone hacking on subtree won't have to deal with that noise. Signed-off-by: Luke Shumaker --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3dcdb6bb5a..a203678e9e 100644 --- a/.gitignore +++ b/.gitignore @@ -162,6 +162,7 @@ /git-stripspace /git-submodule /git-submodule--helper +/git-subtree /git-svn /git-switch /git-symbolic-ref From patchwork Fri Apr 23 19:42:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6182BC43461 for ; Fri, 23 Apr 2021 19:42:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 416F8613C3 for ; Fri, 23 Apr 2021 19:42:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232378AbhDWTnU (ORCPT ); Fri, 23 Apr 2021 15:43:20 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35110 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbhDWTnU (ORCPT ); Fri, 23 Apr 2021 15:43:20 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 035C980592; Fri, 23 Apr 2021 15:42:42 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 02/30] subtree: t7900: update for having the default branch name be 'main' Date: Fri, 23 Apr 2021 13:42:02 -0600 Message-Id: <20210423194230.1388945-3-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Most of the tests had been converted to support `GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main`, but `contrib/subtree/t/` hadn't. Convert it. Most of the mentions of 'master' can just be replaced with 'HEAD'. Signed-off-by: Luke Shumaker --- contrib/subtree/t/t7900-subtree.sh | 117 +++++++++++++++-------------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 57ff4b25c1..4b982e6c2e 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -103,7 +103,7 @@ test_expect_success 'no merge from non-existent subtree' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD ) ' @@ -116,8 +116,8 @@ test_expect_success 'no pull from non-existent subtree' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && - test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" master + git fetch ./"sub proj" HEAD && + test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD )' next_test @@ -128,7 +128,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --prefix' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && check_equal "$(last_commit_message)" "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" ) @@ -142,7 +142,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --prefix and --me test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD && check_equal "$(last_commit_message)" "Added subproject" ) @@ -156,7 +156,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --prefix as -P an test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD && check_equal "$(last_commit_message)" "Added subproject" ) @@ -170,7 +170,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --squash and --pr test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD && check_equal "$(last_commit_message)" "Added subproject with squash" ) @@ -188,13 +188,13 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count/sub proj" sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" ) @@ -208,13 +208,13 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix and - test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count/sub proj" sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD && check_equal "$(last_commit_message)" "Merged changes from subproject" ) @@ -228,13 +228,13 @@ test_expect_success 'merge new subproj history into sub dir/ with --squash and - test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count/sub proj" sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD && check_equal "$(last_commit_message)" "Merged changes from subproject using squash" ) @@ -248,7 +248,7 @@ test_expect_success 'merge the added subproj again, should do nothing' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && # this shouldn not actually do anything, since FETCH_HEAD # is already a parent @@ -265,13 +265,13 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende test_create_commit "$test_count/subproj" sub1 && ( cd "$test_count" && - git fetch ./subproj master && + git fetch ./subproj HEAD && git subtree add --prefix=subdir/ FETCH_HEAD ) && test_create_commit "$test_count/subproj" sub2 && ( cd "$test_count" && - git fetch ./subproj master && + git fetch ./subproj HEAD && git subtree merge --prefix=subdir/ FETCH_HEAD && check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" ) @@ -289,7 +289,7 @@ test_expect_success 'split requires option --prefix' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && echo "You must provide the --prefix option." > expected && test_must_fail git subtree split > actual 2>&1 && @@ -309,7 +309,7 @@ test_expect_success 'split requires path given by option --prefix must exist' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected && test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 && @@ -329,7 +329,7 @@ test_expect_success 'split sub dir/ with --rejoin' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -338,7 +338,7 @@ test_expect_success 'split sub dir/ with --rejoin' ' test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && git subtree split --prefix="sub dir" --annotate="*" --rejoin && @@ -370,7 +370,7 @@ test_expect_success 'split sub dir/ with --rejoin and --message' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -379,7 +379,7 @@ test_expect_success 'split sub dir/ with --rejoin and --message' ' test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin && check_equal "$(last_commit_message)" "Split & rejoin" @@ -394,7 +394,7 @@ test_expect_success 'split "sub dir"/ with --branch' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -403,7 +403,7 @@ test_expect_success 'split "sub dir"/ with --branch' ' test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && @@ -419,7 +419,7 @@ test_expect_success 'check hash of split' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -428,7 +428,7 @@ test_expect_success 'check hash of split' ' test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && @@ -451,7 +451,7 @@ test_expect_success 'split "sub dir"/ with --branch for an existing branch' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git branch subproj-br FETCH_HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && @@ -461,7 +461,7 @@ test_expect_success 'split "sub dir"/ with --branch for an existing branch' ' test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && @@ -478,7 +478,7 @@ test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' ( cd "$subtree_test_count" && git branch init HEAD && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -487,7 +487,7 @@ test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && test_must_fail git subtree split --prefix="sub dir" --branch init ) @@ -505,7 +505,7 @@ test_expect_success 'make sure exactly the right set of files ends up in the sub test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -514,7 +514,7 @@ test_expect_success 'make sure exactly the right set of files ends up in the sub test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && @@ -555,7 +555,7 @@ test_expect_success 'make sure the subproj *only* contains commits that affect t test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -564,7 +564,7 @@ test_expect_success 'make sure the subproj *only* contains commits that affect t test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && @@ -606,7 +606,7 @@ test_expect_success 'make sure exactly the right set of files ends up in the mai test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -615,7 +615,7 @@ test_expect_success 'make sure exactly the right set of files ends up in the mai test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && @@ -643,7 +643,7 @@ test_expect_success 'make sure exactly the right set of files ends up in the mai ) && ( cd "$subtree_test_count" && - git subtree pull --prefix="sub dir" ./"sub proj" master && + git subtree pull --prefix="sub dir" ./"sub proj" HEAD && test_write_lines main1 main2 >chkm && test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms && @@ -666,7 +666,7 @@ test_expect_success 'make sure each filename changed exactly once in the entire ( cd "$subtree_test_count" && git config log.date relative && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -675,7 +675,7 @@ test_expect_success 'make sure each filename changed exactly once in the entire test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && @@ -703,7 +703,7 @@ test_expect_success 'make sure each filename changed exactly once in the entire ) && ( cd "$subtree_test_count" && - git subtree pull --prefix="sub dir" ./"sub proj" master && + git subtree pull --prefix="sub dir" ./"sub proj" HEAD && test_write_lines main1 main2 >chkm && test_write_lines sub1 sub2 sub3 sub4 >chks && @@ -731,7 +731,7 @@ test_expect_success 'make sure the --rejoin commits never make it into subproj' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -740,7 +740,7 @@ test_expect_success 'make sure the --rejoin commits never make it into subproj' test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && @@ -768,7 +768,7 @@ test_expect_success 'make sure the --rejoin commits never make it into subproj' ) && ( cd "$subtree_test_count" && - git subtree pull --prefix="sub dir" ./"sub proj" master && + git subtree pull --prefix="sub dir" ./"sub proj" HEAD && check_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" "" ) ' @@ -781,7 +781,7 @@ test_expect_success 'make sure no "git subtree" tagged commits make it into subp test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -790,7 +790,7 @@ test_expect_success 'make sure no "git subtree" tagged commits make it into subp test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && @@ -818,7 +818,7 @@ test_expect_success 'make sure no "git subtree" tagged commits make it into subp ) && ( cd "$subtree_test_count" && - git subtree pull --prefix="sub dir" ./"sub proj" master && + git subtree pull --prefix="sub dir" ./"sub proj" HEAD && # They are meaningless to subproj since one side of the merge refers to the mainline check_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" "" @@ -837,13 +837,13 @@ test_expect_success 'make sure "git subtree split" find the correct parent' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count/sub proj" sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git branch subproj-ref FETCH_HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD ) && @@ -853,7 +853,7 @@ test_expect_success 'make sure "git subtree split" find the correct parent' ' git subtree split --prefix="sub dir" --branch subproj-br && # at this point, the new commit parent should be subproj-ref, if it is - # not, something went wrong (the "newparent" of "master~" commit should + # not, something went wrong (the "newparent" of "HEAD~" commit should # have been sub2, but it was not, because its cache was not set to # itself) check_equal "$(git log --pretty=format:%P -1 subproj-br)" "$(git rev-parse subproj-ref)" @@ -868,13 +868,13 @@ test_expect_success 'split a new subtree without --onto option' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count/sub proj" sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -903,14 +903,14 @@ test_expect_success 'verify one file change per commit' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git branch sub1 FETCH_HEAD && git subtree add --prefix="sub dir" sub1 ) && test_create_commit "$subtree_test_count/sub proj" sub2 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -947,7 +947,7 @@ test_expect_success 'push split to subproj' ' test_create_commit "$subtree_test_count/sub proj" sub1 && ( cd "$subtree_test_count" && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && @@ -958,7 +958,7 @@ test_expect_success 'push split to subproj' ' cd $subtree_test_count/"sub proj" && git branch sub-branch-1 && cd .. && - git fetch ./"sub proj" master && + git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$subtree_test_count" "sub dir"/main-sub3 && @@ -994,6 +994,7 @@ test_expect_success 'push split to subproj' ' next_test test_expect_success 'subtree descendant check' ' subtree_test_create_repo "$subtree_test_count" && + defaultBranch=$(sed "s,ref: refs/heads/,," "$subtree_test_count/.git/HEAD") && test_create_commit "$subtree_test_count" folder_subtree/a && ( cd "$subtree_test_count" && @@ -1010,7 +1011,7 @@ test_expect_success 'subtree descendant check' ' ( cd "$subtree_test_count" && git cherry-pick $cherry && - git checkout master && + git checkout $defaultBranch && git merge -m "merge should be kept on subtree" branch && git branch no_subtree_work_branch ) && @@ -1022,10 +1023,10 @@ test_expect_success 'subtree descendant check' ' test_create_commit "$subtree_test_count" not_a_subtree_change && ( cd "$subtree_test_count" && - git checkout master && + git checkout $defaultBranch && git merge -m "merge should be skipped on subtree" no_subtree_work_branch && - git subtree split --prefix folder_subtree/ --branch subtree_tip master && + git subtree split --prefix folder_subtree/ --branch subtree_tip $defaultBranch && git subtree split --prefix folder_subtree/ --branch subtree_branch branch && check_equal $(git rev-list --count subtree_tip..subtree_branch) 0 ) From patchwork Fri Apr 23 19:42:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FB20C43470 for ; Fri, 23 Apr 2021 19:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 496296145F for ; Fri, 23 Apr 2021 19:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243828AbhDWTnY (ORCPT ); Fri, 23 Apr 2021 15:43:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbhDWTnX (ORCPT ); Fri, 23 Apr 2021 15:43:23 -0400 Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AA01C061574 for ; Fri, 23 Apr 2021 12:42:46 -0700 (PDT) Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id D416280593; Fri, 23 Apr 2021 15:42:43 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 03/30] subtree: t7900: use test-lib.sh's test_count Date: Fri, 23 Apr 2021 13:42:03 -0600 Message-Id: <20210423194230.1388945-4-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Use test-lib.sh's `test_count`, instead instead of having t7900-subtree.sh do its own book-keeping with `subtree_test_count` that has to be explicitly incremented by calling `next_test`. Signed-off-by: Luke Shumaker --- contrib/subtree/t/t7900-subtree.sh | 636 ++++++++++++++--------------- 1 file changed, 300 insertions(+), 336 deletions(-) diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 4b982e6c2e..a6351d9195 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -86,90 +86,79 @@ last_commit_message() git log --pretty=format:%s -1 } -subtree_test_count=0 -next_test() { - subtree_test_count=$(($subtree_test_count+1)) -} - # # Tests for 'git subtree add' # -next_test test_expect_success 'no merge from non-existent subtree' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD ) ' -next_test test_expect_success 'no pull from non-existent subtree' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD )' -next_test test_expect_success 'add subproj as subtree into sub dir/ with --prefix' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && check_equal "$(last_commit_message)" "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" ) ' -next_test test_expect_success 'add subproj as subtree into sub dir/ with --prefix and --message' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD && check_equal "$(last_commit_message)" "Added subproject" ) ' -next_test test_expect_success 'add subproj as subtree into sub dir/ with --prefix as -P and --message as -m' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD && check_equal "$(last_commit_message)" "Added subproject" ) ' -next_test test_expect_success 'add subproj as subtree into sub dir/ with --squash and --prefix and --message' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD && check_equal "$(last_commit_message)" "Added subproject with squash" @@ -180,74 +169,70 @@ test_expect_success 'add subproj as subtree into sub dir/ with --squash and --pr # Tests for 'git subtree merge' # -next_test test_expect_success 'merge new subproj history into sub dir/ with --prefix' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count/sub proj" sub2 && + test_create_commit "$test_count/sub proj" sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" ) ' -next_test test_expect_success 'merge new subproj history into sub dir/ with --prefix and --message' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count/sub proj" sub2 && + test_create_commit "$test_count/sub proj" sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD && check_equal "$(last_commit_message)" "Merged changes from subproject" ) ' -next_test test_expect_success 'merge new subproj history into sub dir/ with --squash and --prefix and --message' ' - subtree_test_create_repo "$subtree_test_count/sub proj" && - subtree_test_create_repo "$subtree_test_count" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count/sub proj" && + subtree_test_create_repo "$test_count" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count/sub proj" sub2 && + test_create_commit "$test_count/sub proj" sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD && check_equal "$(last_commit_message)" "Merged changes from subproject using squash" ) ' -next_test test_expect_success 'merge the added subproj again, should do nothing' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && # this shouldn not actually do anything, since FETCH_HEAD @@ -257,7 +242,6 @@ test_expect_success 'merge the added subproj again, should do nothing' ' ) ' -next_test test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' ' test_create_repo "$test_count" && test_create_repo "$test_count/subproj" && @@ -281,14 +265,13 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende # Tests for 'git subtree split' # -next_test test_expect_success 'split requires option --prefix' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && echo "You must provide the --prefix option." > expected && @@ -301,14 +284,13 @@ test_expect_success 'split requires option --prefix' ' ) ' -next_test test_expect_success 'split requires path given by option --prefix must exist' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected && @@ -321,23 +303,22 @@ test_expect_success 'split requires path given by option --prefix must exist' ' ) ' -next_test test_expect_success 'split sub dir/ with --rejoin' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && @@ -346,12 +327,11 @@ test_expect_success 'split sub dir/ with --rejoin' ' ) ' -next_test test_expect_success 'split sub dir/ with --rejoin from scratch' ' - subtree_test_create_repo "$subtree_test_count" && - test_create_commit "$subtree_test_count" main1 && + subtree_test_create_repo "$test_count" && + test_create_commit "$test_count" main1 && ( - cd "$subtree_test_count" && + cd "$test_count" && mkdir "sub dir" && echo file >"sub dir"/file && git add "sub dir/file" && @@ -362,23 +342,22 @@ test_expect_success 'split sub dir/ with --rejoin from scratch' ' ) ' -next_test test_expect_success 'split sub dir/ with --rejoin and --message' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin && @@ -386,23 +365,22 @@ test_expect_success 'split sub dir/ with --rejoin and --message' ' ) ' -next_test test_expect_success 'split "sub dir"/ with --branch' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && @@ -411,23 +389,22 @@ test_expect_success 'split "sub dir"/ with --branch' ' ) ' -next_test test_expect_success 'check hash of split' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && @@ -443,24 +420,23 @@ test_expect_success 'check hash of split' ' ) ' -next_test test_expect_success 'split "sub dir"/ with --branch for an existing branch' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git branch subproj-br FETCH_HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && @@ -469,24 +445,23 @@ test_expect_success 'split "sub dir"/ with --branch for an existing branch' ' ) ' -next_test test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git branch init HEAD && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && test_must_fail git subtree split --prefix="sub dir" --branch init @@ -497,46 +472,45 @@ test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' # Validity checking # -next_test test_expect_success 'make sure exactly the right set of files ends up in the subproj' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count/sub proj" sub3 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub3 && + test_create_commit "$test_count/sub proj" sub3 && + test_create_commit "$test_count" "sub dir"/main-sub3 && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD ) && - test_create_commit "$subtree_test_count/sub proj" sub4 && + test_create_commit "$test_count/sub proj" sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub4 && + test_create_commit "$test_count" "sub dir"/main-sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD && @@ -547,46 +521,45 @@ test_expect_success 'make sure exactly the right set of files ends up in the sub ) ' -next_test test_expect_success 'make sure the subproj *only* contains commits that affect the "sub dir"' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count/sub proj" sub3 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub3 && + test_create_commit "$test_count/sub proj" sub3 && + test_create_commit "$test_count" "sub dir"/main-sub3 && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD ) && - test_create_commit "$subtree_test_count/sub proj" sub4 && + test_create_commit "$test_count/sub proj" sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub4 && + test_create_commit "$test_count" "sub dir"/main-sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD && @@ -598,51 +571,50 @@ test_expect_success 'make sure the subproj *only* contains commits that affect t ) ' -next_test test_expect_success 'make sure exactly the right set of files ends up in the mainline' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count/sub proj" sub3 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub3 && + test_create_commit "$test_count/sub proj" sub3 && + test_create_commit "$test_count" "sub dir"/main-sub3 && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD ) && - test_create_commit "$subtree_test_count/sub proj" sub4 && + test_create_commit "$test_count/sub proj" sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub4 && + test_create_commit "$test_count" "sub dir"/main-sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD ) && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree pull --prefix="sub dir" ./"sub proj" HEAD && test_write_lines main1 main2 >chkm && @@ -657,52 +629,51 @@ test_expect_success 'make sure exactly the right set of files ends up in the mai ) ' -next_test test_expect_success 'make sure each filename changed exactly once in the entire history' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git config log.date relative && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count/sub proj" sub3 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub3 && + test_create_commit "$test_count/sub proj" sub3 && + test_create_commit "$test_count" "sub dir"/main-sub3 && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD ) && - test_create_commit "$subtree_test_count/sub proj" sub4 && + test_create_commit "$test_count/sub proj" sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub4 && + test_create_commit "$test_count" "sub dir"/main-sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD ) && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree pull --prefix="sub dir" ./"sub proj" HEAD && test_write_lines main1 main2 >chkm && @@ -723,101 +694,99 @@ test_expect_success 'make sure each filename changed exactly once in the entire ) ' -next_test test_expect_success 'make sure the --rejoin commits never make it into subproj' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count/sub proj" sub3 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub3 && + test_create_commit "$test_count/sub proj" sub3 && + test_create_commit "$test_count" "sub dir"/main-sub3 && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD ) && - test_create_commit "$subtree_test_count/sub proj" sub4 && + test_create_commit "$test_count/sub proj" sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub4 && + test_create_commit "$test_count" "sub dir"/main-sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD ) && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree pull --prefix="sub dir" ./"sub proj" HEAD && check_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" "" ) ' -next_test test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count/sub proj" sub3 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub3 && + test_create_commit "$test_count/sub proj" sub3 && + test_create_commit "$test_count" "sub dir"/main-sub3 && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD ) && - test_create_commit "$subtree_test_count/sub proj" sub4 && + test_create_commit "$test_count/sub proj" sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub4 && + test_create_commit "$test_count" "sub dir"/main-sub4 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin ) && ( - cd "$subtree_test_count/sub proj" && + cd "$test_count/sub proj" && git fetch .. subproj-br && git merge FETCH_HEAD ) && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree pull --prefix="sub dir" ./"sub proj" HEAD && # They are meaningless to subproj since one side of the merge refers to the mainline @@ -829,27 +798,26 @@ test_expect_success 'make sure no "git subtree" tagged commits make it into subp # A new set of tests # -next_test test_expect_success 'make sure "git subtree split" find the correct parent' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count/sub proj" sub2 && + test_create_commit "$test_count/sub proj" sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git branch subproj-ref FETCH_HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" "sub dir"/main-sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --branch subproj-br && # at this point, the new commit parent should be subproj-ref, if it is @@ -860,32 +828,31 @@ test_expect_success 'make sure "git subtree split" find the correct parent' ' ) ' -next_test test_expect_success 'split a new subtree without --onto option' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count/sub proj" sub2 && + test_create_commit "$test_count/sub proj" sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" "sub dir"/main-sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --branch subproj-br ) && - mkdir "$subtree_test_count"/"sub dir2" && - test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 && + mkdir "$test_count"/"sub dir2" && + test_create_commit "$test_count" "sub dir2"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && # also test that we still can split out an entirely new subtree # if the parent of the first commit in the tree is not empty, @@ -895,33 +862,32 @@ test_expect_success 'split a new subtree without --onto option' ' ) ' -next_test test_expect_success 'verify one file change per commit' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git branch sub1 FETCH_HEAD && git subtree add --prefix="sub dir" sub1 ) && - test_create_commit "$subtree_test_count/sub proj" sub2 && + test_create_commit "$test_count/sub proj" sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" "sub dir"/main-sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir" --branch subproj-br ) && - mkdir "$subtree_test_count"/"sub dir2" && - test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 && + mkdir "$test_count"/"sub dir2" && + test_create_commit "$test_count" "sub dir2"/main-sub2 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree split --prefix="sub dir2" --branch subproj2-br && x= && @@ -939,31 +905,30 @@ test_expect_success 'verify one file change per commit' ' ) ' -next_test test_expect_success 'push split to subproj' ' - subtree_test_create_repo "$subtree_test_count" && - subtree_test_create_repo "$subtree_test_count/sub proj" && - test_create_commit "$subtree_test_count" main1 && - test_create_commit "$subtree_test_count/sub proj" sub1 && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && ( - cd "$subtree_test_count" && + cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub1 && - test_create_commit "$subtree_test_count" main2 && - test_create_commit "$subtree_test_count/sub proj" sub2 && - test_create_commit "$subtree_test_count" "sub dir"/main-sub2 && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && ( - cd $subtree_test_count/"sub proj" && + cd $test_count/"sub proj" && git branch sub-branch-1 && cd .. && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD ) && - test_create_commit "$subtree_test_count" "sub dir"/main-sub3 && + test_create_commit "$test_count" "sub dir"/main-sub3 && ( - cd "$subtree_test_count" && + cd "$test_count" && git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 && cd ./"sub proj" && git checkout sub-branch-1 && @@ -991,38 +956,37 @@ test_expect_success 'push split to subproj' ' # set of commits. # -next_test test_expect_success 'subtree descendant check' ' - subtree_test_create_repo "$subtree_test_count" && - defaultBranch=$(sed "s,ref: refs/heads/,," "$subtree_test_count/.git/HEAD") && - test_create_commit "$subtree_test_count" folder_subtree/a && + subtree_test_create_repo "$test_count" && + defaultBranch=$(sed "s,ref: refs/heads/,," "$test_count/.git/HEAD") && + test_create_commit "$test_count" folder_subtree/a && ( - cd "$subtree_test_count" && + cd "$test_count" && git branch branch ) && - test_create_commit "$subtree_test_count" folder_subtree/0 && - test_create_commit "$subtree_test_count" folder_subtree/b && - cherry=$(cd "$subtree_test_count"; git rev-parse HEAD) && + test_create_commit "$test_count" folder_subtree/0 && + test_create_commit "$test_count" folder_subtree/b && + cherry=$(cd "$test_count"; git rev-parse HEAD) && ( - cd "$subtree_test_count" && + cd "$test_count" && git checkout branch ) && - test_create_commit "$subtree_test_count" commit_on_branch && + test_create_commit "$test_count" commit_on_branch && ( - cd "$subtree_test_count" && + cd "$test_count" && git cherry-pick $cherry && git checkout $defaultBranch && git merge -m "merge should be kept on subtree" branch && git branch no_subtree_work_branch ) && - test_create_commit "$subtree_test_count" folder_subtree/d && + test_create_commit "$test_count" folder_subtree/d && ( - cd "$subtree_test_count" && + cd "$test_count" && git checkout no_subtree_work_branch ) && - test_create_commit "$subtree_test_count" not_a_subtree_change && + test_create_commit "$test_count" not_a_subtree_change && ( - cd "$subtree_test_count" && + cd "$test_count" && git checkout $defaultBranch && git merge -m "merge should be skipped on subtree" no_subtree_work_branch && From patchwork Fri Apr 23 19:42:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F4168C43462 for ; Fri, 23 Apr 2021 19:42:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C87EA610A2 for ; Fri, 23 Apr 2021 19:42:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243738AbhDWTnW (ORCPT ); Fri, 23 Apr 2021 15:43:22 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35144 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbhDWTnW (ORCPT ); Fri, 23 Apr 2021 15:43:22 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id CF59580594; Fri, 23 Apr 2021 15:42:44 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 04/30] subtree: t7900: use consistent formatting Date: Fri, 23 Apr 2021 13:42:04 -0600 Message-Id: <20210423194230.1388945-5-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker The formatting in t7900-subtree.sh isn't even consistent throughout the file. Fix that; make it consistent throughout the file. Signed-off-by: Luke Shumaker --- contrib/subtree/t/t7900-subtree.sh | 47 +++++++++++++----------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index a6351d9195..74516513cd 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -11,11 +11,9 @@ and split subcommands of git subtree. TEST_DIRECTORY=$(pwd)/../../../t export TEST_DIRECTORY +. "$TEST_DIRECTORY"/test-lib.sh -. ../../../t/test-lib.sh - -subtree_test_create_repo() -{ +subtree_test_create_repo () { test_create_repo "$1" && ( cd "$1" && @@ -23,26 +21,24 @@ subtree_test_create_repo() ) } -create() -{ +create () { echo "$1" >"$1" && git add "$1" } -check_equal() -{ +check_equal () { test_debug 'echo' test_debug "echo \"check a:\" \"{$1}\"" test_debug "echo \" b:\" \"{$2}\"" - if [ "$1" = "$2" ]; then + if [ "$1" = "$2" ] + then return 0 else return 1 fi } -undo() -{ +undo () { git reset --hard HEAD~ } @@ -50,8 +46,7 @@ undo() # The original set of commits changed only one file each. # A multi-file change would imply that we pruned commits # too aggressively. -join_commits() -{ +join_commits () { commit= all= while read x y; do @@ -70,7 +65,7 @@ join_commits() echo "$commit $all" } -test_create_commit() ( +test_create_commit () ( repo=$1 && commit=$2 && cd "$repo" && @@ -81,8 +76,7 @@ test_create_commit() ( git commit -m "$commit" || error "Could not commit" ) -last_commit_message() -{ +last_commit_message () { git log --pretty=format:%s -1 } @@ -111,7 +105,8 @@ test_expect_success 'no pull from non-existent subtree' ' cd "$test_count" && git fetch ./"sub proj" HEAD && test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD - )' + ) +' test_expect_success 'add subproj as subtree into sub dir/ with --prefix' ' subtree_test_create_repo "$test_count" && @@ -325,7 +320,7 @@ test_expect_success 'split sub dir/ with --rejoin' ' git subtree split --prefix="sub dir" --annotate="*" --rejoin && check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" ) - ' +' test_expect_success 'split sub dir/ with --rejoin from scratch' ' subtree_test_create_repo "$test_count" && @@ -340,7 +335,7 @@ test_expect_success 'split sub dir/ with --rejoin from scratch' ' git subtree split --prefix="sub dir" --rejoin && check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" ) - ' +' test_expect_success 'split sub dir/ with --rejoin and --message' ' subtree_test_create_repo "$test_count" && @@ -921,18 +916,18 @@ test_expect_success 'push split to subproj' ' test_create_commit "$test_count" "sub dir"/main-sub2 && ( cd $test_count/"sub proj" && - git branch sub-branch-1 && - cd .. && + git branch sub-branch-1 && + cd .. && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD ) && test_create_commit "$test_count" "sub dir"/main-sub3 && - ( + ( cd "$test_count" && - git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 && - cd ./"sub proj" && - git checkout sub-branch-1 && - check_equal "$(last_commit_message)" "sub dir/main-sub3" + git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 && + cd ./"sub proj" && + git checkout sub-branch-1 && + check_equal "$(last_commit_message)" "sub dir/main-sub3" ) ' From patchwork Fri Apr 23 19:42:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57450C433B4 for ; Fri, 23 Apr 2021 19:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 36BB361075 for ; Fri, 23 Apr 2021 19:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243801AbhDWTnX (ORCPT ); Fri, 23 Apr 2021 15:43:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243795AbhDWTnX (ORCPT ); Fri, 23 Apr 2021 15:43:23 -0400 Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F333C06174A for ; Fri, 23 Apr 2021 12:42:46 -0700 (PDT) Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id BCBB780590; Fri, 23 Apr 2021 15:42:45 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 05/30] subtree: t7900: comment subtree_test_create_repo Date: Fri, 23 Apr 2021 13:42:05 -0600 Message-Id: <20210423194230.1388945-6-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker It's unclear what the purpose of t7900-subtree.sh's `subtree_test_create_repo` helper function is. It wraps test-lib.sh's, `test_create_repo` but follows that up by setting log.date=relative. Why does it set log.date=relative? My first guess was that at one point the tests required that, but no longer do, and that the function is now vestigial. I even wrote a patch to get rid of it and was moments away from `git send-email`ing it. However, by chance when looking for something else in the history, I discovered the true reason, from e7aac44ed2 (contrib/subtree: ignore log.date configuration, 2015-07-21). It's testing that setting log.date=relative doesn't break `git subtree`, as at one point in the past that did break `git subtree`. So, add a comment about this, to avoid future such confusion. And while at it, go ahead and touch up the function to avoid a pointless subshell. Signed-off-by: Luke Shumaker --- contrib/subtree/t/t7900-subtree.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 74516513cd..827bd3fcd8 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -13,12 +13,14 @@ TEST_DIRECTORY=$(pwd)/../../../t export TEST_DIRECTORY . "$TEST_DIRECTORY"/test-lib.sh +# Use our own wrapper around test-lib.sh's test_create_repo, in order +# to set log.date=relative. `git subtree` parses the output of `git +# log`, and so it must be careful to not be affected by settings that +# change the `git log` output. We test this by setting +# log.date=relative for every repo in the tests. subtree_test_create_repo () { test_create_repo "$1" && - ( - cd "$1" && - git config log.date relative - ) + git -C "$1" config log.date relative } create () { From patchwork Fri Apr 23 19:42:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56954C43460 for ; Fri, 23 Apr 2021 19:42:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3BCA8610A2 for ; Fri, 23 Apr 2021 19:42:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243838AbhDWTnY (ORCPT ); Fri, 23 Apr 2021 15:43:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243795AbhDWTnY (ORCPT ); Fri, 23 Apr 2021 15:43:24 -0400 Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 413DFC061574 for ; Fri, 23 Apr 2021 12:42:47 -0700 (PDT) Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 9E52C80592; Fri, 23 Apr 2021 15:42:46 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 06/30] subtree: t7900: use 'test' for string equality Date: Fri, 23 Apr 2021 13:42:06 -0600 Message-Id: <20210423194230.1388945-7-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker t7900-subtree.sh defines its own `check_equal A B` function, instead of just using `test A = B` like all of the other tests. Don't be special, get rid of `check_equal` in favor of `test`. Signed-off-by: Luke Shumaker --- contrib/subtree/t/t7900-subtree.sh | 60 ++++++++++++------------------ 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 827bd3fcd8..ae96c8cff5 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -28,18 +28,6 @@ create () { git add "$1" } -check_equal () { - test_debug 'echo' - test_debug "echo \"check a:\" \"{$1}\"" - test_debug "echo \" b:\" \"{$2}\"" - if [ "$1" = "$2" ] - then - return 0 - else - return 1 - fi -} - undo () { git reset --hard HEAD~ } @@ -119,7 +107,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --prefix' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && - check_equal "$(last_commit_message)" "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" + test "$(last_commit_message)" = "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" ) ' @@ -132,7 +120,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --prefix and --me cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD && - check_equal "$(last_commit_message)" "Added subproject" + test "$(last_commit_message)" = "Added subproject" ) ' @@ -145,7 +133,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --prefix as -P an cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD && - check_equal "$(last_commit_message)" "Added subproject" + test "$(last_commit_message)" = "Added subproject" ) ' @@ -158,7 +146,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --squash and --pr cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD && - check_equal "$(last_commit_message)" "Added subproject with squash" + test "$(last_commit_message)" = "Added subproject with squash" ) ' @@ -181,7 +169,7 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && - check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + test "$(last_commit_message)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" ) ' @@ -200,7 +188,7 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix and - cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD && - check_equal "$(last_commit_message)" "Merged changes from subproject" + test "$(last_commit_message)" = "Merged changes from subproject" ) ' @@ -219,7 +207,7 @@ test_expect_success 'merge new subproj history into sub dir/ with --squash and - cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD && - check_equal "$(last_commit_message)" "Merged changes from subproject using squash" + test "$(last_commit_message)" = "Merged changes from subproject using squash" ) ' @@ -235,7 +223,7 @@ test_expect_success 'merge the added subproj again, should do nothing' ' # this shouldn not actually do anything, since FETCH_HEAD # is already a parent result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) && - check_equal "${result}" "Already up to date." + test "${result}" = "Already up to date." ) ' @@ -254,7 +242,7 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende cd "$test_count" && git fetch ./subproj HEAD && git subtree merge --prefix=subdir/ FETCH_HEAD && - check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + test "$(last_commit_message)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" ) ' @@ -320,7 +308,7 @@ test_expect_success 'split sub dir/ with --rejoin' ' git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && git subtree split --prefix="sub dir" --annotate="*" --rejoin && - check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" + test "$(last_commit_message)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" ) ' @@ -335,7 +323,7 @@ test_expect_success 'split sub dir/ with --rejoin from scratch' ' git commit -m"sub dir file" && split_hash=$(git subtree split --prefix="sub dir" --rejoin) && git subtree split --prefix="sub dir" --rejoin && - check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" + test "$(last_commit_message)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" ) ' @@ -358,7 +346,7 @@ test_expect_success 'split sub dir/ with --rejoin and --message' ' git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin && - check_equal "$(last_commit_message)" "Split & rejoin" + test "$(last_commit_message)" = "Split & rejoin" ) ' @@ -382,7 +370,7 @@ test_expect_success 'split "sub dir"/ with --branch' ' git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && - check_equal "$(git rev-parse subproj-br)" "$split_hash" + test "$(git rev-parse subproj-br)" = "$split_hash" ) ' @@ -406,13 +394,13 @@ test_expect_success 'check hash of split' ' git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && - check_equal "$(git rev-parse subproj-br)" "$split_hash" && + test "$(git rev-parse subproj-br)" = "$split_hash" && # Check hash of split new_hash=$(git rev-parse subproj-br^2) && ( cd ./"sub proj" && subdir_hash=$(git rev-parse HEAD) && - check_equal ''"$new_hash"'' "$subdir_hash" + test ''"$new_hash"'' = "$subdir_hash" ) ) ' @@ -438,7 +426,7 @@ test_expect_success 'split "sub dir"/ with --branch for an existing branch' ' git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && - check_equal "$(git rev-parse subproj-br)" "$split_hash" + test "$(git rev-parse subproj-br)" = "$split_hash" ) ' @@ -736,7 +724,7 @@ test_expect_success 'make sure the --rejoin commits never make it into subproj' ( cd "$test_count" && git subtree pull --prefix="sub dir" ./"sub proj" HEAD && - check_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" "" + test "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" = "" ) ' @@ -787,7 +775,7 @@ test_expect_success 'make sure no "git subtree" tagged commits make it into subp git subtree pull --prefix="sub dir" ./"sub proj" HEAD && # They are meaningless to subproj since one side of the merge refers to the mainline - check_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" "" + test "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" = "" ) ' @@ -821,7 +809,7 @@ test_expect_success 'make sure "git subtree split" find the correct parent' ' # not, something went wrong (the "newparent" of "HEAD~" commit should # have been sub2, but it was not, because its cache was not set to # itself) - check_equal "$(git log --pretty=format:%P -1 subproj-br)" "$(git rev-parse subproj-ref)" + test "$(git log --pretty=format:%P -1 subproj-br)" = "$(git rev-parse subproj-ref)" ) ' @@ -855,7 +843,7 @@ test_expect_success 'split a new subtree without --onto option' ' # if the parent of the first commit in the tree is not empty, # then the new subtree has accidentally been attached to something git subtree split --prefix="sub dir2" --branch subproj2-br && - check_equal "$(git log --pretty=format:%P -1 subproj2-br)" "" + test "$(git log --pretty=format:%P -1 subproj2-br)" = "" ) ' @@ -894,10 +882,10 @@ test_expect_success 'verify one file change per commit' ' test_debug "echo Verifying commit $commit" test_debug "echo a: $a" test_debug "echo b: $b" - check_equal "$b" "" + test "$b" = "" x=1 done - check_equal "$x" 1 + test "$x" = 1 ) ) ' @@ -929,7 +917,7 @@ test_expect_success 'push split to subproj' ' git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 && cd ./"sub proj" && git checkout sub-branch-1 && - check_equal "$(last_commit_message)" "sub dir/main-sub3" + test "$(last_commit_message)" = "sub dir/main-sub3" ) ' @@ -989,7 +977,7 @@ test_expect_success 'subtree descendant check' ' git subtree split --prefix folder_subtree/ --branch subtree_tip $defaultBranch && git subtree split --prefix folder_subtree/ --branch subtree_branch branch && - check_equal $(git rev-list --count subtree_tip..subtree_branch) 0 + test $(git rev-list --count subtree_tip..subtree_branch) = 0 ) ' From patchwork Fri Apr 23 19:42:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1978FC43462 for ; Fri, 23 Apr 2021 19:42:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F310861075 for ; Fri, 23 Apr 2021 19:42:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243843AbhDWTnZ (ORCPT ); Fri, 23 Apr 2021 15:43:25 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35186 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243832AbhDWTnY (ORCPT ); Fri, 23 Apr 2021 15:43:24 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 7DA6C80590; Fri, 23 Apr 2021 15:42:47 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 07/30] subtree: t7900: delete some dead code Date: Fri, 23 Apr 2021 13:42:07 -0600 Message-Id: <20210423194230.1388945-8-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Signed-off-by: Luke Shumaker --- contrib/subtree/t/t7900-subtree.sh | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index ae96c8cff5..96acd4f8be 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -10,7 +10,6 @@ and split subcommands of git subtree. ' TEST_DIRECTORY=$(pwd)/../../../t -export TEST_DIRECTORY . "$TEST_DIRECTORY"/test-lib.sh # Use our own wrapper around test-lib.sh's test_create_repo, in order @@ -23,15 +22,6 @@ subtree_test_create_repo () { git -C "$1" config log.date relative } -create () { - echo "$1" >"$1" && - git add "$1" -} - -undo () { - git reset --hard HEAD~ -} - # Make sure no patch changes more than one file. # The original set of commits changed only one file each. # A multi-file change would imply that we pruned commits @@ -400,7 +390,7 @@ test_expect_success 'check hash of split' ' ( cd ./"sub proj" && subdir_hash=$(git rev-parse HEAD) && - test ''"$new_hash"'' = "$subdir_hash" + test "$new_hash" = "$subdir_hash" ) ) ' From patchwork Fri Apr 23 19:42:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221585 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C67DEC433ED for ; Fri, 23 Apr 2021 19:42:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8D7D6128B for ; Fri, 23 Apr 2021 19:42:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243861AbhDWTn0 (ORCPT ); Fri, 23 Apr 2021 15:43:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243832AbhDWTn0 (ORCPT ); Fri, 23 Apr 2021 15:43:26 -0400 Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AF33C061574 for ; Fri, 23 Apr 2021 12:42:48 -0700 (PDT) Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 5F23C80594; Fri, 23 Apr 2021 15:42:48 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 08/30] subtree: t7900: fix 'verify one file change per commit' Date: Fri, 23 Apr 2021 13:42:08 -0600 Message-Id: <20210423194230.1388945-9-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker As far as I can tell, this test isn't actually testing anything, because someone forgot to tack on `--name-only` to `git log`. This seems to have been the case since the test was first written, back in fa16ab36ad ("test.sh: make sure no commit changes more than one file at a time.", 2009-04-26), unless `git log` used to do that by default and didn't need the flag back then? Convincing myself that it's not actually testing anything was tricky, the code is a little hard to reason about. It can be made a lot simpler if instead of trying to parse all of the info from a single `git log`, we're OK calling `git log` from inside of a loop. And it's my opinion that tests are not the place for clever optimized code. So, fix and simplify the test, so that it's actually testing something and is simpler to reason about. Signed-off-by: Luke Shumaker --- contrib/subtree/t/t7900-subtree.sh | 41 +++++------------------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 96acd4f8be..70be18246b 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -22,29 +22,6 @@ subtree_test_create_repo () { git -C "$1" config log.date relative } -# Make sure no patch changes more than one file. -# The original set of commits changed only one file each. -# A multi-file change would imply that we pruned commits -# too aggressively. -join_commits () { - commit= - all= - while read x y; do - if [ -z "$x" ]; then - continue - elif [ "$x" = "commit:" ]; then - if [ -n "$commit" ]; then - echo "$commit $all" - all= - fi - commit="$y" - else - all="$all $y" - fi - done - echo "$commit $all" -} - test_create_commit () ( repo=$1 && commit=$2 && @@ -865,18 +842,12 @@ test_expect_success 'verify one file change per commit' ' cd "$test_count" && git subtree split --prefix="sub dir2" --branch subproj2-br && - x= && - git log --pretty=format:"commit: %H" | join_commits | - ( - while read commit a b; do - test_debug "echo Verifying commit $commit" - test_debug "echo a: $a" - test_debug "echo b: $b" - test "$b" = "" - x=1 - done - test "$x" = 1 - ) + git log --format="%H" > commit-list && + while read commit + do + git log -n1 --format="" --name-only "$commit" >file-list && + test_line_count -le 1 file-list || return 1 + done X-Patchwork-Id: 12221587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8FFFC433B4 for ; Fri, 23 Apr 2021 19:42:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC62F61075 for ; Fri, 23 Apr 2021 19:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243809AbhDWTn1 (ORCPT ); Fri, 23 Apr 2021 15:43:27 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35214 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243849AbhDWTn0 (ORCPT ); Fri, 23 Apr 2021 15:43:26 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 4CDDB80595; Fri, 23 Apr 2021 15:42:49 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 09/30] subtree: t7900: rename last_commit_message to last_commit_subject Date: Fri, 23 Apr 2021 13:42:09 -0600 Message-Id: <20210423194230.1388945-10-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker t7900-subtree.sh defines a helper function named last_commit_message. However, it only returns the subject line of the commit message, not the entire commit message. So rename it, to make the name less confusing. Signed-off-by: Luke Shumaker --- contrib/subtree/t/t7900-subtree.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 70be18246b..4c4d6c8e6b 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -33,7 +33,7 @@ test_create_commit () ( git commit -m "$commit" || error "Could not commit" ) -last_commit_message () { +last_commit_subject () { git log --pretty=format:%s -1 } @@ -74,7 +74,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --prefix' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" FETCH_HEAD && - test "$(last_commit_message)" = "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" + test "$(last_commit_subject)" = "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" ) ' @@ -87,7 +87,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --prefix and --me cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD && - test "$(last_commit_message)" = "Added subproject" + test "$(last_commit_subject)" = "Added subproject" ) ' @@ -100,7 +100,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --prefix as -P an cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD && - test "$(last_commit_message)" = "Added subproject" + test "$(last_commit_subject)" = "Added subproject" ) ' @@ -113,7 +113,7 @@ test_expect_success 'add subproj as subtree into sub dir/ with --squash and --pr cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD && - test "$(last_commit_message)" = "Added subproject with squash" + test "$(last_commit_subject)" = "Added subproject with squash" ) ' @@ -136,7 +136,7 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix' ' cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && - test "$(last_commit_message)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" ) ' @@ -155,7 +155,7 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix and - cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD && - test "$(last_commit_message)" = "Merged changes from subproject" + test "$(last_commit_subject)" = "Merged changes from subproject" ) ' @@ -174,7 +174,7 @@ test_expect_success 'merge new subproj history into sub dir/ with --squash and - cd "$test_count" && git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD && - test "$(last_commit_message)" = "Merged changes from subproject using squash" + test "$(last_commit_subject)" = "Merged changes from subproject using squash" ) ' @@ -209,7 +209,7 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende cd "$test_count" && git fetch ./subproj HEAD && git subtree merge --prefix=subdir/ FETCH_HEAD && - test "$(last_commit_message)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" ) ' @@ -275,7 +275,7 @@ test_expect_success 'split sub dir/ with --rejoin' ' git subtree merge --prefix="sub dir" FETCH_HEAD && split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && git subtree split --prefix="sub dir" --annotate="*" --rejoin && - test "$(last_commit_message)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" + test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" ) ' @@ -290,7 +290,7 @@ test_expect_success 'split sub dir/ with --rejoin from scratch' ' git commit -m"sub dir file" && split_hash=$(git subtree split --prefix="sub dir" --rejoin) && git subtree split --prefix="sub dir" --rejoin && - test "$(last_commit_message)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" + test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" ) ' @@ -313,7 +313,7 @@ test_expect_success 'split sub dir/ with --rejoin and --message' ' git fetch ./"sub proj" HEAD && git subtree merge --prefix="sub dir" FETCH_HEAD && git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin && - test "$(last_commit_message)" = "Split & rejoin" + test "$(last_commit_subject)" = "Split & rejoin" ) ' @@ -878,7 +878,7 @@ test_expect_success 'push split to subproj' ' git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 && cd ./"sub proj" && git checkout sub-branch-1 && - test "$(last_commit_message)" = "sub dir/main-sub3" + test "$(last_commit_subject)" = "sub dir/main-sub3" ) ' From patchwork Fri Apr 23 19:42:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221589 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CC8EC433ED for ; Fri, 23 Apr 2021 19:42:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0C1E61075 for ; Fri, 23 Apr 2021 19:42:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243890AbhDWTnb (ORCPT ); Fri, 23 Apr 2021 15:43:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243880AbhDWTn2 (ORCPT ); Fri, 23 Apr 2021 15:43:28 -0400 Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9EF1C061756 for ; Fri, 23 Apr 2021 12:42:50 -0700 (PDT) Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 4FF8380591; Fri, 23 Apr 2021 15:42:50 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 10/30] subtree: t7900: add a test for the -h flag Date: Fri, 23 Apr 2021 13:42:10 -0600 Message-Id: <20210423194230.1388945-11-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker It's a dumb test, but it's surprisingly easy to break. Signed-off-by: Luke Shumaker --- contrib/subtree/t/t7900-subtree.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 4c4d6c8e6b..6b655ab4b5 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -37,6 +37,13 @@ last_commit_subject () { git log --pretty=format:%s -1 } +test_expect_success 'shows short help text for -h' ' + test_expect_code 129 git subtree -h >out 2>err && + test_must_be_empty err && + grep -e "^ *or: git subtree pull" out && + grep -e --annotate out +' + # # Tests for 'git subtree add' # From patchwork Fri Apr 23 19:42:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C29CCC433B4 for ; Fri, 23 Apr 2021 19:42:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA7C96128B for ; Fri, 23 Apr 2021 19:42:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243896AbhDWTnc (ORCPT ); Fri, 23 Apr 2021 15:43:32 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35254 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243845AbhDWTn3 (ORCPT ); Fri, 23 Apr 2021 15:43:29 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 1A91380592; Fri, 23 Apr 2021 15:42:51 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 11/30] subtree: t7900: add porcelain tests for 'pull' and 'push' Date: Fri, 23 Apr 2021 13:42:11 -0600 Message-Id: <20210423194230.1388945-12-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker The 'pull' and 'push' subcommands deserve their own sections in the tests. Add some basic tests for them. Signed-off-by: Luke Shumaker --- contrib/subtree/t/t7900-subtree.sh | 131 ++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 2 deletions(-) diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 6b655ab4b5..3ee0524233 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -202,8 +202,8 @@ test_expect_success 'merge the added subproj again, should do nothing' ' ' test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' ' - test_create_repo "$test_count" && - test_create_repo "$test_count/subproj" && + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/subproj" && test_create_commit "$test_count" main1 && test_create_commit "$test_count/subproj" sub1 && ( @@ -427,6 +427,133 @@ test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' ) ' +# +# Tests for 'git subtree pull' +# + +test_expect_success 'pull requires option --prefix' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count/sub proj" sub2 && + ( + cd "$test_count" && + test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err && + + echo "You must provide the --prefix option." >expected && + test_must_be_empty out && + test_cmp expected err + ) +' + +test_expect_success 'pull requires path given by option --prefix must exist' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err && + + echo "'\''sub dir'\'' does not exist; use '\''git subtree add'\''" > expected && + test_must_be_empty out && + test_cmp expected err + ) +' + +test_expect_success 'pull basic operation' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count/sub proj" sub2 && + ( + cd "$test_count" && + exp=$(git -C "sub proj" rev-parse --verify HEAD:) && + git subtree pull --prefix="sub dir" ./"sub proj" HEAD && + act=$(git rev-parse --verify HEAD:"sub dir") && + test "$act" = "$exp" + ) +' + +# +# Tests for 'git subtree push' +# + +test_expect_success 'push requires option --prefix' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD && + echo "You must provide the --prefix option." > expected && + test_must_fail git subtree push "./sub proj" from-mainline > actual 2>&1 && + test_debug "printf '"expected: "'" && + test_debug "cat expected" && + test_debug "printf '"actual: "'" && + test_debug "cat actual" && + test_cmp expected actual + ) +' + +test_expect_success 'push requires path given by option --prefix must exist' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD && + echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected && + test_must_fail git subtree push --prefix=non-existent-directory "./sub proj" from-mainline > actual 2>&1 && + test_debug "printf '"expected: "'" && + test_debug "cat expected" && + test_debug "printf '"actual: "'" && + test_debug "cat actual" && + test_cmp expected actual + ) +' + +test_expect_success 'push basic operation' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree merge --prefix="sub dir" FETCH_HEAD && + before=$(git rev-parse --verify HEAD) && + split_hash=$(git subtree split --prefix="sub dir") && + git subtree push --prefix="sub dir" ./"sub proj" from-mainline && + test "$before" = "$(git rev-parse --verify HEAD)" && + test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" + ) +' + # # Validity checking # From patchwork Fri Apr 23 19:42:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D1ACC43460 for ; Fri, 23 Apr 2021 19:42:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 096186128B for ; Fri, 23 Apr 2021 19:42:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243903AbhDWTnd (ORCPT ); Fri, 23 Apr 2021 15:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243882AbhDWTna (ORCPT ); Fri, 23 Apr 2021 15:43:30 -0400 Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1DE1C06138D for ; Fri, 23 Apr 2021 12:42:52 -0700 (PDT) Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 0207280593; Fri, 23 Apr 2021 15:42:51 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 12/30] subtree: don't have loose code outside of a function Date: Fri, 23 Apr 2021 13:42:12 -0600 Message-Id: <20210423194230.1388945-13-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Shove all of the loose code inside of a main() function. "Ignore space change" is probably helpful when viewing this diff. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 245 +++++++++++++++++---------------- 1 file changed, 125 insertions(+), 120 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 868e18b9a1..d1ed7f9a6c 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -4,10 +4,7 @@ # # Copyright (C) 2009 Avery Pennarun # -if test $# -eq 0 -then - set -- -h -fi + OPTS_SPEC="\ git subtree add --prefix= git subtree add --prefix= @@ -30,12 +27,8 @@ rejoin merge the new branch back into HEAD options for 'add', 'merge', and 'pull' squash merge subtree changes as a single commit " -eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" PATH=$PATH:$(git --exec-path) -. git-sh-setup - -require_work_tree quiet= branch= @@ -84,126 +77,138 @@ ensure_single_rev () { fi } -while test $# -gt 0 -do - opt="$1" - shift +main () { + if test $# -eq 0 + then + set -- -h + fi + eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" + . git-sh-setup + require_work_tree - case "$opt" in - -q) - quiet=1 - ;; - -d) - debug=1 - ;; - --annotate) - annotate="$1" - shift - ;; - --no-annotate) - annotate= - ;; - -b) - branch="$1" - shift - ;; - -P) - prefix="${1%/}" - shift - ;; - -m) - message="$1" - shift - ;; - --no-prefix) - prefix= - ;; - --onto) - onto="$1" + while test $# -gt 0 + do + opt="$1" shift + + case "$opt" in + -q) + quiet=1 + ;; + -d) + debug=1 + ;; + --annotate) + annotate="$1" + shift + ;; + --no-annotate) + annotate= + ;; + -b) + branch="$1" + shift + ;; + -P) + prefix="${1%/}" + shift + ;; + -m) + message="$1" + shift + ;; + --no-prefix) + prefix= + ;; + --onto) + onto="$1" + shift + ;; + --no-onto) + onto= + ;; + --rejoin) + rejoin=1 + ;; + --no-rejoin) + rejoin= + ;; + --ignore-joins) + ignore_joins=1 + ;; + --no-ignore-joins) + ignore_joins= + ;; + --squash) + squash=1 + ;; + --no-squash) + squash= + ;; + --) + break + ;; + *) + die "Unexpected option: $opt" + ;; + esac + done + + command="$1" + shift + + case "$command" in + add|merge|pull) + default= ;; - --no-onto) - onto= - ;; - --rejoin) - rejoin=1 - ;; - --no-rejoin) - rejoin= - ;; - --ignore-joins) - ignore_joins=1 - ;; - --no-ignore-joins) - ignore_joins= - ;; - --squash) - squash=1 + split|push) + default="--default HEAD" ;; - --no-squash) - squash= + *) + die "Unknown command '$command'" ;; - --) - break + esac + + if test -z "$prefix" + then + die "You must provide the --prefix option." + fi + + case "$command" in + add) + test -e "$prefix" && + die "prefix '$prefix' already exists." ;; *) - die "Unexpected option: $opt" + test -e "$prefix" || + die "'$prefix' does not exist; use 'git subtree add'" ;; esac -done - -command="$1" -shift - -case "$command" in -add|merge|pull) - default= - ;; -split|push) - default="--default HEAD" - ;; -*) - die "Unknown command '$command'" - ;; -esac - -if test -z "$prefix" -then - die "You must provide the --prefix option." -fi - -case "$command" in -add) - test -e "$prefix" && - die "prefix '$prefix' already exists." - ;; -*) - test -e "$prefix" || - die "'$prefix' does not exist; use 'git subtree add'" - ;; -esac - -dir="$(dirname "$prefix/.")" - -if test "$command" != "pull" && - test "$command" != "add" && - test "$command" != "push" -then - revs=$(git rev-parse $default --revs-only "$@") || exit $? - dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $? - ensure_single_rev $revs - if test -n "$dirs" - then - die "Error: Use --prefix instead of bare filenames." - fi -fi - -debug "command: {$command}" -debug "quiet: {$quiet}" -debug "revs: {$revs}" -debug "dir: {$dir}" -debug "opts: {$*}" -debug + + dir="$(dirname "$prefix/.")" + + if test "$command" != "pull" && + test "$command" != "add" && + test "$command" != "push" + then + revs=$(git rev-parse $default --revs-only "$@") || exit $? + dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $? + ensure_single_rev $revs + if test -n "$dirs" + then + die "Error: Use --prefix instead of bare filenames." + fi + fi + + debug "command: {$command}" + debug "quiet: {$quiet}" + debug "revs: {$revs}" + debug "dir: {$dir}" + debug "opts: {$*}" + debug + + "cmd_$command" "$@" +} cache_setup () { cachedir="$GIT_DIR/subtree-cache/$$" @@ -898,4 +903,4 @@ cmd_push () { fi } -"cmd_$command" "$@" +main "$@" From patchwork Fri Apr 23 19:42:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52C0AC43460 for ; Fri, 23 Apr 2021 19:43:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D4E16128B for ; Fri, 23 Apr 2021 19:43:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243924AbhDWTng (ORCPT ); Fri, 23 Apr 2021 15:43:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243885AbhDWTna (ORCPT ); Fri, 23 Apr 2021 15:43:30 -0400 Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D2D8C06138E for ; Fri, 23 Apr 2021 12:42:53 -0700 (PDT) Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id DD95680590; Fri, 23 Apr 2021 15:42:52 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 13/30] subtree: more consistent error propagation Date: Fri, 23 Apr 2021 13:42:13 -0600 Message-Id: <20210423194230.1388945-14-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Ensure that every $(subshell) that calls a function (as opposed to an external executable) is followed by `|| exit $?`. Similarly, ensure that every `cmd | while read; do ... done` loop is followed by `|| exit $?`. Both of those constructs mean that it can miss `die` calls, and keep running when it shouldn't. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index d1ed7f9a6c..9ca498f81c 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -243,7 +243,7 @@ cache_miss () { } check_parents () { - missed=$(cache_miss "$1") + missed=$(cache_miss "$1") || exit $? local indent=$(($2 + 1)) for miss in $missed do @@ -345,7 +345,7 @@ find_latest_squash () { sub= ;; esac - done + done || exit $? } find_existing_splits () { @@ -394,7 +394,7 @@ find_existing_splits () { sub= ;; esac - done + done || exit $? } copy_commit () { @@ -508,7 +508,7 @@ subtree_for_commit () { test "$type" = "commit" && continue # ignore submodules echo $tree break - done + done || exit $? } tree_changed () { @@ -518,7 +518,7 @@ tree_changed () { then return 0 # weird parents, consider it changed else - ptree=$(toptree_for_commit $1) + ptree=$(toptree_for_commit $1) || exit $? if test "$ptree" != "$tree" then return 0 # changed @@ -652,7 +652,7 @@ process_split_commit () { progress "$revcount/$revmax ($createcount) [$extracount]" debug "Processing commit: $rev" - exists=$(cache_get "$rev") + exists=$(cache_get "$rev") || exit $? if test -n "$exists" then debug " prior: $exists" @@ -661,10 +661,10 @@ process_split_commit () { createcount=$(($createcount + 1)) debug " parents: $parents" check_parents "$parents" "$indent" - newparents=$(cache_get $parents) + newparents=$(cache_get $parents) || exit $? debug " newparents: $newparents" - tree=$(subtree_for_commit "$rev" "$dir") + tree=$(subtree_for_commit "$rev" "$dir") || exit $? debug " tree is: $tree" # ugly. is there no better way to tell if this is a subtree @@ -750,7 +750,7 @@ cmd_add_commit () { commit=$(add_squashed_msg "$rev" "$dir" | git commit-tree "$tree" $headp -p "$rev") || exit $? else - revp=$(peel_committish "$rev") && + revp=$(peel_committish "$rev") || exit $? commit=$(add_msg "$dir" $headrev "$rev" | git commit-tree "$tree" $headp -p "$revp") || exit $? fi @@ -773,10 +773,10 @@ cmd_split () { # any parent we find there can be used verbatim debug " cache: $rev" cache_set "$rev" "$rev" - done + done || exit $? fi - unrevs="$(find_existing_splits "$dir" "$revs")" + unrevs="$(find_existing_splits "$dir" "$revs")" || exit $? # We can't restrict rev-list to only $dir here, because some of our # parents have the $dir contents the root, and those won't match. @@ -792,7 +792,7 @@ cmd_split () { process_split_commit "$rev" "$parents" 0 done || exit $? - latest_new=$(cache_get latest_new) + latest_new=$(cache_get latest_new) || exit $? if test -z "$latest_new" then die "No new revisions were found" @@ -801,7 +801,7 @@ cmd_split () { if test -n "$rejoin" then debug "Merging split branch into HEAD..." - latest_old=$(cache_get latest_old) + latest_old=$(cache_get latest_old) || exit $? git merge -s ours \ --allow-unrelated-histories \ -m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \ @@ -834,7 +834,7 @@ cmd_merge () { if test -n "$squash" then - first_split="$(find_latest_squash "$dir")" + first_split="$(find_latest_squash "$dir")" || exit $? if test -z "$first_split" then die "Can't squash-merge: '$dir' was never added." From patchwork Fri Apr 23 19:42:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48AEAC433B4 for ; Fri, 23 Apr 2021 19:43:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30F756128B for ; Fri, 23 Apr 2021 19:43:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243897AbhDWTne (ORCPT ); Fri, 23 Apr 2021 15:43:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243889AbhDWTnb (ORCPT ); Fri, 23 Apr 2021 15:43:31 -0400 Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92FB7C061574 for ; Fri, 23 Apr 2021 12:42:54 -0700 (PDT) Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id C527880591; Fri, 23 Apr 2021 15:42:53 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 14/30] subtree: drop support for git < 1.7 Date: Fri, 23 Apr 2021 13:42:14 -0600 Message-Id: <20210423194230.1388945-15-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker That was nice to have when git-subtree lived out-of-tree. But now that it lives in git.git, it's not nescessary to keep around. "Ignore space change" is probably helpful when viewing this diff. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 9ca498f81c..4503564f7e 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -852,23 +852,12 @@ cmd_merge () { rev="$new" fi - version=$(git version) - if test "$version" \< "git version 1.7" + if test -n "$message" then - if test -n "$message" - then - git merge -s subtree --message="$message" "$rev" - else - git merge -s subtree "$rev" - fi + git merge -Xsubtree="$prefix" \ + --message="$message" "$rev" else - if test -n "$message" - then - git merge -Xsubtree="$prefix" \ - --message="$message" "$rev" - else - git merge -Xsubtree="$prefix" $rev - fi + git merge -Xsubtree="$prefix" $rev fi } From patchwork Fri Apr 23 19:42:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E40DC433B4 for ; Fri, 23 Apr 2021 19:43:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38AA36128B for ; Fri, 23 Apr 2021 19:43:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243927AbhDWTni (ORCPT ); Fri, 23 Apr 2021 15:43:38 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35312 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243832AbhDWTnb (ORCPT ); Fri, 23 Apr 2021 15:43:31 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id A309280594; Fri, 23 Apr 2021 15:42:54 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 15/30] subtree: use `git merge-base --is-ancestor` Date: Fri, 23 Apr 2021 13:42:15 -0600 Message-Id: <20210423194230.1388945-16-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Instead of writing a slow `rev_is_descendant_of_branch $a $b` function in shell, just use the fast `git merge-base --is-ancestor $b $a`. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 4503564f7e..70e16b807b 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -280,20 +280,6 @@ rev_exists () { fi } -rev_is_descendant_of_branch () { - newrev="$1" - branch="$2" - branch_hash=$(git rev-parse "$branch") - match=$(git rev-list -1 "$branch_hash" "^$newrev") - - if test -z "$match" - then - return 0 - else - return 1 - fi -} - # if a commit doesn't have a parent, this might not work. But we only want # to remove the parent from the rev-list, and since it doesn't exist, it won't # be there anyway, so do nothing in that case. @@ -811,7 +797,7 @@ cmd_split () { then if rev_exists "refs/heads/$branch" then - if ! rev_is_descendant_of_branch "$latest_new" "$branch" + if ! git merge-base --is-ancestor "$branch" "$latest_new" then die "Branch '$branch' is not an ancestor of commit '$latest_new'." fi From patchwork Fri Apr 23 19:42:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 497A7C43461 for ; Fri, 23 Apr 2021 19:43:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CDE16113B for ; Fri, 23 Apr 2021 19:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243911AbhDWTni (ORCPT ); Fri, 23 Apr 2021 15:43:38 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35334 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243895AbhDWTnc (ORCPT ); Fri, 23 Apr 2021 15:43:32 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 8261280595; Fri, 23 Apr 2021 15:42:55 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 16/30] subtree: use git-sh-setup's `say` Date: Fri, 23 Apr 2021 13:42:16 -0600 Message-Id: <20210423194230.1388945-17-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker subtree currently defines its own `say` implementation, rather than using git-sh-setups's implementation. Change that, don't re-invent the wheel. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 70e16b807b..bb4934dbc0 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -30,7 +30,6 @@ squash merge subtree changes as a single commit PATH=$PATH:$(git --exec-path) -quiet= branch= debug= command= @@ -49,15 +48,8 @@ debug () { fi } -say () { - if test -z "$quiet" - then - printf "%s\n" "$*" >&2 - fi -} - progress () { - if test -z "$quiet" + if test -z "$GIT_QUIET" then printf "%s\r" "$*" >&2 fi @@ -93,7 +85,7 @@ main () { case "$opt" in -q) - quiet=1 + GIT_QUIET=1 ;; -d) debug=1 @@ -201,7 +193,7 @@ main () { fi debug "command: {$command}" - debug "quiet: {$quiet}" + debug "quiet: {$GIT_QUIET}" debug "revs: {$revs}" debug "dir: {$dir}" debug "opts: {$*}" @@ -698,7 +690,7 @@ cmd_add () { cmd_add_repository "$@" else - say "error: parameters were '$@'" + say >&2 "error: parameters were '$@'" die "Provide either a commit or a repository and commit." fi } @@ -742,7 +734,7 @@ cmd_add_commit () { fi git reset "$commit" || exit $? - say "Added dir '$dir'" + say >&2 "Added dir '$dir'" } cmd_split () { @@ -807,7 +799,7 @@ cmd_split () { fi git update-ref -m 'subtree split' \ "refs/heads/$branch" "$latest_new" || exit $? - say "$action branch '$branch'" + say >&2 "$action branch '$branch'" fi echo "$latest_new" exit 0 @@ -830,7 +822,7 @@ cmd_merge () { sub=$2 if test "$sub" = "$rev" then - say "Subtree is already at commit $rev." + say >&2 "Subtree is already at commit $rev." exit 0 fi new=$(new_squash_commit "$old" "$sub" "$rev") || exit $? From patchwork Fri Apr 23 19:42:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45B5BC433B4 for ; Fri, 23 Apr 2021 19:43:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29EC261422 for ; Fri, 23 Apr 2021 19:43:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243937AbhDWTnk (ORCPT ); Fri, 23 Apr 2021 15:43:40 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35312 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243902AbhDWTnd (ORCPT ); Fri, 23 Apr 2021 15:43:33 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 6863280590; Fri, 23 Apr 2021 15:42:56 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 17/30] subtree: use more explicit variable names for cmdline args Date: Fri, 23 Apr 2021 13:42:17 -0600 Message-Id: <20210423194230.1388945-18-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Make it painfully obvious when reading the code which variables are direct parsings of command line arguments. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 132 ++++++++++++++++----------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index bb4934dbc0..d7de4b0653 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -30,19 +30,19 @@ squash merge subtree changes as a single commit PATH=$PATH:$(git --exec-path) -branch= -debug= -command= -onto= -rejoin= -ignore_joins= -annotate= -squash= -message= -prefix= +arg_debug= +arg_command= +arg_prefix= +arg_split_branch= +arg_split_onto= +arg_split_rejoin= +arg_split_ignore_joins= +arg_split_annotate= +arg_addmerge_squash= +arg_addmerge_message= debug () { - if test -n "$debug" + if test -n "$arg_debug" then printf "%s\n" "$*" >&2 fi @@ -88,54 +88,54 @@ main () { GIT_QUIET=1 ;; -d) - debug=1 + arg_debug=1 ;; --annotate) - annotate="$1" + arg_split_annotate="$1" shift ;; --no-annotate) - annotate= + arg_split_annotate= ;; -b) - branch="$1" + arg_split_branch="$1" shift ;; -P) - prefix="${1%/}" + arg_prefix="${1%/}" shift ;; -m) - message="$1" + arg_addmerge_message="$1" shift ;; --no-prefix) - prefix= + arg_prefix= ;; --onto) - onto="$1" + arg_split_onto="$1" shift ;; --no-onto) - onto= + arg_split_onto= ;; --rejoin) - rejoin=1 + arg_split_rejoin=1 ;; --no-rejoin) - rejoin= + arg_split_rejoin= ;; --ignore-joins) - ignore_joins=1 + arg_split_ignore_joins=1 ;; --no-ignore-joins) - ignore_joins= + arg_split_ignore_joins= ;; --squash) - squash=1 + arg_addmerge_squash=1 ;; --no-squash) - squash= + arg_addmerge_squash= ;; --) break @@ -146,10 +146,10 @@ main () { esac done - command="$1" + arg_command="$1" shift - case "$command" in + case "$arg_command" in add|merge|pull) default= ;; @@ -157,31 +157,31 @@ main () { default="--default HEAD" ;; *) - die "Unknown command '$command'" + die "Unknown command '$arg_command'" ;; esac - if test -z "$prefix" + if test -z "$arg_prefix" then die "You must provide the --prefix option." fi - case "$command" in + case "$arg_command" in add) - test -e "$prefix" && - die "prefix '$prefix' already exists." + test -e "$arg_prefix" && + die "prefix '$arg_prefix' already exists." ;; *) - test -e "$prefix" || - die "'$prefix' does not exist; use 'git subtree add'" + test -e "$arg_prefix" || + die "'$arg_prefix' does not exist; use 'git subtree add'" ;; esac - dir="$(dirname "$prefix/.")" + dir="$(dirname "$arg_prefix/.")" - if test "$command" != "pull" && - test "$command" != "add" && - test "$command" != "push" + if test "$arg_command" != "pull" && + test "$arg_command" != "add" && + test "$arg_command" != "push" then revs=$(git rev-parse $default --revs-only "$@") || exit $? dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $? @@ -192,14 +192,14 @@ main () { fi fi - debug "command: {$command}" + debug "command: {$arg_command}" debug "quiet: {$GIT_QUIET}" debug "revs: {$revs}" debug "dir: {$dir}" debug "opts: {$*}" debug - "cmd_$command" "$@" + "cmd_$arg_command" "$@" } cache_setup () { @@ -333,7 +333,7 @@ find_existing_splits () { main= sub= local grep_format="^git-subtree-dir: $dir/*\$" - if test -n "$ignore_joins" + if test -n "$arg_split_ignore_joins" then grep_format="^Add '$dir/' from commit '" fi @@ -394,7 +394,7 @@ copy_commit () { GIT_COMMITTER_EMAIL \ GIT_COMMITTER_DATE ( - printf "%s" "$annotate" + printf "%s" "$arg_split_annotate" cat ) | git commit-tree "$2" $3 # reads the rest of stdin @@ -405,9 +405,9 @@ add_msg () { dir="$1" latest_old="$2" latest_new="$3" - if test -n "$message" + if test -n "$arg_addmerge_message" then - commit_message="$message" + commit_message="$arg_addmerge_message" else commit_message="Add '$dir/' from commit '$latest_new'" fi @@ -421,9 +421,9 @@ add_msg () { } add_squashed_msg () { - if test -n "$message" + if test -n "$arg_addmerge_message" then - echo "$message" + echo "$arg_addmerge_message" else echo "Merge commit '$1' as '$2'" fi @@ -433,9 +433,9 @@ rejoin_msg () { dir="$1" latest_old="$2" latest_new="$3" - if test -n "$message" + if test -n "$arg_addmerge_message" then - commit_message="$message" + commit_message="$arg_addmerge_message" else commit_message="Split '$dir/' into commit '$latest_new'" fi @@ -722,7 +722,7 @@ cmd_add_commit () { headp= fi - if test -n "$squash" + if test -n "$arg_addmerge_squash" then rev=$(new_squash_commit "" "" "$rev") || exit $? commit=$(add_squashed_msg "$rev" "$dir" | @@ -741,10 +741,10 @@ cmd_split () { debug "Splitting $dir..." cache_setup || exit $? - if test -n "$onto" + if test -n "$arg_split_onto" then - debug "Reading history for --onto=$onto..." - git rev-list $onto | + debug "Reading history for --onto=$arg_split_onto..." + git rev-list $arg_split_onto | while read rev do # the 'onto' history is already just the subdir, so @@ -776,7 +776,7 @@ cmd_split () { die "No new revisions were found" fi - if test -n "$rejoin" + if test -n "$arg_split_rejoin" then debug "Merging split branch into HEAD..." latest_old=$(cache_get latest_old) || exit $? @@ -785,21 +785,21 @@ cmd_split () { -m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \ "$latest_new" >&2 || exit $? fi - if test -n "$branch" + if test -n "$arg_split_branch" then - if rev_exists "refs/heads/$branch" + if rev_exists "refs/heads/$arg_split_branch" then - if ! git merge-base --is-ancestor "$branch" "$latest_new" + if ! git merge-base --is-ancestor "$arg_split_branch" "$latest_new" then - die "Branch '$branch' is not an ancestor of commit '$latest_new'." + die "Branch '$arg_split_branch' is not an ancestor of commit '$latest_new'." fi action='Updated' else action='Created' fi git update-ref -m 'subtree split' \ - "refs/heads/$branch" "$latest_new" || exit $? - say >&2 "$action branch '$branch'" + "refs/heads/$arg_split_branch" "$latest_new" || exit $? + say >&2 "$action branch '$arg_split_branch'" fi echo "$latest_new" exit 0 @@ -810,7 +810,7 @@ cmd_merge () { ensure_single_rev $rev ensure_clean - if test -n "$squash" + if test -n "$arg_addmerge_squash" then first_split="$(find_latest_squash "$dir")" || exit $? if test -z "$first_split" @@ -830,12 +830,12 @@ cmd_merge () { rev="$new" fi - if test -n "$message" + if test -n "$arg_addmerge_message" then - git merge -Xsubtree="$prefix" \ - --message="$message" "$rev" + git merge -Xsubtree="$arg_prefix" \ + --message="$arg_addmerge_message" "$rev" else - git merge -Xsubtree="$prefix" $rev + git merge -Xsubtree="$arg_prefix" $rev fi } @@ -863,7 +863,7 @@ cmd_push () { repository=$1 refspec=$2 echo "git push using: " "$repository" "$refspec" - localrev=$(git subtree split --prefix="$prefix") || die + localrev=$(git subtree split --prefix="$arg_prefix") || die git push "$repository" "$localrev":"refs/heads/$refspec" else die "'$dir' must already exist. Try 'git subtree add'." From patchwork Fri Apr 23 19:42:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221605 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92089C43460 for ; Fri, 23 Apr 2021 19:43:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6860461075 for ; Fri, 23 Apr 2021 19:43:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243958AbhDWTnl (ORCPT ); Fri, 23 Apr 2021 15:43:41 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35334 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243799AbhDWTne (ORCPT ); Fri, 23 Apr 2021 15:43:34 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 504E680596; Fri, 23 Apr 2021 15:42:57 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 18/30] subtree: use $* instead of $@ as appropriate Date: Fri, 23 Apr 2021 13:42:18 -0600 Message-Id: <20210423194230.1388945-19-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker $* is for when you want to smash things together, whitespace-separated; $@ is for when you want them to be separate strings. There are a couple of places in subtree that erroneously use $@ when smashing args together in to an error message. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index d7de4b0653..3105eb8033 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -58,14 +58,14 @@ progress () { assert () { if ! "$@" then - die "assertion failed: " "$@" + die "assertion failed: $*" fi } ensure_single_rev () { if test $# -ne 1 then - die "You must provide exactly one revision. Got: '$@'" + die "You must provide exactly one revision. Got: '$*'" fi } @@ -690,7 +690,7 @@ cmd_add () { cmd_add_repository "$@" else - say >&2 "error: parameters were '$@'" + say >&2 "error: parameters were '$*'" die "Provide either a commit or a repository and commit." fi } From patchwork Fri Apr 23 19:42:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3B9AC433ED for ; Fri, 23 Apr 2021 19:43:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C82C2613C3 for ; Fri, 23 Apr 2021 19:43:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243923AbhDWTnn (ORCPT ); Fri, 23 Apr 2021 15:43:43 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35312 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243905AbhDWTnf (ORCPT ); Fri, 23 Apr 2021 15:43:35 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 2AC9680591; Fri, 23 Apr 2021 15:42:58 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 19/30] subtree: give `$(git --exec-path)` precedence over `$PATH` Date: Fri, 23 Apr 2021 13:42:19 -0600 Message-Id: <20210423194230.1388945-20-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Other Git commands implemented in shell give `git --exec-path` precedence over the existing $PATH, but subtree gives the existing $PATH precedence. Flip subtree's PATH around to match what other commands do. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 3105eb8033..9d365c9f2f 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -28,7 +28,7 @@ rejoin merge the new branch back into HEAD squash merge subtree changes as a single commit " -PATH=$PATH:$(git --exec-path) +PATH=$(git --exec-path):$PATH arg_debug= arg_command= From patchwork Fri Apr 23 19:42:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09694C433B4 for ; Fri, 23 Apr 2021 19:43:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2192613C3 for ; Fri, 23 Apr 2021 19:43:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243973AbhDWTno (ORCPT ); Fri, 23 Apr 2021 15:43:44 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35334 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243880AbhDWTng (ORCPT ); Fri, 23 Apr 2021 15:43:36 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id F127D80594; Fri, 23 Apr 2021 15:42:58 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 20/30] subtree: use "^{commit}" instead of "^0" Date: Fri, 23 Apr 2021 13:42:20 -0600 Message-Id: <20210423194230.1388945-21-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker They are synonyms. Both are used in the file. ^{commit} is clearer, so "standardize" on that. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 9d365c9f2f..d200fbfed7 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -302,7 +302,7 @@ find_latest_squash () { main="$b" ;; git-subtree-split:) - sub="$(git rev-parse "$b^0")" || + sub="$(git rev-parse "$b^{commit}")" || die "could not rev-parse split hash $b from commit $sq" ;; END) @@ -349,7 +349,7 @@ find_existing_splits () { main="$b" ;; git-subtree-split:) - sub="$(git rev-parse "$b^0")" || + sub="$(git rev-parse "$b^{commit}")" || die "could not rev-parse split hash $b from commit $sq" ;; END) From patchwork Fri Apr 23 19:42:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89464C433B4 for ; Fri, 23 Apr 2021 19:43:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67BF7610A2 for ; Fri, 23 Apr 2021 19:43:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243977AbhDWTnp (ORCPT ); Fri, 23 Apr 2021 15:43:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243904AbhDWTni (ORCPT ); Fri, 23 Apr 2021 15:43:38 -0400 Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C684CC061574 for ; Fri, 23 Apr 2021 12:43:00 -0700 (PDT) Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id CAD4F80590; Fri, 23 Apr 2021 15:42:59 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 21/30] subtree: parse revs in individual cmd_ functions Date: Fri, 23 Apr 2021 13:42:21 -0600 Message-Id: <20210423194230.1388945-22-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker The main argument parser goes ahead and tries to parse revs to make things simpler for the sub-command implementations. But, it includes enough special cases for different sub-commands. And it's difficult having having to think about "is this info coming from an argument, or a global variable?". So the main argument parser's effort to make things "simpler" ends up just making it more confusing and complicated. Begone with the 'revs' global variable; parse 'rev=$(...)' as needed in individual 'cmd_*' functions. Begone with the 'default' global variable. Its would-be value is knowable just from which function we're in. Begone with the 'ensure_single_rev' function. Its functionality can be achieved by passing '--verify' to 'git rev-parse'. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 62 +++++++++++++--------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index d200fbfed7..2efad85768 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -62,13 +62,6 @@ assert () { fi } -ensure_single_rev () { - if test $# -ne 1 - then - die "You must provide exactly one revision. Got: '$*'" - fi -} - main () { if test $# -eq 0 then @@ -150,11 +143,8 @@ main () { shift case "$arg_command" in - add|merge|pull) - default= - ;; - split|push) - default="--default HEAD" + add|merge|pull|split|push) + : ;; *) die "Unknown command '$arg_command'" @@ -179,22 +169,8 @@ main () { dir="$(dirname "$arg_prefix/.")" - if test "$arg_command" != "pull" && - test "$arg_command" != "add" && - test "$arg_command" != "push" - then - revs=$(git rev-parse $default --revs-only "$@") || exit $? - dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $? - ensure_single_rev $revs - if test -n "$dirs" - then - die "Error: Use --prefix instead of bare filenames." - fi - fi - debug "command: {$arg_command}" debug "quiet: {$GIT_QUIET}" - debug "revs: {$revs}" debug "dir: {$dir}" debug "opts: {$*}" debug @@ -700,14 +676,13 @@ cmd_add_repository () { repository=$1 refspec=$2 git fetch "$@" || exit $? - revs=FETCH_HEAD - set -- $revs - cmd_add_commit "$@" + cmd_add_commit FETCH_HEAD } cmd_add_commit () { - rev=$(git rev-parse $default --revs-only "$@") || exit $? - ensure_single_rev $rev + # The rev has already been validated by cmd_add(), we just + # need to normalize it. + rev=$(git rev-parse --verify "$1^{commit}") || exit $? debug "Adding $dir as '$rev'..." git read-tree --prefix="$dir" $rev || exit $? @@ -738,6 +713,17 @@ cmd_add_commit () { } cmd_split () { + if test $# -eq 0 + then + rev=$(git rev-parse HEAD) + elif test $# -eq 1 + then + rev=$(git rev-parse -q --verify "$1^{commit}") || + die "'$1' does not refer to a commit" + else + die "You must provide exactly one revision. Got: '$*'" + fi + debug "Splitting $dir..." cache_setup || exit $? @@ -754,12 +740,12 @@ cmd_split () { done || exit $? fi - unrevs="$(find_existing_splits "$dir" "$revs")" || exit $? + unrevs="$(find_existing_splits "$dir" "$rev")" || exit $? # We can't restrict rev-list to only $dir here, because some of our # parents have the $dir contents the root, and those won't match. # (and rev-list --follow doesn't seem to solve this) - grl='git rev-list --topo-order --reverse --parents $revs $unrevs' + grl='git rev-list --topo-order --reverse --parents $rev $unrevs' revmax=$(eval "$grl" | wc -l) revcount=0 createcount=0 @@ -806,8 +792,10 @@ cmd_split () { } cmd_merge () { - rev=$(git rev-parse $default --revs-only "$@") || exit $? - ensure_single_rev $rev + test $# -eq 1 || + die "You must provide exactly one revision. Got: '$*'" + rev=$(git rev-parse -q --verify "$1^{commit}") || + die "'$1' does not refer to a commit" ensure_clean if test -n "$arg_addmerge_squash" @@ -847,9 +835,7 @@ cmd_pull () { ensure_clean ensure_valid_ref_format "$2" git fetch "$@" || exit $? - revs=FETCH_HEAD - set -- $revs - cmd_merge "$@" + cmd_merge FETCH_HEAD } cmd_push () { From patchwork Fri Apr 23 19:42:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F354C433ED for ; Fri, 23 Apr 2021 19:43:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64CF361075 for ; Fri, 23 Apr 2021 19:43:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243956AbhDWTnu (ORCPT ); Fri, 23 Apr 2021 15:43:50 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35312 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243885AbhDWTni (ORCPT ); Fri, 23 Apr 2021 15:43:38 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id A7E8B80595; Fri, 23 Apr 2021 15:43:00 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 22/30] subtree: remove duplicate check Date: Fri, 23 Apr 2021 13:42:22 -0600 Message-Id: <20210423194230.1388945-23-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker `cmd_add` starts with a check that the directory doesn't yet exist. However, the `main` function performs the exact same check before calling `cmd_add`. So remove the check from `cmd_add`. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 2efad85768..04dfaf443e 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -641,10 +641,6 @@ process_split_commit () { } cmd_add () { - if test -e "$dir" - then - die "'$dir' already exists. Cannot add." - fi ensure_clean From patchwork Fri Apr 23 19:42:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 005FDC433B4 for ; Fri, 23 Apr 2021 19:43:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7CFF6113B for ; Fri, 23 Apr 2021 19:43:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244008AbhDWTny (ORCPT ); Fri, 23 Apr 2021 15:43:54 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35334 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243930AbhDWTni (ORCPT ); Fri, 23 Apr 2021 15:43:38 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 6EDE980594; Fri, 23 Apr 2021 15:43:01 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 23/30] subtree: add comments and sanity checks Date: Fri, 23 Apr 2021 13:42:23 -0600 Message-Id: <20210423194230.1388945-24-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 62 ++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 04dfaf443e..ddfa74c3bf 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -41,6 +41,7 @@ arg_split_annotate= arg_addmerge_squash= arg_addmerge_message= +# Usage: debug [MSG...] debug () { if test -n "$arg_debug" then @@ -48,6 +49,7 @@ debug () { fi } +# Usage: progress [MSG...] progress () { if test -z "$GIT_QUIET" then @@ -55,6 +57,7 @@ progress () { fi } +# Usage: assert CMD... assert () { if ! "$@" then @@ -178,7 +181,9 @@ main () { "cmd_$arg_command" "$@" } +# Usage: cache_setup cache_setup () { + assert test $# = 0 cachedir="$GIT_DIR/subtree-cache/$$" rm -rf "$cachedir" || die "Can't delete old cachedir: $cachedir" @@ -189,6 +194,7 @@ cache_setup () { debug "Using cachedir: $cachedir" >&2 } +# Usage: cache_get [REVS...] cache_get () { for oldrev in "$@" do @@ -200,6 +206,7 @@ cache_get () { done } +# Usage: cache_miss [REVS...] cache_miss () { for oldrev in "$@" do @@ -210,7 +217,9 @@ cache_miss () { done } +# Usage: check_parents PARENTS_EXPR INDENT check_parents () { + assert test $# = 2 missed=$(cache_miss "$1") || exit $? local indent=$(($2 + 1)) for miss in $missed @@ -223,11 +232,15 @@ check_parents () { done } +# Usage: set_notree REV set_notree () { + assert test $# = 1 echo "1" > "$cachedir/notree/$1" } +# Usage: cache_set OLDREV NEWREV cache_set () { + assert test $# = 2 oldrev="$1" newrev="$2" if test "$oldrev" != "latest_old" && @@ -239,7 +252,9 @@ cache_set () { echo "$newrev" >"$cachedir/$oldrev" } +# Usage: rev_exists REV rev_exists () { + assert test $# = 1 if git rev-parse "$1" >/dev/null 2>&1 then return 0 @@ -248,17 +263,22 @@ rev_exists () { fi } +# Usage: try_remove_previous REV +# # if a commit doesn't have a parent, this might not work. But we only want # to remove the parent from the rev-list, and since it doesn't exist, it won't # be there anyway, so do nothing in that case. try_remove_previous () { + assert test $# = 1 if rev_exists "$1^" then echo "^$1^" fi } +# Usage: find_latest_squash DIR find_latest_squash () { + assert test $# = 1 debug "Looking for latest squash ($dir)..." dir="$1" sq= @@ -302,10 +322,12 @@ find_latest_squash () { done || exit $? } +# Usage: find_existing_splits DIR REV find_existing_splits () { + assert test $# = 2 debug "Looking for prior splits..." dir="$1" - revs="$2" + rev="$2" main= sub= local grep_format="^git-subtree-dir: $dir/*\$" @@ -314,7 +336,7 @@ find_existing_splits () { grep_format="^Add '$dir/' from commit '" fi git log --grep="$grep_format" \ - --no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs | + --no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' "$rev" | while read a b junk do case "$a" in @@ -351,7 +373,9 @@ find_existing_splits () { done || exit $? } +# Usage: copy_commit REV TREE FLAGS_STR copy_commit () { + assert test $# = 3 # We're going to set some environment vars here, so # do it in a subshell to get rid of them safely later debug copy_commit "{$1}" "{$2}" "{$3}" @@ -377,7 +401,9 @@ copy_commit () { ) || die "Can't copy commit $1" } +# Usage: add_msg DIR LATEST_OLD LATEST_NEW add_msg () { + assert test $# = 3 dir="$1" latest_old="$2" latest_new="$3" @@ -396,7 +422,9 @@ add_msg () { EOF } +# Usage: add_squashed_msg REV DIR add_squashed_msg () { + assert test $# = 2 if test -n "$arg_addmerge_message" then echo "$arg_addmerge_message" @@ -405,7 +433,9 @@ add_squashed_msg () { fi } +# Usage: rejoin_msg DIR LATEST_OLD LATEST_NEW rejoin_msg () { + assert test $# = 3 dir="$1" latest_old="$2" latest_new="$3" @@ -424,7 +454,9 @@ rejoin_msg () { EOF } +# Usage: squash_msg DIR OLD_SUBTREE_COMMIT NEW_SUBTREE_COMMIT squash_msg () { + assert test $# = 3 dir="$1" oldsub="$2" newsub="$3" @@ -446,12 +478,16 @@ squash_msg () { echo "git-subtree-split: $newsub" } +# Usage: toptree_for_commit COMMIT toptree_for_commit () { + assert test $# = 1 commit="$1" git rev-parse --verify "$commit^{tree}" || exit $? } +# Usage: subtree_for_commit COMMIT DIR subtree_for_commit () { + assert test $# = 2 commit="$1" dir="$2" git ls-tree "$commit" -- "$dir" | @@ -465,7 +501,9 @@ subtree_for_commit () { done || exit $? } +# Usage: tree_changed TREE [PARENTS...] tree_changed () { + assert test $# -gt 0 tree=$1 shift if test $# -ne 1 @@ -482,7 +520,9 @@ tree_changed () { fi } +# Usage: new_squash_commit OLD_SQUASHED_COMMIT OLD_NONSQUASHED_COMMIT NEW_NONSQUASHED_COMMIT new_squash_commit () { + assert test $# = 3 old="$1" oldsub="$2" newsub="$3" @@ -497,7 +537,9 @@ new_squash_commit () { fi } +# Usage: copy_or_skip REV TREE NEWPARENTS copy_or_skip () { + assert test $# = 3 rev="$1" tree="$2" newparents="$3" @@ -572,7 +614,9 @@ copy_or_skip () { fi } +# Usage: ensure_clean ensure_clean () { + assert test $# = 0 if ! git diff-index HEAD --exit-code --quiet 2>&1 then die "Working tree has modifications. Cannot add." @@ -583,12 +627,16 @@ ensure_clean () { fi } +# Usage: ensure_valid_ref_format REF ensure_valid_ref_format () { + assert test $# = 1 git check-ref-format "refs/heads/$1" || die "'$1' does not look like a ref" } +# Usage: process_split_commit REV PARENTS INDENT process_split_commit () { + assert test $# = 3 local rev="$1" local parents="$2" local indent=$3 @@ -640,6 +688,8 @@ process_split_commit () { cache_set latest_old "$rev" } +# Usage: cmd_add REV +# Or: cmd_add REPOSITORY REF cmd_add () { ensure_clean @@ -667,7 +717,9 @@ cmd_add () { fi } +# Usage: cmd_add_repository REPOSITORY REFSPEC cmd_add_repository () { + assert test $# = 2 echo "git fetch" "$@" repository=$1 refspec=$2 @@ -675,9 +727,11 @@ cmd_add_repository () { cmd_add_commit FETCH_HEAD } +# Usage: cmd_add_commit REV cmd_add_commit () { # The rev has already been validated by cmd_add(), we just # need to normalize it. + assert test $# = 1 rev=$(git rev-parse --verify "$1^{commit}") || exit $? debug "Adding $dir as '$rev'..." @@ -708,6 +762,7 @@ cmd_add_commit () { say >&2 "Added dir '$dir'" } +# Usage: cmd_split [REV] cmd_split () { if test $# -eq 0 then @@ -787,6 +842,7 @@ cmd_split () { exit 0 } +# Usage: cmd_merge REV cmd_merge () { test $# -eq 1 || die "You must provide exactly one revision. Got: '$*'" @@ -823,6 +879,7 @@ cmd_merge () { fi } +# Usage: cmd_pull REPOSITORY REMOTEREF cmd_pull () { if test $# -ne 2 then @@ -834,6 +891,7 @@ cmd_pull () { cmd_merge FETCH_HEAD } +# Usage: cmd_push REPOSITORY REMOTEREF cmd_push () { if test $# -ne 2 then From patchwork Fri Apr 23 19:42:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA302C43460 for ; Fri, 23 Apr 2021 19:43:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A2166113B for ; Fri, 23 Apr 2021 19:43:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244014AbhDWTnz (ORCPT ); Fri, 23 Apr 2021 15:43:55 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35450 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243932AbhDWTnk (ORCPT ); Fri, 23 Apr 2021 15:43:40 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 560FD80596; Fri, 23 Apr 2021 15:43:02 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 24/30] subtree: don't let debug and progress output clash Date: Fri, 23 Apr 2021 13:42:24 -0600 Message-Id: <20210423194230.1388945-25-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Currently, debug output (triggered by passing '-d') and progress output stomp on eachother. The debug output is just streamed as lines to stderr, and the progress output is sent to stderr as '%s\r'. It is difficult to distinguish between the debug output and a progress line. When writing to a terminal the debug lines hide progress lines. So, when '-d' has been passed, spit out progress as 'progress: %s\n', instead of as '%s\r', so that it can be detected, and so that the debug lines don't overwrite the progress when written to a terminal. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index ddfa74c3bf..62cf54928e 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -53,7 +53,12 @@ debug () { progress () { if test -z "$GIT_QUIET" then - printf "%s\r" "$*" >&2 + if test -n "$arg_debug" + then + printf "progress: %s\n" "$*" >&2 + else + printf "%s\r" "$*" >&2 + fi fi } From patchwork Fri Apr 23 19:42:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33E42C433ED for ; Fri, 23 Apr 2021 19:43:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B46D6113B for ; Fri, 23 Apr 2021 19:43:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244016AbhDWTn4 (ORCPT ); Fri, 23 Apr 2021 15:43:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243926AbhDWTnl (ORCPT ); Fri, 23 Apr 2021 15:43:41 -0400 Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3719C06175F for ; Fri, 23 Apr 2021 12:43:03 -0700 (PDT) Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 4BAB580597; Fri, 23 Apr 2021 15:43:03 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 25/30] subtree: have $indent actually affect indentation Date: Fri, 23 Apr 2021 13:42:25 -0600 Message-Id: <20210423194230.1388945-26-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Currently, the $indent variable is just used to track how deeply we're nested, and the debug log is indented by things like debug " foo" That is: The indentation-level is hard-coded. It used to be that the code couldn't recurse, so the indentation level could be known statically, so it made sense to just hard-code it in the output. However, since 315a84f9aa ("subtree: use commits before rejoins for splits", 2018-09-28), it can now recurse, and the debug log is misleading. So fix that. Indent according to $indent. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 42 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 62cf54928e..54e904516b 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -41,11 +41,13 @@ arg_split_annotate= arg_addmerge_squash= arg_addmerge_message= +indent=0 + # Usage: debug [MSG...] debug () { if test -n "$arg_debug" then - printf "%s\n" "$*" >&2 + printf "%$(($indent * 2))s%s\n" '' "$*" >&2 fi } @@ -222,17 +224,17 @@ cache_miss () { done } -# Usage: check_parents PARENTS_EXPR INDENT +# Usage: check_parents PARENTS_EXPR check_parents () { - assert test $# = 2 + assert test $# = 1 missed=$(cache_miss "$1") || exit $? - local indent=$(($2 + 1)) + local indent=$(($indent + 1)) for miss in $missed do if ! test -r "$cachedir/notree/$miss" then - debug " incorrect order: $miss" - process_split_commit "$miss" "" "$indent" + debug "incorrect order: $miss" + process_split_commit "$miss" "" fi done } @@ -285,6 +287,8 @@ try_remove_previous () { find_latest_squash () { assert test $# = 1 debug "Looking for latest squash ($dir)..." + local indent=$(($indent + 1)) + dir="$1" sq= main= @@ -331,6 +335,8 @@ find_latest_squash () { find_existing_splits () { assert test $# = 2 debug "Looking for prior splits..." + local indent=$(($indent + 1)) + dir="$1" rev="$2" main= @@ -356,7 +362,7 @@ find_existing_splits () { die "could not rev-parse split hash $b from commit $sq" ;; END) - debug " Main is: '$main'" + debug "Main is: '$main'" if test -z "$main" -a -n "$sub" then # squash commits refer to a subtree @@ -639,12 +645,11 @@ ensure_valid_ref_format () { die "'$1' does not look like a ref" } -# Usage: process_split_commit REV PARENTS INDENT +# Usage: process_split_commit REV PARENTS process_split_commit () { - assert test $# = 3 + assert test $# = 2 local rev="$1" local parents="$2" - local indent=$3 if test $indent -eq 0 then @@ -659,20 +664,21 @@ process_split_commit () { progress "$revcount/$revmax ($createcount) [$extracount]" debug "Processing commit: $rev" + local indent=$(($indent + 1)) exists=$(cache_get "$rev") || exit $? if test -n "$exists" then - debug " prior: $exists" + debug "prior: $exists" return fi createcount=$(($createcount + 1)) - debug " parents: $parents" - check_parents "$parents" "$indent" + debug "parents: $parents" + check_parents "$parents" newparents=$(cache_get $parents) || exit $? - debug " newparents: $newparents" + debug "newparents: $newparents" tree=$(subtree_for_commit "$rev" "$dir") || exit $? - debug " tree is: $tree" + debug "tree is: $tree" # ugly. is there no better way to tell if this is a subtree # vs. a mainline commit? Does it matter? @@ -687,7 +693,7 @@ process_split_commit () { fi newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $? - debug " newrev is: $newrev" + debug "newrev is: $newrev" cache_set "$rev" "$newrev" cache_set latest_new "$newrev" cache_set latest_old "$rev" @@ -791,7 +797,7 @@ cmd_split () { do # the 'onto' history is already just the subdir, so # any parent we find there can be used verbatim - debug " cache: $rev" + debug "cache: $rev" cache_set "$rev" "$rev" done || exit $? fi @@ -809,7 +815,7 @@ cmd_split () { eval "$grl" | while read rev parents do - process_split_commit "$rev" "$parents" 0 + process_split_commit "$rev" "$parents" done || exit $? latest_new=$(cache_get latest_new) || exit $? From patchwork Fri Apr 23 19:42:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55EE6C433B4 for ; Fri, 23 Apr 2021 19:43:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3958161075 for ; Fri, 23 Apr 2021 19:43:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243952AbhDWTn6 (ORCPT ); Fri, 23 Apr 2021 15:43:58 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35312 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243951AbhDWTnl (ORCPT ); Fri, 23 Apr 2021 15:43:41 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 2E08380598; Fri, 23 Apr 2021 15:43:04 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 26/30] subtree: give the docs a once-over Date: Fri, 23 Apr 2021 13:42:26 -0600 Message-Id: <20210423194230.1388945-27-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Just went through the docs looking for anything inaccurate or that can be improved. In the '-h' text, in the man page synopsis, and in the man page description: Normalize the ordering of the list of sub-commands: 'add', 'merge', 'split', 'pull', 'push'. This allows us to kinda separate the lower-level add/merge/split from the higher-level pull/push. '-h' text: - correction: Indicate that split's arg is optional. - clarity: Emphasize that 'pull' takes the 'add'/'merge' flags. man page: - correction: State that all subcommands take options (it seemed to indicate that only 'split' takes any options other than '-P'). - correction: 'split' only guarantees that the results are identical if the flags are identical. - completeness: Clarify that 'push' always operates on HEAD, and that 'split' operates on HEAD if no local commit is given. - clarity: In the description, when listing commands, repeat what their arguments are. This way the reader doesn't need to flip back and forth between the command description and the synopsis and the full description to understand what's being said. - clarity: In the used to give command arguments, give slightly longer, descriptive names. Like instead of just . - clarity: Emphasize that 'pull' takes the 'add'/'merge' flags. - style: In the synopsis, list options before the subcommand. This makes things line up and be much more readable when shown non-monospace (such as in `make html`), and also more closely matches other man pages (like `git-submodule.txt`). - style: Use the correct syntax for indicating the options ([] instead of [OPTIONS]). - style: In the synopsis, separate 'pull' and 'push' from the other lower-level commands. I think this helps readability. - style: Code-quote things in prose that seem like they should be code-quoted, like '.gitmodules', flags, or full commands. - style: Minor wording improvements, like more consistent mood (many of the command descriptions start in the imperative mood and switch to the indicative mode by the end). That sort of thing. - style: Capitalize "ID". - style: Remove the "This option is only valid for XXX command" remarks from each option, and instead rely on the section headings. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 4 +- contrib/subtree/git-subtree.txt | 162 +++++++++++++++----------------- 2 files changed, 80 insertions(+), 86 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 54e904516b..4d0be1ad5c 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -9,9 +9,9 @@ OPTS_SPEC="\ git subtree add --prefix= git subtree add --prefix= git subtree merge --prefix= +git subtree split --prefix= [] git subtree pull --prefix= git subtree push --prefix= -git subtree split --prefix= -- h,help show the help q quiet @@ -24,7 +24,7 @@ b,branch= create a new branch from the split subtree ignore-joins ignore prior --rejoin commits onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD - options for 'add', 'merge', and 'pull' + options for 'add' and 'merge' (also: 'pull') squash merge subtree changes as a single commit " diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt index 0db02fe3c0..5728778bdf 100644 --- a/contrib/subtree/git-subtree.txt +++ b/contrib/subtree/git-subtree.txt @@ -9,13 +9,14 @@ git-subtree - Merge subtrees together and split repository into subtrees SYNOPSIS -------- [verse] -'git subtree' add -P -'git subtree' add -P -'git subtree' pull -P -'git subtree' push -P -'git subtree' merge -P -'git subtree' split -P [OPTIONS] [] +'git subtree' [] -P add +'git subtree' [] -P add +'git subtree' [] -P merge +'git subtree' [] -P split [] +[verse] +'git subtree' [] -P pull +'git subtree' [] -P push DESCRIPTION ----------- @@ -28,7 +29,7 @@ as a subdirectory of your application. Subtrees are not to be confused with submodules, which are meant for the same task. Unlike submodules, subtrees do not need any special -constructions (like .gitmodules files or gitlinks) be present in +constructions (like '.gitmodules' files or gitlinks) be present in your repository, and do not force end-users of your repository to do anything special or to understand how subtrees work. A subtree is just a subdirectory that can be @@ -59,27 +60,28 @@ project as much as possible. That is, if you make a change that affects both the library and the main application, commit it in two pieces. That way, when you split the library commits out later, their descriptions will still make sense. But if this -isn't important to you, it's not *necessary*. git subtree will +isn't important to you, it's not *necessary*. 'git subtree' will simply leave out the non-library-related parts of the commit when it splits it out into the subproject later. COMMANDS -------- -add:: +add :: +add :: Create the subtree by importing its contents - from the given or and remote . + from the given or and . A new commit is created automatically, joining the imported - project's history with your own. With '--squash', imports + project's history with your own. With '--squash', import only a single commit from the subproject, rather than its entire history. -merge:: - Merge recent changes up to into the +merge :: + Merge recent changes up to into the subtree. As with normal 'git merge', this doesn't remove your own local changes; it just merges those - changes into the latest . With '--squash', - creates only one commit that contains all the changes, + changes into the latest . With '--squash', + create only one commit that contains all the changes, rather than merging in the entire history. + If you use '--squash', the merge direction doesn't always have to be @@ -87,39 +89,40 @@ forward; you can use this command to go back in time from v2.5 to v2.4, for example. If your merge introduces a conflict, you can resolve it in the usual ways. -pull:: - Exactly like 'merge', but parallels 'git pull' in that - it fetches the given ref from the specified remote - repository. - -push:: - Does a 'split' (see below) using the supplied - and then does a 'git push' to push the result to the - repository and ref. This can be used to push your - subtree to different branches of the remote repository. - -split:: +split []:: Extract a new, synthetic project history from the - history of the subtree. The new history + history of the subtree of , or of + HEAD if no is given. The new history includes only the commits (including merges) that affected , and each of those commits now has the contents of at the root of the project instead of in a subdirectory. Thus, the newly created history is suitable for export as a separate git repository. + -After splitting successfully, a single commit id is printed to stdout. +After splitting successfully, a single commit ID is printed to stdout. This corresponds to the HEAD of the newly created tree, which you can manipulate however you want. + Repeated splits of exactly the same history are guaranteed to be -identical (i.e. to produce the same commit ids). Because of this, if -you add new commits and then re-split, the new commits will be attached -as commits on top of the history you generated last time, so 'git merge' -and friends will work as expected. +identical (i.e. to produce the same commit IDs) as long as the +settings passed to 'split' (such as '--annotate') are the same. +Because of this, if you add new commits and then re-split, the new +commits will be attached as commits on top of the history you +generated last time, so 'git merge' and friends will work as expected. + Note that if you use '--squash' when you merge, you should usually not just '--rejoin' when you split. +pull :: + Exactly like 'merge', but parallels 'git pull' in that + it fetches the given ref from the specified remote + repository. + +push :: + Does a 'split' using the subtree of HEAD and then + does a 'git push' to push the result to the and + . This can be used to push your subtree to + different branches of the remote repository. OPTIONS ------- @@ -139,19 +142,18 @@ OPTIONS -m :: --message=:: - This option is only valid for add, merge, pull, and split --rejoin. + This option is only valid for 'add', 'merge', 'pull', and 'split --rejoin'. Specify as the commit message for the merge commit. +OPTIONS FOR 'add' AND 'merge' (ALSO: 'pull') +-------------------------------------------- +These options for 'add' and 'merge' may also be given to 'pull' (which +wraps 'merge'). -OPTIONS FOR add, merge, and pull --------------------------------- --squash:: - This option is only valid for add, merge, and pull - commands. -+ -Instead of merging the entire history from the subtree project, produce -only a single commit that contains all the differences you want to -merge, and then merge that new commit into your project. + Instead of merging the entire history from the subtree project, produce + only a single commit that contains all the differences you want to + merge, and then merge that new commit into your project. + Using this option helps to reduce log clutter. People rarely want to see every change that happened between v1.0 and v1.1 of the library they're @@ -175,56 +177,48 @@ remain intact and can be later split and send upstream to the subproject. -OPTIONS FOR split ------------------ +OPTIONS FOR 'split' +------------------- +These options are only valid for 'split'. + --annotate=:: - This option is only valid for the split command. -+ -When generating synthetic history, add as a prefix to each -commit message. Since we're creating new commits with the same commit -message, but possibly different content, from the original commits, this -can help to differentiate them and avoid confusion. + When generating synthetic history, add as a prefix to each + commit message. Since we're creating new commits with the same commit + message, but possibly different content, from the original commits, this + can help to differentiate them and avoid confusion. + Whenever you split, you need to use the same , or else you don't have a guarantee that the new re-created history will be identical to the old one. That will prevent merging from working correctly. git -subtree tries to make it work anyway, particularly if you use --rejoin, +subtree tries to make it work anyway, particularly if you use '--rejoin', but it may not always be effective. -b :: --branch=:: - This option is only valid for the split command. -+ -After generating the synthetic history, create a new branch called - that contains the new history. This is suitable for immediate -pushing upstream. must not already exist. + After generating the synthetic history, create a new branch called + that contains the new history. This is suitable for immediate + pushing upstream. must not already exist. --ignore-joins:: - This option is only valid for the split command. -+ -If you use '--rejoin', git subtree attempts to optimize its history -reconstruction to generate only the new commits since the last -'--rejoin'. '--ignore-join' disables this behaviour, forcing it to -regenerate the entire history. In a large project, this can take a long -time. + If you use '--rejoin', git subtree attempts to optimize its history + reconstruction to generate only the new commits since the last + '--rejoin'. '--ignore-join' disables this behaviour, forcing it to + regenerate the entire history. In a large project, this can take a long + time. --onto=:: - This option is only valid for the split command. -+ -If your subtree was originally imported using something other than git -subtree, its history may not match what git subtree is expecting. In -that case, you can specify the commit id that corresponds to the -first revision of the subproject's history that was imported into your -project, and git subtree will attempt to build its history from there. + If your subtree was originally imported using something other than git + subtree, its history may not match what git subtree is expecting. In + that case, you can specify the commit ID that corresponds to the + first revision of the subproject's history that was imported into your + project, and git subtree will attempt to build its history from there. + If you used 'git subtree add', you should never need this option. --rejoin:: - This option is only valid for the split command. -+ -After splitting, merge the newly created synthetic history back into -your main project. That way, future splits can search only the part of -history that has been added since the most recent --rejoin. + After splitting, merge the newly created synthetic history back into + your main project. That way, future splits can search only the part of + history that has been added since the most recent '--rejoin'. + If your split commits end up merged into the upstream subproject, and then you want to get the latest upstream version, this will allow git's @@ -240,8 +234,8 @@ split, because you don't want the subproject's history to be part of your project anyway. -EXAMPLE 1. Add command ----------------------- +EXAMPLE 1. 'add' command +------------------------ Let's assume that you have a local repository that you would like to add an external vendor library to. In this case we will add the git-subtree repository as a subdirectory of your already existing @@ -253,15 +247,15 @@ git-extensions repository in ~/git-extensions/: 'master' needs to be a valid remote ref and can be a different branch name -You can omit the --squash flag, but doing so will increase the number +You can omit the '--squash' flag, but doing so will increase the number of commits that are included in your local repository. We now have a ~/git-extensions/git-subtree directory containing code from the master branch of git://github.com/apenwarr/git-subtree.git in our git-extensions repository. -EXAMPLE 2. Extract a subtree using commit, merge and pull ---------------------------------------------------------- +EXAMPLE 2. Extract a subtree using 'commit', 'merge' and 'pull' +--------------------------------------------------------------- Let's use the repository for the git source code as an example. First, get your own copy of the git.git repository: @@ -284,9 +278,9 @@ the upstream. You could do this: 0a8f4f0 to the current version, including 0a8f4f0 itself.") If gitweb had originally been merged using 'git subtree add' (or -a previous split had already been done with --rejoin specified) +a previous split had already been done with '--rejoin' specified) then you can do all your splits without having to remember any -weird commit ids: +weird commit IDs: $ git subtree split --prefix=gitweb --annotate='(split) ' --rejoin \ --branch gitweb-latest2 @@ -321,8 +315,8 @@ the standard gitweb: git log gitweb-latest..$(git subtree split --prefix=gitweb) -EXAMPLE 3. Extract a subtree using branch ------------------------------------------ +EXAMPLE 3. Extract a subtree using a branch +------------------------------------------- Suppose you have a source directory with many files and subdirectories, and you want to extract the lib directory to its own git project. Here's a short way to do it: From patchwork Fri Apr 23 19:42:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 086A3C43460 for ; Fri, 23 Apr 2021 19:43:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D23796128B for ; Fri, 23 Apr 2021 19:43:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243895AbhDWTn6 (ORCPT ); Fri, 23 Apr 2021 15:43:58 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35334 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243960AbhDWTnm (ORCPT ); Fri, 23 Apr 2021 15:43:42 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 109B180590; Fri, 23 Apr 2021 15:43:05 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 27/30] subtree: allow --squash to be used with --rejoin Date: Fri, 23 Apr 2021 13:42:27 -0600 Message-Id: <20210423194230.1388945-28-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Besides being a genuinely useful thing to do, this also just makes sense and harmonizes which flags may be used when. `git subtree split --rejoin` amounts to "automatically go ahead and do a `git subtree merge` after doing the main `git subtree split`", so it's weird and arbitrary that you can't pass `--squash` to `git subtree split --rejoin` like you can `git subtree merge`. It's weird that `git subtree split --rejoin` inherits `git subtree merge`'s `--message` but not `--squash`. Reconcile the situation by just having `split --rejoin` actually just call `merge` internally (or call `add` instead, as appropriate), so it can get access to the full `merge` behavior, including `--squash`. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 33 ++++++++++++++++++++++------ contrib/subtree/git-subtree.txt | 27 ++++++++++------------- contrib/subtree/t/t7900-subtree.sh | 35 ++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 23 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 4d0be1ad5c..ff54009c49 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -17,15 +17,15 @@ h,help show the help q quiet d show debug messages P,prefix= the name of the subdir to split out -m,message= use the given message as the commit message for the merge commit options for 'split' annotate= add a prefix to commit message of new commits b,branch= create a new branch from the split subtree ignore-joins ignore prior --rejoin commits onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD - options for 'add' and 'merge' (also: 'pull') + options for 'add' and 'merge' (also: 'pull' and 'split --rejoin') squash merge subtree changes as a single commit +m,message= use the given message as the commit message for the merge commit " PATH=$(git --exec-path):$PATH @@ -424,6 +424,13 @@ add_msg () { else commit_message="Add '$dir/' from commit '$latest_new'" fi + if test -n "$arg_split_rejoin" + then + # If this is from a --rejoin, then rejoin_msg has + # already inserted the `git-subtree-xxx:` tags + echo "$commit_message" + return + fi cat <<-EOF $commit_message @@ -746,7 +753,12 @@ cmd_add_commit () { rev=$(git rev-parse --verify "$1^{commit}") || exit $? debug "Adding $dir as '$rev'..." - git read-tree --prefix="$dir" $rev || exit $? + if test -z "$arg_split_rejoin" + then + # Only bother doing this if this is a genuine 'add', + # not a synthetic 'add' from '--rejoin'. + git read-tree --prefix="$dir" $rev || exit $? + fi git checkout -- "$dir" || exit $? tree=$(git write-tree) || exit $? @@ -786,6 +798,11 @@ cmd_split () { die "You must provide exactly one revision. Got: '$*'" fi + if test -n "$arg_split_rejoin" + then + ensure_clean + fi + debug "Splitting $dir..." cache_setup || exit $? @@ -828,10 +845,12 @@ cmd_split () { then debug "Merging split branch into HEAD..." latest_old=$(cache_get latest_old) || exit $? - git merge -s ours \ - --allow-unrelated-histories \ - -m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \ - "$latest_new" >&2 || exit $? + arg_addmerge_message="$(rejoin_msg "$dir" "$latest_old" "$latest_new")" || exit $? + if test -z "$(find_latest_squash "$dir")"; then + cmd_add "$latest_new" >&2 || exit $? + else + cmd_merge "$latest_new" >&2 || exit $? + fi fi if test -n "$arg_split_branch" then diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt index 5728778bdf..b03ef88e1a 100644 --- a/contrib/subtree/git-subtree.txt +++ b/contrib/subtree/git-subtree.txt @@ -109,9 +109,6 @@ settings passed to 'split' (such as '--annotate') are the same. Because of this, if you add new commits and then re-split, the new commits will be attached as commits on top of the history you generated last time, so 'git merge' and friends will work as expected. -+ -Note that if you use '--squash' when you merge, you should usually not -just '--rejoin' when you split. pull :: Exactly like 'merge', but parallels 'git pull' in that @@ -124,8 +121,8 @@ push :: . This can be used to push your subtree to different branches of the remote repository. -OPTIONS -------- +OPTIONS FOR ALL COMMANDS +------------------------ -q:: --quiet:: Suppress unnecessary output messages on stderr. @@ -140,15 +137,11 @@ OPTIONS want to manipulate. This option is mandatory for all commands. --m :: ---message=:: - This option is only valid for 'add', 'merge', 'pull', and 'split --rejoin'. - Specify as the commit message for the merge commit. - -OPTIONS FOR 'add' AND 'merge' (ALSO: 'pull') --------------------------------------------- +OPTIONS FOR 'add' AND 'merge' (ALSO: 'pull' AND 'split --rejoin') +----------------------------------------------------------------- These options for 'add' and 'merge' may also be given to 'pull' (which -wraps 'merge'). +wraps 'merge') and 'split --rejoin' (which wraps either 'add' or +'merge' as appropriate). --squash:: Instead of merging the entire history from the subtree project, produce @@ -176,6 +169,9 @@ Whether or not you use '--squash', changes made in your local repository remain intact and can be later split and send upstream to the subproject. +-m :: +--message=:: + Specify as the commit message for the merge commit. OPTIONS FOR 'split' ------------------- @@ -229,9 +225,8 @@ Unfortunately, using this option results in 'git log' showing an extra copy of every new commit that was created (the original, and the synthetic one). + -If you do all your merges with '--squash', don't use '--rejoin' when you -split, because you don't want the subproject's history to be part of -your project anyway. +If you do all your merges with '--squash', make sure you also use +'--squash' when you 'split --rejoin'. EXAMPLE 1. 'add' command diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 3ee0524233..e5467c117b 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -324,6 +324,41 @@ test_expect_success 'split sub dir/ with --rejoin and --message' ' ) ' +test_expect_success 'split "sub dir"/ with --rejoin and --squash' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" --squash FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD && + MAIN=$(git rev-parse --verify HEAD) && + SUB=$(git -C "sub proj" rev-parse --verify HEAD) && + + SPLIT=$(git subtree split --prefix="sub dir" --annotate="*" --rejoin --squash) && + + ! git merge-base --is-ancestor $SUB HEAD && + ! git merge-base --is-ancestor $SPLIT HEAD && + git rev-list HEAD ^$MAIN >commit-list && + test_line_count = 2 commit-list && + test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" && + test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" && + test "$(git rev-parse --verify HEAD^1)" = $MAIN && + test "$(git rev-parse --verify HEAD^2)" != $SPLIT && + test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" && + test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''" + ) +' + test_expect_success 'split "sub dir"/ with --branch' ' subtree_test_create_repo "$test_count" && subtree_test_create_repo "$test_count/sub proj" && From patchwork Fri Apr 23 19:42:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 762ABC433ED for ; Fri, 23 Apr 2021 19:43:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B8DD61422 for ; Fri, 23 Apr 2021 19:43:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243968AbhDWTn7 (ORCPT ); Fri, 23 Apr 2021 15:43:59 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35508 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243967AbhDWTnn (ORCPT ); Fri, 23 Apr 2021 15:43:43 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id E85AB80595; Fri, 23 Apr 2021 15:43:05 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 28/30] subtree: allow 'split' flags to be passed to 'push' Date: Fri, 23 Apr 2021 13:42:28 -0600 Message-Id: <20210423194230.1388945-29-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker 'push' does a 'split' internally, but it doesn't pass flags through to the 'split'. This is silly, if you need to pass flags to 'split', then it means that you can't use 'push'! So, have 'push' accept 'split' flags, and pass them through to 'split'. Add tests for this by copying split's tests with minimal modification. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 6 +- contrib/subtree/git-subtree.txt | 15 +- contrib/subtree/t/t7900-subtree.sh | 214 ++++++++++++++++++++++++++++- 3 files changed, 223 insertions(+), 12 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index ff54009c49..2846bd21b4 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -17,13 +17,13 @@ h,help show the help q quiet d show debug messages P,prefix= the name of the subdir to split out - options for 'split' + options for 'split' (also: 'push') annotate= add a prefix to commit message of new commits b,branch= create a new branch from the split subtree ignore-joins ignore prior --rejoin commits onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD - options for 'add' and 'merge' (also: 'pull' and 'split --rejoin') + options for 'add' and 'merge' (also: 'pull', 'split --rejoin', and 'push --rejoin') squash merge subtree changes as a single commit m,message= use the given message as the commit message for the merge commit " @@ -933,7 +933,7 @@ cmd_push () { repository=$1 refspec=$2 echo "git push using: " "$repository" "$refspec" - localrev=$(git subtree split --prefix="$arg_prefix") || die + localrev=$(cmd_split) || die git push "$repository" "$localrev":"refs/heads/$refspec" else die "'$dir' must already exist. Try 'git subtree add'." diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt index b03ef88e1a..a597d61d0f 100644 --- a/contrib/subtree/git-subtree.txt +++ b/contrib/subtree/git-subtree.txt @@ -137,11 +137,11 @@ OPTIONS FOR ALL COMMANDS want to manipulate. This option is mandatory for all commands. -OPTIONS FOR 'add' AND 'merge' (ALSO: 'pull' AND 'split --rejoin') ------------------------------------------------------------------ +OPTIONS FOR 'add' AND 'merge' (ALSO: 'pull', 'split --rejoin', AND 'push --rejoin') +----------------------------------------------------------------------------------- These options for 'add' and 'merge' may also be given to 'pull' (which -wraps 'merge') and 'split --rejoin' (which wraps either 'add' or -'merge' as appropriate). +wraps 'merge'), 'split --rejoin' (which wraps either 'add' or 'merge' +as appropriate), and 'push --rejoin' (which wraps 'split --rejoin'). --squash:: Instead of merging the entire history from the subtree project, produce @@ -173,9 +173,10 @@ subproject. --message=:: Specify as the commit message for the merge commit. -OPTIONS FOR 'split' -------------------- -These options are only valid for 'split'. +OPTIONS FOR 'split' (ALSO: 'push') +---------------------------------- +These options for 'split' may also be given to 'push' (which wraps +'split'). --annotate=:: When generating synthetic history, add as a prefix to each diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index e5467c117b..e89e46fe65 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -5,8 +5,8 @@ # test_description='Basic porcelain support for subtrees -This test verifies the basic operation of the add, pull, merge -and split subcommands of git subtree. +This test verifies the basic operation of the add, merge, split, pull, +and push subcommands of git subtree. ' TEST_DIRECTORY=$(pwd)/../../../t @@ -589,6 +589,216 @@ test_expect_success 'push basic operation' ' ) ' +test_expect_success 'push sub dir/ with --rejoin' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree merge --prefix="sub dir" FETCH_HEAD && + split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && + git subtree push --prefix="sub dir" --annotate="*" --rejoin ./"sub proj" from-mainline && + test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" && + test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" + ) +' + +test_expect_success 'push sub dir/ with --rejoin from scratch' ' + subtree_test_create_repo "$test_count" && + test_create_commit "$test_count" main1 && + ( + cd "$test_count" && + mkdir "sub dir" && + echo file >"sub dir"/file && + git add "sub dir/file" && + git commit -m"sub dir file" && + split_hash=$(git subtree split --prefix="sub dir" --rejoin) && + git init --bare "sub proj.git" && + git subtree push --prefix="sub dir" --rejoin ./"sub proj.git" from-mainline && + test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" && + test "$split_hash" = "$(git -C "sub proj.git" rev-parse --verify refs/heads/from-mainline)" + ) +' + +test_expect_success 'push sub dir/ with --rejoin and --message' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree merge --prefix="sub dir" FETCH_HEAD && + git subtree push --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin ./"sub proj" from-mainline && + test "$(last_commit_subject)" = "Split & rejoin" && + split_hash="$(git rev-parse --verify HEAD^2)" && + test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" + ) +' + +test_expect_success 'push "sub dir"/ with --rejoin and --squash' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" --squash FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD && + MAIN=$(git rev-parse --verify HEAD) && + SUB=$(git -C "sub proj" rev-parse --verify HEAD) && + + SPLIT=$(git subtree split --prefix="sub dir" --annotate="*") && + git subtree push --prefix="sub dir" --annotate="*" --rejoin --squash ./"sub proj" from-mainline && + + ! git merge-base --is-ancestor $SUB HEAD && + ! git merge-base --is-ancestor $SPLIT HEAD && + git rev-list HEAD ^$MAIN >commit-list && + test_line_count = 2 commit-list && + test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" && + test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" && + test "$(git rev-parse --verify HEAD^1)" = $MAIN && + test "$(git rev-parse --verify HEAD^2)" != $SPLIT && + test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" && + test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''" && + test "$SPLIT" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" + ) +' + +test_expect_success 'push "sub dir"/ with --branch' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree merge --prefix="sub dir" FETCH_HEAD && + split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && + git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline && + test "$(git rev-parse subproj-br)" = "$split_hash" && + test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" + ) +' + +test_expect_success 'check hash of push' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree merge --prefix="sub dir" FETCH_HEAD && + split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && + git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline && + test "$(git rev-parse subproj-br)" = "$split_hash" && + # Check hash of split + new_hash=$(git rev-parse subproj-br^2) && + ( + cd ./"sub proj" && + subdir_hash=$(git rev-parse HEAD) && + test "$new_hash" = "$subdir_hash" + ) && + test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" + ) +' + +test_expect_success 'push "sub dir"/ with --branch for an existing branch' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git branch subproj-br FETCH_HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree merge --prefix="sub dir" FETCH_HEAD && + split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && + git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline && + test "$(git rev-parse subproj-br)" = "$split_hash" && + test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" + ) +' + +test_expect_success 'push "sub dir"/ with --branch for an incompatible branch' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git branch init HEAD && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree merge --prefix="sub dir" FETCH_HEAD && + test_must_fail git subtree push --prefix="sub dir" --branch init "./sub proj" from-mainline + ) +' + # # Validity checking # From patchwork Fri Apr 23 19:42:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 114B1C43461 for ; Fri, 23 Apr 2021 19:43:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1A416128B for ; Fri, 23 Apr 2021 19:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244017AbhDWTn7 (ORCPT ); Fri, 23 Apr 2021 15:43:59 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35522 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243905AbhDWTno (ORCPT ); Fri, 23 Apr 2021 15:43:44 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id C06EB80594; Fri, 23 Apr 2021 15:43:06 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 29/30] subtree: push: allow specifying a local rev other than HEAD Date: Fri, 23 Apr 2021 13:42:29 -0600 Message-Id: <20210423194230.1388945-30-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker 'git subtree split' lets you specify a rev other than HEAD. 'git push' lets you specify a mapping between a local thing and a remot ref. So smash those together, and have 'git subtree push' let you specify which local thing to run split on and push the result of that split to the remote ref. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 24 +++++++++++++++++------- contrib/subtree/git-subtree.txt | 14 ++++++++------ contrib/subtree/t/t7900-subtree.sh | 22 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 2846bd21b4..7361d8de3f 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -11,7 +11,7 @@ git subtree add --prefix= git subtree merge --prefix= git subtree split --prefix= [] git subtree pull --prefix= -git subtree push --prefix= +git subtree push --prefix= -- h,help show the help q quiet @@ -921,20 +921,30 @@ cmd_pull () { cmd_merge FETCH_HEAD } -# Usage: cmd_push REPOSITORY REMOTEREF +# Usage: cmd_push REPOSITORY [+][LOCALREV:]REMOTEREF cmd_push () { if test $# -ne 2 then - die "You must provide " + die "You must provide " fi - ensure_valid_ref_format "$2" if test -e "$dir" then repository=$1 - refspec=$2 + refspec=${2#+} + remoteref=${refspec#*:} + if test "$remoteref" = "$refspec" + then + localrevname_presplit=HEAD + else + localrevname_presplit=${refspec%%:*} + fi + ensure_valid_ref_format "$remoteref" + localrev_presplit=$(git rev-parse -q --verify "$localrevname_presplit^{commit}") || + die "'$localrevname_presplit' does not refer to a commit" + echo "git push using: " "$repository" "$refspec" - localrev=$(cmd_split) || die - git push "$repository" "$localrev":"refs/heads/$refspec" + localrev=$(cmd_split "$localrev_presplit") || die + git push "$repository" "$localrev":"refs/heads/$remoteref" else die "'$dir' must already exist. Try 'git subtree add'." fi diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt index a597d61d0f..c049827cb5 100644 --- a/contrib/subtree/git-subtree.txt +++ b/contrib/subtree/git-subtree.txt @@ -16,7 +16,7 @@ SYNOPSIS [verse] 'git subtree' [] -P pull -'git subtree' [] -P push +'git subtree' [] -P push DESCRIPTION ----------- @@ -115,11 +115,13 @@ pull :: it fetches the given ref from the specified remote repository. -push :: - Does a 'split' using the subtree of HEAD and then - does a 'git push' to push the result to the and - . This can be used to push your subtree to - different branches of the remote repository. +push [+][:]:: + Does a 'split' using the subtree of + and then does a 'git push' to push the result to the + and . This can be used to push your + subtree to different branches of the remote repository. Just + as with 'split', if no is given, then HEAD is + used. The optional leading '+' is ignored. OPTIONS FOR ALL COMMANDS ------------------------ diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index e89e46fe65..fb85eed5fc 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -799,6 +799,28 @@ test_expect_success 'push "sub dir"/ with --branch for an incompatible branch' ' ) ' +test_expect_success 'push "sub dir"/ with a local rev' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + bad_tree=$(git rev-parse --verify HEAD:"sub dir") && + good_tree=$(git rev-parse --verify HEAD^:"sub dir") && + git subtree push --prefix="sub dir" --annotate="*" ./"sub proj" HEAD^:from-mainline && + split_tree=$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline:) && + test "$split_tree" = "$good_tree" + ) +' + # # Validity checking # From patchwork Fri Apr 23 19:42:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89E51C43462 for ; Fri, 23 Apr 2021 19:43:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67DD76113B for ; Fri, 23 Apr 2021 19:43:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244018AbhDWToB (ORCPT ); Fri, 23 Apr 2021 15:44:01 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35450 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243934AbhDWTnp (ORCPT ); Fri, 23 Apr 2021 15:43:45 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 9948A80596; Fri, 23 Apr 2021 15:43:07 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 30/30] subtree: be stricter about validating flags Date: Fri, 23 Apr 2021 13:42:30 -0600 Message-Id: <20210423194230.1388945-31-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker Don't silently ignore a flag that's invalid for a given subcommand. The user expected it to do something; we should tell the user that they are mistaken, instead of surprising the user. It could be argued that this change might break existing users. I'd argue that those existing users are already broken, and they just don't know it. Let them know that they're broken. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 89 ++++++++++++++++------- contrib/subtree/t/t7900-subtree.sh | 111 +++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 25 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 7361d8de3f..5073d82b2e 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -30,17 +30,6 @@ m,message= use the given message as the commit message for the merge commit PATH=$(git --exec-path):$PATH -arg_debug= -arg_command= -arg_prefix= -arg_split_branch= -arg_split_onto= -arg_split_rejoin= -arg_split_ignore_joins= -arg_split_annotate= -arg_addmerge_squash= -arg_addmerge_message= - indent=0 # Usage: debug [MSG...] @@ -77,10 +66,61 @@ main () { then set -- -h fi - eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" + set_args="$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" + eval "$set_args" . git-sh-setup require_work_tree + # First figure out the command and whether we use --rejoin, so + # that we can provide more helpful validation when we do the + # "real" flag parsing. + arg_split_rejoin= + allow_split= + allow_addmerge= + while test $# -gt 0 + do + opt="$1" + shift + case "$opt" in + --annotate|-b|-P|-m|--onto) + shift + ;; + --rejoin) + arg_split_rejoin=1 + ;; + --no-rejoin) + arg_split_rejoin= + ;; + --) + break + ;; + esac + done + arg_command=$1 + case "$arg_command" in + add|merge|pull) + allow_addmerge=1 + ;; + split|push) + allow_split=1 + allow_addmerge=$arg_split_rejoin + ;; + *) + die "Unknown command '$arg_command'" + ;; + esac + # Reset the arguments array for "real" flag parsing. + eval "$set_args" + + # Begin "real" flag parsing. + arg_debug= + arg_prefix= + arg_split_branch= + arg_split_onto= + arg_split_ignore_joins= + arg_split_annotate= + arg_addmerge_squash= + arg_addmerge_message= while test $# -gt 0 do opt="$1" @@ -94,13 +134,16 @@ main () { arg_debug=1 ;; --annotate) + test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." arg_split_annotate="$1" shift ;; --no-annotate) + test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." arg_split_annotate= ;; -b) + test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." arg_split_branch="$1" shift ;; @@ -109,6 +152,7 @@ main () { shift ;; -m) + test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." arg_addmerge_message="$1" shift ;; @@ -116,28 +160,34 @@ main () { arg_prefix= ;; --onto) + test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." arg_split_onto="$1" shift ;; --no-onto) + test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." arg_split_onto= ;; --rejoin) - arg_split_rejoin=1 + test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." ;; --no-rejoin) - arg_split_rejoin= + test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." ;; --ignore-joins) + test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." arg_split_ignore_joins=1 ;; --no-ignore-joins) + test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." arg_split_ignore_joins= ;; --squash) + test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." arg_addmerge_squash=1 ;; --no-squash) + test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'." arg_addmerge_squash= ;; --) @@ -148,19 +198,8 @@ main () { ;; esac done - - arg_command="$1" shift - case "$arg_command" in - add|merge|pull|split|push) - : - ;; - *) - die "Unknown command '$arg_command'" - ;; - esac - if test -z "$arg_prefix" then die "You must provide the --prefix option." diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index fb85eed5fc..f83c491a61 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -33,6 +33,12 @@ test_create_commit () ( git commit -m "$commit" || error "Could not commit" ) +test_wrong_flag() { + test_must_fail "$@" >out 2>err && + test_must_be_empty out && + grep "flag does not make sense with" err +} + last_commit_subject () { git log --pretty=format:%s -1 } @@ -72,6 +78,22 @@ test_expect_success 'no pull from non-existent subtree' ' ) ' +test_expect_success 'add rejects flags for split' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + test_wrong_flag git subtree add --prefix="sub dir" --annotate=foo FETCH_HEAD && + test_wrong_flag git subtree add --prefix="sub dir" --branch=foo FETCH_HEAD && + test_wrong_flag git subtree add --prefix="sub dir" --ignore-joins FETCH_HEAD && + test_wrong_flag git subtree add --prefix="sub dir" --onto=foo FETCH_HEAD && + test_wrong_flag git subtree add --prefix="sub dir" --rejoin FETCH_HEAD + ) +' + test_expect_success 'add subproj as subtree into sub dir/ with --prefix' ' subtree_test_create_repo "$test_count" && subtree_test_create_repo "$test_count/sub proj" && @@ -128,6 +150,28 @@ test_expect_success 'add subproj as subtree into sub dir/ with --squash and --pr # Tests for 'git subtree merge' # +test_expect_success 'merge rejects flags for split' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count/sub proj" sub2 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + test_wrong_flag git subtree merge --prefix="sub dir" --annotate=foo FETCH_HEAD && + test_wrong_flag git subtree merge --prefix="sub dir" --branch=foo FETCH_HEAD && + test_wrong_flag git subtree merge --prefix="sub dir" --ignore-joins FETCH_HEAD && + test_wrong_flag git subtree merge --prefix="sub dir" --onto=foo FETCH_HEAD && + test_wrong_flag git subtree merge --prefix="sub dir" --rejoin FETCH_HEAD + ) +' + test_expect_success 'merge new subproj history into sub dir/ with --prefix' ' subtree_test_create_repo "$test_count" && subtree_test_create_repo "$test_count/sub proj" && @@ -262,6 +306,30 @@ test_expect_success 'split requires path given by option --prefix must exist' ' ) ' +test_expect_success 'split rejects flags for add' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree merge --prefix="sub dir" FETCH_HEAD && + split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && + test_wrong_flag git subtree split --prefix="sub dir" --squash && + test_wrong_flag git subtree split --prefix="sub dir" --message=foo + ) +' + test_expect_success 'split sub dir/ with --rejoin' ' subtree_test_create_repo "$test_count" && subtree_test_create_repo "$test_count/sub proj" && @@ -521,6 +589,26 @@ test_expect_success 'pull basic operation' ' ) ' +test_expect_success 'pull rejects flags for split' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count/sub proj" sub2 && + ( + test_must_fail git subtree pull --prefix="sub dir" --annotate=foo ./"sub proj" HEAD && + test_must_fail git subtree pull --prefix="sub dir" --branch=foo ./"sub proj" HEAD && + test_must_fail git subtree pull --prefix="sub dir" --ignore-joins ./"sub proj" HEAD && + test_must_fail git subtree pull --prefix="sub dir" --onto=foo ./"sub proj" HEAD && + test_must_fail git subtree pull --prefix="sub dir" --rejoin ./"sub proj" HEAD + ) +' + # # Tests for 'git subtree push' # @@ -563,6 +651,29 @@ test_expect_success 'push requires path given by option --prefix must exist' ' ) ' +test_expect_success 'push rejects flags for add' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" main2 && + test_create_commit "$test_count/sub proj" sub2 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree merge --prefix="sub dir" FETCH_HEAD && + test_wrong_flag git subtree split --prefix="sub dir" --squash ./"sub proj" from-mainline && + test_wrong_flag git subtree split --prefix="sub dir" --message=foo ./"sub proj" from-mainline + ) +' + test_expect_success 'push basic operation' ' subtree_test_create_repo "$test_count" && subtree_test_create_repo "$test_count/sub proj" &&