subtree: clean up, improve UX
cover subtree: clean up, improve UX
From: Luke Shumaker <[email protected]>
Ostensibly, this patch set is about improving various aspects of git subtree's user interface (and it is!), but it's also mostly about setting the foundation and being "batch 1" of a bunch more changes to subtree that I'm getting queued up. So please forgive the large amount of churn in the leading clean-up commits, I promise that there's more work coming on top of it (we've discovered lots of ways to break the "subtree split" algorithm, and come up with fixes for most of them). In the mean-time, I do think that the UX improvements in this patchset are already worth it themselves.
- The first 11 commits improve subtree's tests, largely around the code-quality of the tests, but a few of the commits do actually improve what's being tested.
- The middle 12 commits improve the code-quality of subtree's implementation.
- The final 7 commits improve various aspects of subtree's user experience, from readability of the debug output, to documentation, to option flag handling.
The very last commit is likely to be a little objectionable--it makes some option flag parsing more strict, so there will probably be worry that the change breaks existing users. However, it's being strict about arg combinations that were always invalid, the difference is that now it reports that to the users and bails. Those users were already broken, they just didn't know it. git subtree should tell them.
As a final question, would it be all right to amend CI to run the subtree tests? And if so, what would be the best way to do it? For my own testing, I just made the following edit to the main Makefile, but I'm not sure it's the mos appropriate approach:
--- a/Makefile
+++ b/Makefile
@@ -2836,6 +2836,7 @@
test: all
$(MAKE) -C t/ all
+ $(MAKE) -C contrib/subtree/ test
perf: all
$(MAKE) -C t/perf/ allThe first two commits are about getting that to pass. I'd prefer to avoid that type of bitrot in the future.
Luke Shumaker (30):
.gitignore: Ignore /git-subtree
subtree: t7900: update for having the default branch name be 'main'
subtree: t7900: use test-lib.sh's test_count
subtree: t7900: use consistent formatting
subtree: t7900: comment subtree_test_create_repo
subtree: t7900: use 'test' for string equality
subtree: t7900: delete some dead code
subtree: t7900: fix 'verify one file change per commit'
subtree: t7900: rename last_commit_message to last_commit_subject
subtree: t7900: add a test for the -h flag
subtree: t7900: add porcelain tests for 'pull' and 'push'
subtree: don't have loose code outside of a function
subtree: more consistent error propagation
subtree: drop support for git < 1.7
subtree: use git merge-base --is-ancestor
subtree: use git-sh-setup's say
subtree: use more explicit variable names for cmdline args
subtree: use $* instead of $@ as appropriate
subtree: give $(git --exec-path) precedence over $PATH
subtree: use "^{commit}" instead of "^0"
subtree: parse revs in individual cmd_ functions
subtree: remove duplicate check
subtree: add comments and sanity checks
subtree: don't let debug and progress output clash
subtree: have $indent actually affect indentation
subtree: give the docs a once-over
subtree: allow --squash to be used with --rejoin
subtree: allow 'split' flags to be passed to 'push'
subtree: push: allow specifying a local rev other than HEAD
subtree: be stricter about validating flags
.gitignore | 1 + contrib/subtree/git-subtree.sh | 613 +++++++----- contrib/subtree/git-subtree.txt | 184 ++-- contrib/subtree/t/t7900-subtree.sh | 1421 ++++++++++++++++++---------- 4 files changed, 1363 insertions(+), 856 deletions(-)
Signature · 4 lines
2.31.1 Happy hacking, ~ Luke Shumaker
PATCH 1/30 .gitignore: Ignore /git-subtree
From: Luke Shumaker <[email protected]>
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.
--- .gitignore | 1 + 1 file changed, 1 insertion(+)
.gitignore +1 -0
@@ -162,6 +162,7 @@ /git-stripspace /git-submodule /git-submodule--helper +/git-subtree /git-svn /git-switch /git-symbolic-ref
Signature · 1 line
2.31.1
PATCH 2/30 subtree: t7900: update for having the default branch name be 'main'
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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'.
--- contrib/subtree/t/t7900-subtree.sh | 117 +++++++++++++++-------------- 1 file changed, 59 insertions(+), 58 deletions(-)
contrib/subtree/t/t7900-subtree.sh +59 -58
@@ -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 )
Signature · 1 line
2.31.1
PATCH 3/30 subtree: t7900: use test-lib.sh's test_count
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/t/t7900-subtree.sh | 636 ++++++++++++++--------------- 1 file changed, 300 insertions(+), 336 deletions(-)
contrib/subtree/t/t7900-subtree.sh +300 -336
@@ -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 &&
Signature · 1 line
2.31.1
PATCH 4/30 subtree: t7900: use consistent formatting
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
The formatting in t7900-subtree.sh isn't even consistent throughout the file. Fix that; make it consistent throughout the file.
--- contrib/subtree/t/t7900-subtree.sh | 47 +++++++++++++----------------- 1 file changed, 21 insertions(+), 26 deletions(-)
contrib/subtree/t/t7900-subtree.sh +21 -26
@@ -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" ) '
Signature · 1 line
2.31.1
Re: [PATCH 04/30] subtree: t7900: use consistent formatting
Quoted 7 lines · Luke Shumaker
The formatting in
t7900-subtree.shisn't even consistent throughout the file. Fix that; make it consistent throughout the file.Signed-off-by Luke Shumaker <[email protected]>---
contrib/subtree/t/t7900-subtree.sh subtree_test_create_repo() · line 26
Quoted 9 lines
contrib/subtree/t/t7900-subtree.sh +3
-3@@ -23,26 +21,24 @@ subtree_test_create_repo() -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
We prefer test over [, so it might make sense to update that, as well, along with these other style cleanups.
Re: [PATCH 04/30] subtree: t7900: use consistent formatting
Quoted 5 lines · Eric Sunshine
Quoted 3 lines · Luke Shumaker
The formatting in
t7900-subtree.shisn't even consistent throughout the file. Fix that; make it consistent throughout the file.
Quoted 16 lines
contrib/subtree/t/t7900-subtree.sh subtree_test_create_repo() · line 26
Quoted 13 lines
Signed-off-by Luke Shumaker <[email protected]>---
contrib/subtree/t/t7900-subtree.sh +3
-3@@ -23,26 +21,24 @@ subtree_test_create_repo() -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" ] + thenWe prefer
testover[, so it might make sense to update that, as well, along with these other style cleanups.
OK, I'll include that in this commit.
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
Re: [PATCH 04/30] subtree: t7900: use consistent formatting
In reply to Eric SunshineQuoted 10 lines · Eric Sunshine
contrib/subtree/t/t7900-subtree.sh subtree_test_create_repo() · line 34
Quoted 7 lines
contrib/subtree/t/t7900-subtree.sh +3
-1+check_equal () { test_debug 'echo' test_debug "echo \"check a:\" \"{$1}\"" test_debug "echo \" b:\" \"{$2}\"" - if [ "$1" = "$2" ]; then + if [ "$1" = "$2" ] + thenWe prefer
testover[, so it might make sense to update that, as well, along with these other style cleanups.
If I were working on this, I wouldn't bother.
As far as I am concerned, contrib/subtree has always been treated as a borrowed code [*] that is written in a dialect of shell that is different from what our scripts are written in, and there are too many style differences (I wouldn't call them violations---nobody has expected the code there to follow our style, or attempted to enforce our style there) to bother coercing.
If Luke is volunteering to take over its maintainership, it would be appreciated by its users. It has been in the "abandonware" status for too long.
[Footnote]
* ... as opposed to a properly maintained part of the git-core proper.
Re: [PATCH 04/30] subtree: t7900: use consistent formatting
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Eric Sunshine
Quoted 7 lines
contrib/subtree/t/t7900-subtree.sh +3
-1+check_equal () { test_debug 'echo' test_debug "echo \"check a:\" \"{$1}\"" test_debug "echo \" b:\" \"{$2}\"" - if [ "$1" = "$2" ]; then + if [ "$1" = "$2" ] + then
Quoted 4 lines
Quoted 2 lines
We prefer
testover[, so it might make sense to update that, as well, along with these other style cleanups.If I were working on this, I wouldn't bother.
In this case, it's not just about consistency with git-core, it's about consistency within contrib/subtree; there were just 2 or 3 places where it used [ instead of test.
Quoted 3 lines
If Luke is volunteering to take over its maintainership, it would be appreciated by its users. It has been in the "abandonware" status for too long.
I think I am volunteering.
We have been using git-subtree increasingly heavily at Ambassador Labs (née Datawire) for about 2 years now, and I don't see that changing. What I'm doing now is trying to get >2 years of accumulated patches in to a submittable state (a lot of the patches were bad; for instance on my main branch git subtree add is broken, but that's fine, because you don't use add all the time like you do split or merge, but that's something I need to fix before submitting it). Assuming that we're going to continue being heavy users of it, and are going to continue to patch issues with it, I'd rather let that live upstream rather than telling all of my coworkers to get it from
<https://github.com/LukeShu/git>.
With a recent change in project scheduling, I anticipate that I'll have bandwidth to be able to handle that. (It's what's giving me adequate time to work through this pile of existing patches, anyway.)
What does being a maintainer consist of? Are there standups that I should join?
Quoted 11 lines
As far as I am concerned, contrib/subtree has always been treated as a borrowed code [*] that is written in a dialect of shell that is different from what our scripts are written in, and there are too many style differences (I wouldn't call them violations---nobody has expected the code there to follow our style, or attempted to enforce our style there) to bother coercing.
[Footnote]
* ... as opposed to a properly maintained part of the git-core proper.
Elsewhere in the thread, you suggested that subtree be taken out of git.git, and live as a standalone project.
I'm not entirely opposed to that, but
1. I'm not sure how whoever picks it up (me) establishes their git-subtree as the "real" subtree (get a blessing from Avery?).
2. I think a lot of the reason why more people don't use git-subtree is that the core 'split' operation doesn't quite work reliably (and also it can be quite slow), and so it doesn't get recommended. I would like nothing more than to improve the 'split' reliability to where it does start to gain adoption, to where we can think about it graduating from contrib/ to git-core.
3. Many systems (Arch Linux and macOS, at least) give users git-subtree as part of the stock Git install. If I'm interested in growing git-subtree adoption, I'd be a fool to give that up :)
On the other hand, I think that in the long-ish term git-subtree wants to be rewritten in a better-suited language. My personal inclination would be Go, but if I ever want it to graduate to git-core, it'd have to be C, huh?
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
Re: [PATCH 04/30] subtree: t7900: use consistent formatting
Quoted 5 lines · Luke Shumaker
Quoted 3 lines
If Luke is volunteering to take over its maintainership, it would be appreciated by its users. It has been in the "abandonware" status for too long.
I think I am volunteering.
Wonderful, and thanks.
Quoted 7 lines
Elsewhere in the thread, you suggested that subtree be taken out of git.git, and live as a standalone project.
I'm not entirely opposed to that, but
1. I'm not sure how whoever picks it up (me) establishes their git-subtree as the "real" subtree (get a blessing from Avery?).
Avery is so distant a past, but a work like this series, while we still have it in contrib/ in my tree, will help build necessary trust in you by the Git user/developer community, and when that happens, it would be obvious to everybody that you would be the new owner of the tool.
And when that happens while the tool is in the contrib/ in my tree, and you'd be an established trusted member of the development community by then, I do not mind if you take it and maintain out of tree, if you keep working on the tool still in contrib/, or if you polish it to the main porcelain status and take it out of contrib/ and make it part of the git-core proper.
Quoted 4 lines
On the other hand, I think that in the long-ish term git-subtree wants to be rewritten in a better-suited language. My personal inclination would be Go, but if I ever want it to graduate to git-core, it'd have to be C, huh?
If somebody is willing to do a rewrite and will maintain it for a long haul, I'd say that it would not necessarily have to be in C especially if it is not performance sensitive.
As long as it is done in a widely available language, that is (which used to man Perl or Python, but my persoonal preference won't carry that much weight these days ;-)
Then folks who really want it in C can rewrite the rewrite on their own after that.
One advantage you may have if you choose to take it out of my tree and make it a standalone project is that you have more latitude on the future implementation technology, but we'd need to start from helping you earn the trust by convincing others that "subtree" would be in good hands with your volunteering ;-)
Thanks.
PATCH 5/30 subtree: t7900: comment subtree_test_create_repo
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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-emailing 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.
--- contrib/subtree/t/t7900-subtree.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
contrib/subtree/t/t7900-subtree.sh +6 -4
@@ -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 () {
Signature · 1 line
2.31.1
PATCH 6/30 subtree: t7900: use 'test' for string equality
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/t/t7900-subtree.sh | 60 ++++++++++++------------------ 1 file changed, 24 insertions(+), 36 deletions(-)
contrib/subtree/t/t7900-subtree.sh +24 -36
@@ -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 ) '
Signature · 1 line
2.31.1
PATCH 7/30 subtree: t7900: delete some dead code
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
--- contrib/subtree/t/t7900-subtree.sh | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
contrib/subtree/t/t7900-subtree.sh +1 -11
@@ -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" ) ) '
Signature · 1 line
2.31.1
PATCH 8/30 subtree: t7900: fix 'verify one file change per commit'
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/t/t7900-subtree.sh | 41 +++++------------------------- 1 file changed, 6 insertions(+), 35 deletions(-)
contrib/subtree/t/t7900-subtree.sh +6 -35
@@ -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 <commit-list ) '
Signature · 1 line
2.31.1
PATCH 9/30 subtree: t7900: rename last_commit_message to last_commit_subject
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/t/t7900-subtree.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
contrib/subtree/t/t7900-subtree.sh +13 -13
@@ -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" ) '
Signature · 1 line
2.31.1
PATCH 10/30 subtree: t7900: add a test for the -h flag
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
It's a dumb test, but it's surprisingly easy to break.
--- contrib/subtree/t/t7900-subtree.sh | 7 +++++++ 1 file changed, 7 insertions(+)
contrib/subtree/t/t7900-subtree.sh +7 -0
@@ -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' #
Signature · 1 line
2.31.1
PATCH 11/30 subtree: t7900: add porcelain tests for 'pull' and 'push'
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
The 'pull' and 'push' subcommands deserve their own sections in the tests. Add some basic tests for them.
--- contrib/subtree/t/t7900-subtree.sh | 131 ++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 2 deletions(-)
contrib/subtree/t/t7900-subtree.sh +129 -2
@@ -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 #
Signature · 1 line
2.31.1
Re: [PATCH 11/30] subtree: t7900: add porcelain tests for 'pull' and 'push'
Quoted 7 lines · 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 <[email protected]>---
contrib/subtree/t/t7900-subtree.sh test_expect_success 'merge the added subproj again, should do nothing' ' · line 206
Quoted 7 lines
contrib/subtree/t/t7900-subtree.sh +2
-2@@ -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 &&
This change doesn't seem to be related to the stated purpose of this patch. Was it included by accident or is it just a drive-by "while at it" fix that seems somewhat related since you're using subtree_test_create_repo() in the newly-added tests? It might deserve mention in the commit message.
contrib/subtree/t/t7900-subtree.sh test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' · line 436
Quoted 11 lines
contrib/subtree/t/t7900-subtree.sh +10
-0@@ -427,6 +427,133 @@ test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' +test_expect_success 'pull requires path given by option --prefix must exist' ' + 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 + ) +'
The use of single-quotes and escaped single-quotes within the single-quoted test body is breaking my brain. Perhaps take advantage of SQ from test-lib.sh and interoplate it into the string rather than dealing with raw single-quotes?
echo "this $SQ is a single-quote"
(After writing the above, I now see that you are just mirroring existing practice in this test script. The single-quotes are confusing, but following existing style may be important -- or not.)
contrib/subtree/t/t7900-subtree.sh test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' · line 476
Quoted 8 lines
contrib/subtree/t/t7900-subtree.sh +8
-0+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 &&
I was going to comment on the unusual:
./"sub proj"
rather than the more typical:
"./sub proj"
but I see that that also is mirroring existing practice in this script, so... [intentionally left blank]
contrib/subtree/t/t7900-subtree.sh test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' · line 503
Quoted 11 lines
contrib/subtree/t/t7900-subtree.sh +11
-0+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 &&
Style: There is an inconsistent mix of "> foo" and ">foo" formatting in the newly-added tests. These days, we prefer ">foo".
Re: [PATCH 11/30] subtree: t7900: add porcelain tests for 'pull' and 'push'
Quoted 14 lines · Eric Sunshine
Quoted 12 lines · 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 <[email protected]>---
contrib/subtree/t/t7900-subtree.sh +2
-2@@ -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" &&
Quoted 8 lines
contrib/subtree/t/t7900-subtree.sh test_expect_success 'merge the added subproj again, should do nothing' ' · line 208
Quoted 2 lines
contrib/subtree/t/t7900-subtree.sh +0
-0test_create_commit "$test_count" main1 && test_create_commit "$test_count/subproj" sub1 &&This change doesn't seem to be related to the stated purpose of this patch. Was it included by accident or is it just a drive-by "while at it" fix that seems somewhat related since you're using
subtree_test_create_repo()in the newly-added tests? It might deserve mention in the commit message.
It was included by accident. I guess I'll move it to be in the "comment subtree_test_create_repo" commit, and mention it in the commit message there.
Quoted 17 lines
contrib/subtree/t/t7900-subtree.sh test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' · line 436
Quoted 11 lines
contrib/subtree/t/t7900-subtree.sh +10
-0@@ -427,6 +427,133 @@ test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' +test_expect_success 'pull requires path given by option --prefix must exist' ' + 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 + ) +'The use of single-quotes and escaped single-quotes within the single-quoted test body is breaking my brain. Perhaps take advantage of SQ from
test-lib.shand interoplate it into the string rather than dealing with raw single-quotes?
Quoted 5 lines
echo "this $SQ is a single-quote"
(After writing the above, I now see that you are just mirroring existing practice in this test script. The single-quotes are confusing, but following existing style may be important -- or not.)
I don't think I'll change it, for consistency with the rest of the file... and I don't want to change the rest of the file, because there's enough churn already. But thanks for the tip, I wasn't aware of $SQ.
Quoted 11 lines
contrib/subtree/t/t7900-subtree.sh test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' · line 476
Quoted 8 lines
contrib/subtree/t/t7900-subtree.sh +8
-0+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 &&I was going to comment on the unusual:
Quoted 8 lines
./"sub proj"rather than the more typical:
"./sub proj"but I see that that also is mirroring existing practice in this script, so... [intentionally left blank]
...yeah
Quoted 12 lines
contrib/subtree/t/t7900-subtree.sh test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' · line 503
Quoted 11 lines
contrib/subtree/t/t7900-subtree.sh +11
-0+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 &&
Quoted 2 lines
Style: There is an inconsistent mix of "> foo" and ">foo" formatting in the newly-added tests. These days, we prefer ">foo".
Indeed, so do I :) That test was copied with minimal modification from the pre-existing 'split requires option --prefix' test, which wrote it that way. I guess I'll update the formatting commit to also normalize away the whitespace after ">"s.
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
PATCH 12/30 subtree: don't have loose code outside of a function
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
Shove all of the loose code inside of a main() function.
"Ignore space change" is probably helpful when viewing this diff.
--- contrib/subtree/git-subtree.sh | 245 +++++++++++++++++---------------- 1 file changed, 125 insertions(+), 120 deletions(-)
contrib/subtree/git-subtree.sh +125 -120
@@ -4,10 +4,7 @@ # # Copyright (C) 2009 Avery Pennarun <[email protected]> # -if test $# -eq 0 -then - set -- -h -fi + OPTS_SPEC="\ git subtree add --prefix=<prefix> <commit> git subtree add --prefix=<prefix> <repository> <ref>
@@ -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 "$@"
Signature · 1 line
2.31.1
Re: [PATCH 12/30] subtree: don't have loose code outside of a function
Quoted 1 line · Luke Shumaker
"Ignore space change" is probably helpful when viewing this diff.
For mailing-list reading, the git show -w is
---
contrib/subtree/git-subtree.sh +14 -9
@@ -4,10 +4,7 @@ # # Copyright (C) 2009 Avery Pennarun <[email protected]> # -if test $# -eq 0 -then - set -- -h -fi + OPTS_SPEC="\ git subtree add --prefix=<prefix> <commit> git subtree add --prefix=<prefix> <repository> <ref>
@@ -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,6 +77,15 @@ ensure_single_rev () { fi } +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 + while test $# -gt 0 do opt="$1"
@@ -205,6 +207,9 @@ debug "dir: {$dir}" debug "opts: {$*}" debug + "cmd_$command" "$@" +} + cache_setup () { cachedir="$GIT_DIR/subtree-cache/$$" rm -rf "$cachedir" ||
@@ -898,4 +903,4 @@ cmd_push () { fi } -"cmd_$command" "$@" +main "$@"
Re: [PATCH 12/30] subtree: don't have loose code outside of a function
In reply to Luke ShumakerQuoted 5 lines · 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 <[email protected]>
What is the purpose of this change? Does some subsequent commit depend upon this or is it just a personal preference? The commit message explains the "what" of the change but not the "why".
Re: [PATCH 12/30] subtree: don't have loose code outside of a function
Quoted 11 lines · Eric Sunshine
Quoted 5 lines · 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 <[email protected]>What is the purpose of this change? Does some subsequent commit depend upon this or is it just a personal preference? The commit message explains the "what" of the change but not the "why".
Dropping the commit would surely cause me much trouble with rebasing both the subsequent commits in this patchset and the commits I haven't yet submitted. But I don't think they "depend" on it.
I guess it is personal preference... one that I've developed from years of maintaining Bash scripts. It's in a nearby part of my brain to "avoid global variables". It's related to my notion that the reason most people think shell scripts are so terrible is that most people don't treat it like a real programming language and don't apply normal programming best practices; that not littering code around outside of a function is part of treating it like a real language (at least once the program grows beyond a certain size, which git-subtree surely has). It's probably related to the Python idiom
if __name__ == "__main__":
main()that is often seen at the bottom of Python scripts.
In this specific case, it's also moving the set -- -h, the git rev-parse --parseopt, and the . git-sh-setup to be closer to all the rest of the argument parsing, which is a readability win on its own, IMO.
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
Re: [PATCH 12/30] subtree: don't have loose code outside of a function
Quoted 10 lines · Luke Shumaker
Quoted 3 lines · Eric Sunshine
What is the purpose of this change? Does some subsequent commit depend upon this or is it just a personal preference? The commit message explains the "what" of the change but not the "why".
Dropping the commit would surely cause me much trouble with rebasing both the subsequent commits in this patchset and the commits I haven't yet submitted. But I don't think they "depend" on it.
I guess it is personal preference... [...]
That's fine. I wasn't suggesting removing the commit but was interested in having the commit message explain the reason for the change, which is often the most important part of the commit message to convince readers (reviewers) that the patch isn't just needless noise. Obviously, if changes in subsequent patches become easier by making this change, then that's easier to explain than something which is mere personal preference -- which isn't to say that such preference isn't important, especially if you're going to be living in the code for a while.
Quoted 4 lines
In this specific case, it's also moving the
set -- -h, thegit rev-parse --parseopt, and the. git-sh-setupto be closer to all the rest of the argument parsing, which is a readability win on its own, IMO.
If you happen to re-roll, perhaps update the commit message to include a small bit of your explanation (which I've mostly snipped here). The last bit about moving set -- -h and whatnot closer to the rest of the argument parsing -- basically improving encapsulation -- may be justification enough for readers.
Re: [PATCH 12/30] subtree: don't have loose code outside of a function
Quoted 5 lines · Eric Sunshine
If you happen to re-roll, perhaps update the commit message to include a small bit of your explanation (which I've mostly snipped here). The last bit about moving
set -- -hand whatnot closer to the rest of the argument parsing -- basically improving encapsulation -- may be justification enough for readers.
Whenever I end up explaining something on-list, I assume that I should update either a comment or a commit-message when I re-roll :)
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
PATCH 13/30 subtree: more consistent error propagation
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
contrib/subtree/git-subtree.sh +14 -14
@@ -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."
Signature · 1 line
2.31.1
PATCH 14/30 subtree: drop support for git < 1.7
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
contrib/subtree/git-subtree.sh +4 -15
@@ -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 }
Signature · 1 line
2.31.1
Re: [PATCH 14/30] subtree: drop support for git < 1.7
Quoted 1 line · Luke Shumaker
"Ignore space change" is probably helpful when viewing this diff.
For mailing-list reading, the git show -w is:
---
contrib/subtree/git-subtree.sh +0 -11
@@ -852,16 +852,6 @@ cmd_merge () { rev="$new" fi - version=$(git version) - if test "$version" \< "git version 1.7" - then - if test -n "$message" - then - git merge -s subtree --message="$message" "$rev" - else - git merge -s subtree "$rev" - fi - else if test -n "$message" then git merge -Xsubtree="$prefix" \
@@ -869,7 +859,6 @@ cmd_merge () { else git merge -Xsubtree="$prefix" $rev fi - fi } cmd_pull () {
Re: [PATCH 14/30] subtree: drop support for git < 1.7
In reply to Luke ShumakerQuoted 2 lines · 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.
s/nescessary/necessary/
Quoted 1 line
Signed-off-by Luke Shumaker <[email protected]>
Is there a higher reason for this change aside from "let's do it because we can"? For instance, are subsequent changes going to take advantage of features only present in more recent Git versions which would be painful or impossible to support with the older Git?
The downside of this change is that, while git-subtree may live in git.git, it's still just "contrib", so people might grab git-subtree from a modern git.git but then end up using it with an older Git installation. That's not to say that doing such a thing is guaranteed to work anyhow, but we don't need to make it harder on people if there isn't a good reason (hence my question about whether subsequent changes will actually take advantage of newer Git features).
Re: [PATCH 14/30] subtree: drop support for git < 1.7
Quoted 6 lines · Eric Sunshine
Quoted 2 lines · 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.
s/nescessary/necessary/
Ack.
Quoted 7 lines
Quoted 1 line
Signed-off-by Luke Shumaker <[email protected]>Is there a higher reason for this change aside from "let's do it because we can"? For instance, are subsequent changes going to take advantage of features only present in more recent Git versions which would be painful or impossible to support with the older Git?
Quoted 7 lines
The downside of this change is that, while git-subtree may live in git.git, it's still just "contrib", so people might grab git-subtree from a modern git.git but then end up using it with an older Git installation. That's not to say that doing such a thing is guaranteed to work anyhow, but we don't need to make it harder on people if there isn't a good reason (hence my question about whether subsequent changes will actually take advantage of newer Git features).
With the goal of making the whole thing easier to hack on, this just seemed like an easy (if small) piece of fat to trim.
I guess I should include here that my bias is: With the 'git' package that Parabola inherits from Arch Linux, you install 'git', you get a working 'git subtree'. If you want 'git send-email' to work, you also need to install several other Perl packages. Like, it might live in the "contrib" directory, but it's de-facto at least as much a "part of" Git as send-email is.
So that's the mindset I started from. It looks like the latest macOS supports me on that, but other distros like Fedora don't (Fedora has a separate 'git-subtree' package). If I take a step back, I realize that mindset is flawed, but that's where I started from.
I don't think any of the other work depends on this (I think the only commit that will conflict if we drop it is the "rename a some variables" commit in this patchset). It's very possible that something else I do relies on newer git features (I'm not testing against older git), but that's not something I did intentionally.
I just figured this would be a welcome piece of cleanup. If that's not the case, I don't have a problem dropping it.
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
Re: [PATCH 14/30] subtree: drop support for git < 1.7
Quoted 29 lines · Luke Shumaker
Quoted 5 lines · Eric Sunshine
Is there a higher reason for this change aside from "let's do it because we can"? For instance, are subsequent changes going to take advantage of features only present in more recent Git versions which would be painful or impossible to support with the older Git?
Quoted 7 lines
The downside of this change is that, while git-subtree may live in git.git, it's still just "contrib", so people might grab git-subtree from a modern git.git but then end up using it with an older Git installation. That's not to say that doing such a thing is guaranteed to work anyhow, but we don't need to make it harder on people if there isn't a good reason (hence my question about whether subsequent changes will actually take advantage of newer Git features).
With the goal of making the whole thing easier to hack on, this just seemed like an easy (if small) piece of fat to trim.
I guess I should include here that my bias is: With the 'git' package that Parabola inherits from Arch Linux, you install 'git', you get a working 'git subtree'. If you want 'git send-email' to work, you also need to install several other Perl packages. Like, it might live in the "contrib" directory, but it's de-facto at least as much a "part of" Git as send-email is.
So that's the mindset I started from. It looks like the latest macOS supports me on that, but other distros like Fedora don't (Fedora has a separate 'git-subtree' package). If I take a step back, I realize that mindset is flawed, but that's where I started from.
Quoted 8 lines
I don't think any of the other work depends on this (I think the only commit that will conflict if we drop it is the "rename a some variables" commit in this patchset). It's very possible that something else I do relies on newer git features (I'm not testing against older git), but that's not something I did intentionally.
I just figured this would be a welcome piece of cleanup. If that's not the case, I don't have a problem dropping it.
As a person who does not and has never used git-subtree, I don't have a strong opinion, and any git-subtree opinion I might have wouldn't carry any weight. I do have a bit of reflexive negative reaction to such removals in general if there's no clear and strong benefit, perhaps because my daily-use computers are old (perhaps ancient, as in 10-25 years old), so I am regularly stung by support being dropped by packages I use. That's why I was asking if later patches would take advantage of some newer Git feature.
Anyhow, I wasn't specifically asking for the patch to be dropped. As a reviewer I rather wanted to better understand the reason for the change beyond the somewhat hand-wavy "git-subtree now lives in-tree". If you happen to re-roll, perhaps you can expand the commit message a bit with something more concrete (for instance, how some packagers include git-subtree by default) to better sell the patch to reviewers who actually have investment in git-subtree (of which I am not one). Considering how old Git <1.7 is, it's quite likely that no current git-subtree users/reviewers would care about dropping support for such old versions.
Re: [PATCH 14/30] subtree: drop support for git < 1.7
Quoted 40 lines · Eric Sunshine
Quoted 29 lines · Luke Shumaker
Quoted 5 lines · Eric Sunshine
Is there a higher reason for this change aside from "let's do it because we can"? For instance, are subsequent changes going to take advantage of features only present in more recent Git versions which would be painful or impossible to support with the older Git?
Quoted 7 lines
The downside of this change is that, while git-subtree may live in git.git, it's still just "contrib", so people might grab git-subtree from a modern git.git but then end up using it with an older Git installation. That's not to say that doing such a thing is guaranteed to work anyhow, but we don't need to make it harder on people if there isn't a good reason (hence my question about whether subsequent changes will actually take advantage of newer Git features).
With the goal of making the whole thing easier to hack on, this just seemed like an easy (if small) piece of fat to trim.
I guess I should include here that my bias is: With the 'git' package that Parabola inherits from Arch Linux, you install 'git', you get a working 'git subtree'. If you want 'git send-email' to work, you also need to install several other Perl packages. Like, it might live in the "contrib" directory, but it's de-facto at least as much a "part of" Git as send-email is.
So that's the mindset I started from. It looks like the latest macOS supports me on that, but other distros like Fedora don't (Fedora has a separate 'git-subtree' package). If I take a step back, I realize that mindset is flawed, but that's where I started from.
Quoted 8 lines
I don't think any of the other work depends on this (I think the only commit that will conflict if we drop it is the "rename a some variables" commit in this patchset). It's very possible that something else I do relies on newer git features (I'm not testing against older git), but that's not something I did intentionally.
I just figured this would be a welcome piece of cleanup. If that's not the case, I don't have a problem dropping it.
Quoted 8 lines
As a person who does not and has never used git-subtree, I don't have a strong opinion, and any git-subtree opinion I might have wouldn't carry any weight. I do have a bit of reflexive negative reaction to such removals in general if there's no clear and strong benefit, perhaps because my daily-use computers are old (perhaps ancient, as in 10-25 years old), so I am regularly stung by support being dropped by packages I use. That's why I was asking if later patches would take advantage of some newer Git feature.
I'm sending this from my work laptop, which is a little newer (2015), but my personal laptop (2007) is sitting on the end-table. So I commiserate. I'm a modern-software on old-hardware kind of guy though, so I don't mind dropping support for old software versions.
Quoted 10 lines
Anyhow, I wasn't specifically asking for the patch to be dropped. As a reviewer I rather wanted to better understand the reason for the change beyond the somewhat hand-wavy "git-subtree now lives in-tree". If you happen to re-roll, perhaps you can expand the commit message a bit with something more concrete (for instance, how some packagers include git-subtree by default) to better sell the patch to reviewers who actually have investment in git-subtree (of which I am not one). Considering how old Git <1.7 is, it's quite likely that no current git-subtree users/reviewers would care about dropping support for such old versions.
I'll expand the commit message.
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
PATCH 15/30 subtree: use `git merge-base --is-ancestor`
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
contrib/subtree/git-subtree.sh +1 -15
@@ -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
Signature · 1 line
2.31.1
PATCH 16/30 subtree: use git-sh-setup's `say`
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
subtree currently defines its own say implementation, rather than using git-sh-setups's implementation. Change that, don't re-invent the wheel.
--- contrib/subtree/git-subtree.sh | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
contrib/subtree/git-subtree.sh +7 -15
@@ -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 $?
Signature · 1 line
2.31.1
PATCH 17/30 subtree: use more explicit variable names for cmdline args
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
Make it painfully obvious when reading the code which variables are direct parsings of command line arguments.
--- contrib/subtree/git-subtree.sh | 132 ++++++++++++++++----------------- 1 file changed, 66 insertions(+), 66 deletions(-)
contrib/subtree/git-subtree.sh +66 -66
@@ -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'."
Signature · 1 line
2.31.1
PATCH 18/30 subtree: use $* instead of $@ as appropriate
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
$* 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.
--- contrib/subtree/git-subtree.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
contrib/subtree/git-subtree.sh +3 -3
@@ -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 }
Signature · 1 line
2.31.1
Re: [PATCH 18/30] subtree: use $* instead of $@ as appropriate
Quoted 4 lines · 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.
Can we be explicit and say "$@" in the commit message rather than bare $@ since the unquoted form is not magical and acts exactly like $*.
Also: s/in to/into/
Nit: I have some trouble following what the commit message is actually trying to say with "smash things" and "separate strings". It might be simpler to say merely that use of "$@" in these particular instances is overkill and possibly misleading to readers not familiar with the finer details of $* vs. "$@".
The patch itself makes sense.
Re: [PATCH 18/30] subtree: use $* instead of $@ as appropriate
Quoted 12 lines · Eric Sunshine
Quoted 4 lines · 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.
Can we be explicit and say "$@" in the commit message rather than bare $@ since the unquoted form is not magical and acts exactly like $*.
Also: s/in to/into/
Quoted 7 lines
Nit: I have some trouble following what the commit message is actually trying to say with "smash things" and "separate strings". It might be simpler to say merely that use of "$@" in these particular instances is overkill and possibly misleading to readers not familiar with the finer details of $* vs. "$@".
The patch itself makes sense.
How's this:
---
subtree: use "$*" instead of "$@" as appropriate
"$*" is for when you want to concatenate the args together, whitespace-separated; and "$@" is for when you want them to be separate strings.
There are several places in subtree that erroneously use $@ when concatenating args together into an error message.
For instance, if the args are argv[1]="dead" and argv[2]="beef", then the line
die "You must provide exactly one revision. Got: '$@'"
surely intends to call 'die' with the argument
argv[1]="You must provide exactly one revision. Got: 'dead beef'"
however, because the line used $@ instead of $*, it will actually call 'die' with the arguments
argv[1]="You must provide exactly one revision. Got: 'dead" argv[2]="beef'"
This isn't a big deal, because 'die' concatenates its arguments together anyway (using "$*"). But that doesn't change the fact that it was a mistake to use $@ instead of $*, even though in the end $@ still ended up doing the right thing.
---
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
Re: [PATCH 18/30] subtree: use $* instead of $@ as appropriate
Quoted 6 lines · Luke Shumaker
Quoted 5 lines · Eric Sunshine
Nit: I have some trouble following what the commit message is actually trying to say with "smash things" and "separate strings". It might be simpler to say merely that use of "$@" in these particular instances is overkill and possibly misleading to readers not familiar with the finer details of $* vs. "$@".
Oof, I somehow misread the code this patch is touching and ended up confusing myself, and the confusion bled into my review comments. Sorry.
Quoted 23 lines
How's this:
---
subtree: use "$*" instead of "$@" as appropriate"$*" is for when you want to concatenate the args together, whitespace-separated; and "$@" is for when you want them to be separate strings.
There are several places in subtree that erroneously use $@ when concatenating args together into an error message.
For instance, if the args are argv[1]="dead" and argv[2]="beef", then the line
die "You must provide exactly one revision. Got: '$@'"
surely intends to call 'die' with the argument
argv[1]="You must provide exactly one revision. Got: 'dead beef'"
however, because the line used $@ instead of $*, it will actually call 'die' with the arguments
Quoted 7 lines
argv[1]="You must provide exactly one revision. Got: 'dead" argv[2]="beef'"
This isn't a big deal, because 'die' concatenates its arguments together anyway (using "$*"). But that doesn't change the fact that it was a mistake to use $@ instead of $*, even though in the end $@ still ended up doing the right thing.
This explanation spells out the problem nicely.
PATCH 19/30 subtree: give `$(git --exec-path)` precedence over `$PATH`
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/subtree/git-subtree.sh +1 -1
@@ -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=
Signature · 1 line
2.31.1
Re: [PATCH 19/30] subtree: give `$(git --exec-path)` precedence over `$PATH`
Quoted 16 lines · Luke Shumaker
From: Luke Shumaker <[email protected]>
Other Git commands implemented in shell give
git --exec-pathprecedence 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 <[email protected]>--- contrib/subtree/git-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)contrib/subtree/git-subtree.sh +0
-0
contrib/subtree/git-subtree.sh rejoin merge the new branch back into HEAD · line 31
Quoted 5 lines
contrib/subtree/git-subtree.sh +1
-1@@ -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
The history of git-subtree.sh suggests that instead of this change we'd be better of removing this PATH assignment, and then later doing:
. "$(git --exec-path)/git-sh-setup"
Isn't that closer to what git-subtree.sh wants here?
PATCH 20/30 subtree: use "^{commit}" instead of "^0"
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
They are synonyms. Both are used in the file. ^{commit} is clearer, so "standardize" on that.
--- contrib/subtree/git-subtree.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
contrib/subtree/git-subtree.sh +2 -2
@@ -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)
Signature · 1 line
2.31.1
Re: [PATCH 20/30] subtree: use "^{commit}" instead of "^0"
Quoted 24 lines · Luke Shumaker
From: Luke Shumaker <[email protected]>
They are synonyms. Both are used in the file. ^{commit} is clearer, so "standardize" on that.
Signed-off-by Luke Shumaker <[email protected]>--- contrib/subtree/git-subtree.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)contrib/subtree/git-subtree.sh +1
-1@@ -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)
contrib/subtree/git-subtree.sh find_existing_splits () { · line 355
Quoted 8 lines
contrib/subtree/git-subtree.sh +1
-1@@ -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)
Not a new problem, but those error messages seem weird/bad, isn't that message originally from find_existing_splits() and copied over to find_latest_squash() where talking about "split hash" doesn't make sense?
I'd expect something like "could not peel $b to commit" as the error for both.
PATCH 21/30 subtree: parse revs in individual cmd_ functions
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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'.
--- contrib/subtree/git-subtree.sh | 62 +++++++++++++--------------------- 1 file changed, 24 insertions(+), 38 deletions(-)
contrib/subtree/git-subtree.sh +24 -38
@@ -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 () {
Signature · 1 line
2.31.1
PATCH 22/30 subtree: remove duplicate check
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 4 ---- 1 file changed, 4 deletions(-)
contrib/subtree/git-subtree.sh +0 -4
@@ -641,10 +641,6 @@ process_split_commit () { } cmd_add () { - if test -e "$dir" - then - die "'$dir' already exists. Cannot add." - fi ensure_clean
Signature · 1 line
2.31.1
PATCH 23/30 subtree: add comments and sanity checks
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
--- contrib/subtree/git-subtree.sh | 62 ++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-)
contrib/subtree/git-subtree.sh +60 -2
@@ -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
Signature · 1 line
2.31.1
Re: [PATCH 23/30] subtree: add comments and sanity checks
contrib/subtree/git-subtree.sh rev_exists () { · line 265
Quoted 7 lines · Luke Shumaker
Signed-off-by Luke Shumaker <[email protected]>---
contrib/subtree/git-subtree.sh +2
-0@@ -248,17 +263,22 @@ rev_exists () { +# Usage: try_remove_previous REV +# # if a commit doesn't have a parent, this might not work. But we only want
s/if/If/ perhaps
Quoted 11 lines
contrib/subtree/git-subtree.sh +3
-1# 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.@@ -302,10 +322,12 @@ find_latest_squash () { +# Usage: find_existing_splits DIR REV find_existing_splits () { + assert test $# = 2 debug "Looking for prior splits..." dir="$1" - revs="$2" + rev="$2"
contrib/subtree/git-subtree.sh find_existing_splits () { · line 337
Quoted 3 lines
contrib/subtree/git-subtree.sh +1
-1@@ -314,7 +336,7 @@ find_existing_splits () { 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" |
The caller of this function is passing in "$revs". Did you make this semantic change because the caller's revs is guaranteed to be a single rev? In any case, this change may deserve mention in the commit message so readers don't have to wonder about it.
Re: [PATCH 23/30] subtree: add comments and sanity checks
Quoted 11 lines · Eric Sunshine
contrib/subtree/git-subtree.sh rev_exists () { · line 265
Quoted 7 lines · Luke Shumaker
Signed-off-by Luke Shumaker <[email protected]>---
contrib/subtree/git-subtree.sh +2
-0@@ -248,17 +263,22 @@ rev_exists () { +# Usage: try_remove_previous REV +# # if a commit doesn't have a parent, this might not work. But we only wants/if/If/ perhaps
Ack.
Quoted 11 lines
Quoted 11 lines
contrib/subtree/git-subtree.sh +3
-1# 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.@@ -302,10 +322,12 @@ find_latest_squash () { +# Usage: find_existing_splits DIR REV find_existing_splits () { + assert test $# = 2 debug "Looking for prior splits..." dir="$1" - revs="$2" + rev="$2"@@ -314,7 +336,7 @@ find_existing_splits () {
Quoted 8 lines
contrib/subtree/git-subtree.sh find_existing_splits () { · line 339
Quoted 3 lines
contrib/subtree/git-subtree.sh +1
-1git 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" |The caller of this function is passing in "$revs". Did you make this semantic change because the caller's
revsis guaranteed to be a single rev? In any case, this change may deserve mention in the commit message so readers don't have to wonder about it.
No it's not? The only caller is
unrevs="$(find_existing_splits "$dir" "$rev")" || exit $?
But yeah, this would be a good thing for me to call out in the commit message.
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
PATCH 24/30 subtree: don't let debug and progress output clash
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
contrib/subtree/git-subtree.sh +6 -1
@@ -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 }
Signature · 1 line
2.31.1
Re: [PATCH 24/30] subtree: don't let debug and progress output clash
Quoted 2 lines · Luke Shumaker
Currently, debug output (triggered by passing '-d') and progress output stomp on eachother. The debug output is just streamed as lines to
s/eachother/each other/
Quoted 7 lines
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.
Makes perfect sense when output is to a terminal, though might be annoying for the person who redirects stderr to a file. Just idly wondering if it makes sense to take that case into consideration... (but maybe it doesn't matter much when someone is working at debugging a problem).
Quoted 6 lines
Signed-off-by Luke Shumaker <[email protected]>---
contrib/subtree/git-subtree.sh +0
-0@@ -53,7 +53,12 @@ debug () { progress () { if test -z "$GIT_QUIET"
contrib/subtree/git-subtree.sh debug () { · line 63
Quoted 10 lines
contrib/subtree/git-subtree.sh +6
-1then - printf "%s\r" "$*" >&2 + if test -n "$arg_debug" + then + printf "progress: %s\n" "$*" >&2 + else + printf "%s\r" "$*" >&2 + fi fi }
Subjective (not necessarily worth changing): An echo would suffice in place of printf "...\n":
echo "progress: $*" >&2
It _might_ be worthwhile to have an in-code comment here explaining why progress() behaves differently in debug mode, especially if the reader is confused about why one case explicitly emits "progress:" and the other doesn't.
Re: [PATCH 24/30] subtree: don't let debug and progress output clash
Quoted 6 lines · Eric Sunshine
Quoted 2 lines · Luke Shumaker
Currently, debug output (triggered by passing '-d') and progress output stomp on eachother. The debug output is just streamed as lines to
s/eachother/each other/
Ack.
Quoted 8 lines
Quoted 7 lines
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.
Quoted 5 lines
Makes perfect sense when output is to a terminal, though might be annoying for the person who redirects stderr to a file. Just idly wondering if it makes sense to take that case into consideration... (but maybe it doesn't matter much when someone is working at debugging a problem).
The '%s\r' isn't really useful when written to a file, so this change is useful in the file case too. I'll add a comment and update the commit-message.
Quoted 20 lines
Quoted 6 lines
Signed-off-by Luke Shumaker <[email protected]>---
contrib/subtree/git-subtree.sh +0
-0@@ -53,7 +53,12 @@ debug () { progress () { if test -z "$GIT_QUIET"contrib/subtree/git-subtree.sh debug () { · line 63
Quoted 10 lines
contrib/subtree/git-subtree.sh +6
-1then - printf "%s\r" "$*" >&2 + if test -n "$arg_debug" + then + printf "progress: %s\n" "$*" >&2 + else + printf "%s\r" "$*" >&2 + fi fi }Subjective (not necessarily worth changing): An
echowould suffice in place ofprintf "...\n":
Quoted 1 line
echo "progress: $*" >&2
echo would suffice, but I prefer the printf.
Quoted 4 lines
It _might_ be worthwhile to have an in-code comment here explaining why
progress()behaves differently in debug mode, especially if the reader is confused about why one case explicitly emits "progress:" and the other doesn't.
Adding a comment is a good idea, I'll do that.
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
Re: [PATCH 24/30] subtree: don't let debug and progress output clash
Quoted 10 lines · Luke Shumaker
Quoted 5 lines · Eric Sunshine
Makes perfect sense when output is to a terminal, though might be annoying for the person who redirects stderr to a file. Just idly wondering if it makes sense to take that case into consideration... (but maybe it doesn't matter much when someone is working at debugging a problem).
The '%s\r' isn't really useful when written to a file, so this change is useful in the file case too. I'll add a comment and update the commit-message.
Ah, right. I didn't pay close enough attention to really notice that the "\r"-terminated line was going to stderr, so ignore that bit in my review comment.
PATCH 25/30 subtree: have $indent actually affect indentation
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 42 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-)
contrib/subtree/git-subtree.sh +24 -18
@@ -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 $?
Signature · 1 line
2.31.1
PATCH 26/30 subtree: give the docs a once-over
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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 <variables> used to give command arguments, give slightly longer, descriptive names. Like <local-commit> instead of just <commit>.
- 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 ([<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.
--- contrib/subtree/git-subtree.sh | 4 +- contrib/subtree/git-subtree.txt | 162 +++++++++++++++----------------- 2 files changed, 80 insertions(+), 86 deletions(-)
contrib/subtree/git-subtree.sh +2 -2
@@ -9,9 +9,9 @@ OPTS_SPEC="\ git subtree add --prefix=<prefix> <commit> git subtree add --prefix=<prefix> <repository> <ref> git subtree merge --prefix=<prefix> <commit> +git subtree split --prefix=<prefix> [<commit>] git subtree pull --prefix=<prefix> <repository> <ref> git subtree push --prefix=<prefix> <repository> <ref> -git subtree split --prefix=<prefix> <commit> -- 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 "
contrib/subtree/git-subtree.txt +78 -84
279 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 27/30 subtree: allow --squash to be used with --rejoin
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- 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(-)
contrib/subtree/git-subtree.sh +26 -7
@@ -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
contrib/subtree/git-subtree.txt +11 -16
@@ -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 <repository> <remote-ref>:: Exactly like 'merge', but parallels 'git pull' in that
@@ -124,8 +121,8 @@ push <repository> <remote-ref>:: <remote-ref>. 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>:: ---message=<message>:: - This option is only valid for 'add', 'merge', 'pull', and 'split --rejoin'. - Specify <message> 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>:: +--message=<message>:: + Specify <message> 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
contrib/subtree/t/t7900-subtree.sh +35 -0
@@ -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" &&
Signature · 1 line
2.31.1
Re: [PATCH 27/30] subtree: allow --squash to be used with --rejoin
Quoted 16 lines · 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 --rejoinamounts to "automatically go ahead and do agit subtree mergeafter doing the maingit subtree split", so it's weird and arbitrary that you can't pass--squashtogit subtree split --rejoinlike you cangit subtree merge. It's weird thatgit subtree split --rejoininheritsgit subtree merge's--messagebut not--squash.Reconcile the situation by just having
split --rejoinactually just callmergeinternally (or calladdinstead, as appropriate), so it can get access to the fullmergebehavior, including--squash.Signed-off-by Luke Shumaker <[email protected]>---
contrib/subtree/t/t7900-subtree.sh test_expect_success 'split sub dir/ with --rejoin and --message' ' · line 329
Quoted 6 lines
contrib/subtree/t/t7900-subtree.sh +6
-0@@ -324,6 +324,41 @@ test_expect_success 'split sub dir/ with --rejoin and --message' ' +test_expect_success 'split "sub dir"/ with --rejoin and --squash' ' + [...] + SPLIT=$(git subtree split --prefix="sub dir" --annotate="*" --rejoin --squash) && + + ! git merge-base --is-ancestor $SUB HEAD && + ! git merge-base --is-ancestor $SPLIT HEAD &&
It's preferable to use test_must_fail rather than ! for Git commands (but not for non-Git commands) since test_must_fail correctly distinguishes between an expected failure and an unexpected one such as a crash, whereas ! can't make that distinction and would even consider a crashed Git invocation to be successful.
Existing tests in this script already employ test_must_fail rather than !, so using test_must_fail would also match precedent.
Re: [PATCH 27/30] subtree: allow --squash to be used with --rejoin
Quoted 6 lines · Eric Sunshine
contrib/subtree/t/t7900-subtree.sh test_expect_success 'split sub dir/ with --rejoin and --message' ' · line 350
Quoted 2 lines · Luke Shumaker
contrib/subtree/t/t7900-subtree.sh +2
-0+ ! git merge-base --is-ancestor $SUB HEAD && + ! git merge-base --is-ancestor $SPLIT HEAD &&It's preferable to use
test_must_failrather than!for Git commands
Indeed, this was an oversight on my part. I'll adjust it.
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
PATCH 28/30 subtree: allow 'split' flags to be passed to 'push'
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
'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.
--- 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(-)
contrib/subtree/git-subtree.sh +3 -3
@@ -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'."
contrib/subtree/git-subtree.txt +8 -7
@@ -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=<message>:: Specify <message> 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=<annotation>:: When generating synthetic history, add <annotation> as a prefix to each
contrib/subtree/t/t7900-subtree.sh +212 -2
226 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 29/30 subtree: push: allow specifying a local rev other than HEAD
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
'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.
--- 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(-)
contrib/subtree/git-subtree.sh +17 -7
@@ -11,7 +11,7 @@ git subtree add --prefix=<prefix> <repository> <ref> git subtree merge --prefix=<prefix> <commit> git subtree split --prefix=<prefix> [<commit>] git subtree pull --prefix=<prefix> <repository> <ref> -git subtree push --prefix=<prefix> <repository> <ref> +git subtree push --prefix=<prefix> <repository> <refspec> -- 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 <repository> <ref>" + die "You must provide <repository> <refspec>" 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
contrib/subtree/git-subtree.txt +8 -6
@@ -16,7 +16,7 @@ SYNOPSIS [verse] 'git subtree' [<options>] -P <prefix> pull <repository> <remote-ref> -'git subtree' [<options>] -P <prefix> push <repository> <remote-ref> +'git subtree' [<options>] -P <prefix> push <repository> <refspec> DESCRIPTION -----------
@@ -115,11 +115,13 @@ pull <repository> <remote-ref>:: it fetches the given ref from the specified remote repository. -push <repository> <remote-ref>:: - Does a 'split' using the <prefix> subtree of HEAD and then - does a 'git push' to push the result to the <repository> and - <remote-ref>. This can be used to push your subtree to - different branches of the remote repository. +push <repository> [+][<local-commit>:]<remote-ref>:: + Does a 'split' using the <prefix> subtree of <local-commit> + and then does a 'git push' to push the result to the + <repository> and <remote-ref>. This can be used to push your + subtree to different branches of the remote repository. Just + as with 'split', if no <local-commit> is given, then HEAD is + used. The optional leading '+' is ignored. OPTIONS FOR ALL COMMANDS ------------------------
contrib/subtree/t/t7900-subtree.sh +22 -0
@@ -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 #
Signature · 1 line
2.31.1
PATCH 30/30 subtree: be stricter about validating flags
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 89 ++++++++++++++++------- contrib/subtree/t/t7900-subtree.sh | 111 +++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 25 deletions(-)
contrib/subtree/git-subtree.sh +64 -25
@@ -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."
contrib/subtree/t/t7900-subtree.sh +111 -0
147 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH 30/30] subtree: be stricter about validating flags
Quoted 7 lines
From: Luke Shumaker <[email protected]>
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.
Quoted 6 lines
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 <[email protected]>......
Thank you for the recent works, Luke.
I'd like to know if you are aware or working on the issue that branches before "git subtree add --squash" are pushed via "git subtree push", which has been reported by me at Tue, 16 Jul 2019 02:30:44 +0800, as I haven't seen an obvious fix about it in the recent patches in a quick glance.
Below is the original report (with a slight modification):
-----------------------------------------------------------------------
Say we have a repository with "master" and "sub" branches like below:
A---B---C---D---E---F master
/
X---Y
X---Y subwhere commits A and B include changes in subdirectory "sub", commit C removes subdirectory "sub", commit D is generated by "git subtree add -P sub Y", and commits E and F also include changes in subdirectory "sub".
We'd get this if we run "git subtree push -P sub . sub" on master at F:
X---Y---E'--F' sub (after push)
On the other hand, if we have simliar trees except that commit D is generated by "git subtree add --squash -P sub Y":
A---B---C---D---E---F master
/
Y'
X---Y subWe'd expect to get this after we run "git subtree push -P sub . sub" on master at F:
X---Y---E'--F' sub (after push, expected)
But actually we get this (in Git 2.22.0):
A---B---C---D'--E'--F' sub (after push, actual)
/
X---YThis seems to be a side effect of 2.7.0 -> 2.7.1 in which a change is made to include merged branches in "git subtree push", but mistakenly causes branches before "git subtree add --squash" be included.
This bug is especially obvious if we simply run git subtree push after a git subtree add --squash:
If master is at commit D, which is generated bygit subtree add --squash -P sub Y:
A---B---C---D master
/
Y'
X---Y subAfter running git subtree push -P sub . sub, we get:
A---B---C---D' sub (after push, actual)
/
X---YWhile the sub branch should not change at all!
This bug, seemingly introduced by 933cfeb90b5d03b4096db6d60494a6eedea25d03 critically makes --squash approach for git subtree almost unusable.
Re: [PATCH 30/30] subtree: be stricter about validating flags
Quoted 7 lines · Danny Lin
Thank you for the recent works, Luke.
I'd like to know if you are aware or working on the issue that branches before "git subtree add --squash" are pushed via "git subtree push", which has been reported by me at Tue, 16 Jul 2019 02:30:44 +0800, as I haven't seen an obvious fix about it in the recent patches in a quick glance.
I'm not sure if I was aware of it before, but I'll be sure to keep it in mind when I'm updating my (yet to be submitted) fixes to the 'split' algorithm.
Thanks for the additional test-case!
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
Quoted 4 lines · Luke Shumaker
I promise that
there's more work coming on top of it (we've discovered lots of ways to break the "subtree split" algorithm, and come up with fixes for most of them).
Follow-up question: If in that work I changed the shebang from "#!/bin/sh" to "#!/usr/bin/env bash" and started using Bash arrays, would that be so bad? Would that be land-able?
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
Quoted 10 lines · Luke Shumaker
Quoted 4 lines · Luke Shumaker
I promise that
there's more work coming on top of it (we've discovered lots of ways to break the "subtree split" algorithm, and come up with fixes for most of them).Follow-up question: If in that work I changed the shebang from "#!/bin/sh" to "#!/usr/bin/env bash" and started using Bash arrays, would that be so bad? Would that be land-able?
It's in contrib, so personally I don't care much. But e.g. on OSX that means targeting some ancient (and going away?) version of bash + having *BSDs needing to install bash for this etc.
Bash or not it seems to me like that argument parsing code could be much simplified by simply declaring strings of arguments accepted for each sub-command, and then parsing those arguments + dying on unknown ones.
Quoted 10 lines · Luke Shumaker
Quoted 4 lines · Luke Shumaker
I promise that
there's more work coming on top of it (we've discovered lots of ways to break the "subtree split" algorithm, and come up with fixes for most of them).Follow-up question: If in that work I changed the shebang from "#!/bin/sh" to "#!/usr/bin/env bash" and started using Bash arrays, would that be so bad? Would that be land-able?
I'd rather see "git subtree" tool taken out of my tree and flourish as a standalone project of its own.
Over its long history, from time to time people stepped in only to scratch their own itch and then went away. Without having continued presense of an area expert (or two) who can give consistent guidance to the tool's evolution, I feel that Git project itself failed to give sufficient service to users of "git subtree".
As I won't be that area expert, and we do not seem to be growing such an area expert who can be responsible for the tool in the long haul, it probably is a disservice to its users to keep it in my tree and pretend that it is maintained to the same degree as the rest of Git.
If those who are interested and/or have stake in the "git subtree" tool can unite and take its development in their hands, with their own style, that might be better for the health of the "git subtree" tool in the long run.
Thanks.
v2 cover subtree: clean up, improve UX
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
The diff between v1 and v2 is largely stylistic. The only non-stylistic changes are fixing the tests to use test_must_fail instead of !, and re-thinking the commit about fussing with PATH.
Ostensibly, this patch set is about improving various aspects of git subtree's user interface (and it is!), but it's also mostly about setting the foundation and being "batch 1" of a bunch more changes to subtree that I'm getting queued up. So please forgive the large amount of churn in the leading clean-up commits, I promise that there's more work coming on top of it (we've discovered lots of ways to break the "subtree split" algorithm, and come up with fixes for most of them). In the mean-time, I do think that the UX improvements in this patchset are already worth it themselves.
- The first 11 commits improve subtree's tests, largely around the code-quality of the tests, but a few of the commits do actually improve what's being tested.
- The middle 12 commits improve the code-quality of subtree's implementation.
- The final 7 commits improve various aspects of subtree's user experience, from readability of the debug output, to documentation, to option flag handling.
The very last commit is likely to be a little objectionable--it makes some option flag parsing more strict, so there will probably be worry that the change breaks existing users. However, it's being strict about arg combinations that were always invalid, the difference is that now it reports that to the users and bails. Those users were already broken, they just didn't know it. git subtree should tell them.
Finally, two questions for my continuing work:
1. Would it be all right to amend CI to run the subtree tests? And if so, what would be the best way to do it? For my own testing, I just made the following edit to the main Makefile, but I'm not sure it's the mos appropriate approach:
--- a/Makefile
+++ b/Makefile
@@ -2836,6 +2836,7 @@
test: all
$(MAKE) -C t/ all
+ $(MAKE) -C contrib/subtree/ test
perf: all
$(MAKE) -C t/perf/ allThe first two commits are about getting that to pass. I'd prefer to avoid that type of bitrot in the future.
2. If in that work I changed the shebang from "#!/bin/sh" to "#!/usr/bin/env bash" and started using Bash arrays, would that be so bad? Would that be land-able?
Luke Shumaker (30):
.gitignore: Ignore /git-subtree
subtree: t7900: update for having the default branch name be 'main'
subtree: t7900: use test-lib.sh's test_count
subtree: t7900: use consistent formatting
v2:
- Also normalize on test X instead of [ X ].
- Also normalize on >FILENAME with no spaces.
- Fix a few if statements with if and then on the same line that I missed in v1.
subtree: t7900: comment subtree_test_create_repo
v2:
- Also switch the few uses of vanilla test_create_repo over to subtree_test_create_repo. In v1 this was erroneously included in a different commit.
subtree: t7900: use 'test' for string equality
subtree: t7900: delete some dead code
subtree: t7900: fix 'verify one file change per commit'
v2:
- Fix whitespace.
subtree: t7900: rename last_commit_message to last_commit_subject
subtree: t7900: add a test for the -h flag
subtree: t7900: add porcelain tests for 'pull' and 'push'
v2:
- Don't switch unrelated uses of vanilla test_create_repo over to subtree_test_create_repo; this has been moved to happen in an earlier commit.
- Fix whitespace.
subtree: don't have loose code outside of a function
v2:
- Include rationale in the the commit message.
subtree: more consistent error propagation
subtree: drop support for git < 1.7
v2:
- Include rationale in the the commit message.
subtree: use git merge-base --is-ancestor
subtree: use git-sh-setup's say
subtree: use more explicit variable names for cmdline args
subtree: use "$*" instead of "$@" as appropriate
v2:
- Improve the commit message with quoting and clearer explanation.
subtree: Don't fuss with PATH
v2:
- This commit changed entirely. In v1 it changed how git-subtree adjusts the PATH. In v2, it removes any fussing with the PATH, and in its place adds a pre-flight sanity check that it doesn't need to fuss with the PATH.
subtree: use "^{commit}" instead of "^0"
subtree: parse revs in individual cmd_ functions
subtree: remove duplicate check
subtree: add comments and sanity checks
v2:
- Expand on the the commit message.
- Fix capitalization in one of the comments.
subtree: don't let debug and progress output clash
v2:
- Reword the commit message to be clearer.
- Add comments to the code.
- Flip the if and else cases around, so that the comments read better.
subtree: have $indent actually affect indentation
subtree: give the docs a once-over
v2:
- behaviour -> behavior
subtree: allow --squash to be used with --rejoin
v2:
- In the added tests, use test_must_fail instead of !, as appropriate.
subtree: allow 'split' flags to be passed to 'push'
v2:
- In the added tests, use test_must_fail instead of !, as appropriate.
subtree: push: allow specifying a local rev other than HEAD
subtree: be stricter about validating flags
.gitignore | 1 + contrib/subtree/git-subtree.sh | 638 ++++++++----- contrib/subtree/git-subtree.txt | 184 ++-- contrib/subtree/t/t7900-subtree.sh | 1429 ++++++++++++++++++---------- 4 files changed, 1394 insertions(+), 858 deletions(-)
Signature · 4 lines
2.31.1 Happy hacking, ~ Luke Shumaker
PATCH v2 1/30 .gitignore: Ignore /git-subtree
From: Luke Shumaker <[email protected]>
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.
--- .gitignore | 1 + 1 file changed, 1 insertion(+)
.gitignore +1 -0
@@ -162,6 +162,7 @@ /git-stripspace /git-submodule /git-submodule--helper +/git-subtree /git-svn /git-switch /git-symbolic-ref
Signature · 1 line
2.31.1
PATCH v2 2/30 subtree: t7900: update for having the default branch name be 'main'
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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'.
--- contrib/subtree/t/t7900-subtree.sh | 117 +++++++++++++++-------------- 1 file changed, 59 insertions(+), 58 deletions(-)
contrib/subtree/t/t7900-subtree.sh +59 -58
@@ -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 )
Signature · 1 line
2.31.1
PATCH v2 3/30 subtree: t7900: use test-lib.sh's test_count
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/t/t7900-subtree.sh | 636 ++++++++++++++--------------- 1 file changed, 300 insertions(+), 336 deletions(-)
contrib/subtree/t/t7900-subtree.sh +300 -336
@@ -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 &&
Signature · 1 line
2.31.1
PATCH v2 4/30 subtree: t7900: use consistent formatting
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
The formatting in t7900-subtree.sh isn't even consistent throughout the file. Fix that; make it consistent throughout the file.
---
v2:
- Also normalize on test X instead of [ X ].
- Also normalize on >FILENAME with no spaces.
- Fix a few if statements with if and then on the same line that I missed in v1.
contrib/subtree/t/t7900-subtree.sh | 64 +++++++++++++++--------------- 1 file changed, 31 insertions(+), 33 deletions(-)
contrib/subtree/t/t7900-subtree.sh +31 -33
@@ -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 test "$1" = "$2" + then return 0 else return 1 fi } -undo() -{ +undo () { git reset --hard HEAD~ }
@@ -50,15 +46,17 @@ 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 - if [ -z "$x" ]; then + if test -z "$x" + then continue - elif [ "$x" = "commit:" ]; then - if [ -n "$commit" ]; then + elif test "$x" = "commit:" + then + if test -n "$commit" + then echo "$commit $all" all= fi
@@ -70,7 +68,7 @@ join_commits() echo "$commit $all" } -test_create_commit() ( +test_create_commit () ( repo=$1 && commit=$2 && cd "$repo" &&
@@ -81,8 +79,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 +108,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" &&
@@ -274,8 +272,8 @@ test_expect_success 'split requires option --prefix' ' 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 split > actual 2>&1 && + echo "You must provide the --prefix option." >expected && + test_must_fail git subtree split >actual 2>&1 && test_debug "printf '"expected: "'" && test_debug "cat expected" && test_debug "printf '"actual: "'" &&
@@ -293,8 +291,8 @@ test_expect_success 'split requires path given by option --prefix must exist' ' 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 split --prefix=non-existent-directory > actual 2>&1 && + 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 && test_debug "printf '"expected: "'" && test_debug "cat expected" && test_debug "printf '"actual: "'" &&
@@ -325,7 +323,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 +338,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 +919,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" ) '
Signature · 1 line
2.31.1
Re: [PATCH v2 04/30] subtree: t7900: use consistent formatting
Quoted 13 lines · Luke Shumaker
contrib/subtree/t/t7900-subtree.sh +3
-3@@ -50,15 +46,17 @@ 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 - if [ -z "$x" ]; then + if test -z "$x" + then
contrib/subtree/t/t7900-subtree.sh undo() · line 62
Quoted 10 lines
contrib/subtree/t/t7900-subtree.sh +4
-2continue - elif [ "$x" = "commit:" ]; then - if [ -n "$commit" ]; then + elif test "$x" = "commit:" + then + if test -n "$commit" + then echo "$commit $all" all= fi
Whoops, I should have changed those 1-line while ...; do's, in addition to the 1-line if ...; then's.
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
PATCH v2 5/30 subtree: t7900: comment subtree_test_create_repo
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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-emailing 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 (1) touch up the function to avoid a pointless subshell and (2) update the one test that didn't use it.
---
v2:
- Also switch the few uses of vanilla test_create_repo over to subtree_test_create_repo. In v1 this was erroneously included in a different commit.
contrib/subtree/t/t7900-subtree.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
contrib/subtree/t/t7900-subtree.sh +8 -6
@@ -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 () {
@@ -241,8 +243,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 && (
Signature · 1 line
2.31.1
PATCH v2 6/30 subtree: t7900: use 'test' for string equality
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/t/t7900-subtree.sh | 60 ++++++++++++------------------ 1 file changed, 24 insertions(+), 36 deletions(-)
contrib/subtree/t/t7900-subtree.sh +24 -36
@@ -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 test "$1" = "$2" - then - return 0 - else - return 1 - fi -} - undo () { git reset --hard HEAD~ }
@@ -122,7 +110,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)'\''" ) '
@@ -135,7 +123,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" ) '
@@ -148,7 +136,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" ) '
@@ -161,7 +149,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" ) '
@@ -184,7 +172,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)'\''" ) '
@@ -203,7 +191,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" ) '
@@ -222,7 +210,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" ) '
@@ -238,7 +226,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." ) '
@@ -257,7 +245,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)'\''" ) '
@@ -323,7 +311,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'\''" ) '
@@ -338,7 +326,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'\''" ) '
@@ -361,7 +349,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" ) '
@@ -385,7 +373,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" ) '
@@ -409,13 +397,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" ) ) '
@@ -441,7 +429,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" ) '
@@ -739,7 +727,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)" = "" ) '
@@ -790,7 +778,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.*:")" = "" ) '
@@ -824,7 +812,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)" ) '
@@ -858,7 +846,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)" = "" ) '
@@ -897,10 +885,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 ) ) '
@@ -932,7 +920,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" ) '
@@ -992,7 +980,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 ) '
Signature · 1 line
2.31.1
PATCH v2 7/30 subtree: t7900: delete some dead code
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
--- contrib/subtree/t/t7900-subtree.sh | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
contrib/subtree/t/t7900-subtree.sh +1 -11
@@ -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
@@ -403,7 +393,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" ) ) '
Signature · 1 line
2.31.1
PATCH v2 8/30 subtree: t7900: fix 'verify one file change per commit'
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
---
v2:
- Fix whitespace.
contrib/subtree/t/t7900-subtree.sh | 44 ++++-------------------------- 1 file changed, 6 insertions(+), 38 deletions(-)
contrib/subtree/t/t7900-subtree.sh +6 -38
@@ -22,32 +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 test -z "$x" - then - continue - elif test "$x" = "commit:" - then - if test -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 &&
@@ -868,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 <commit-list ) '
Signature · 1 line
2.31.1
PATCH v2 9/30 subtree: t7900: rename last_commit_message to last_commit_subject
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/t/t7900-subtree.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
contrib/subtree/t/t7900-subtree.sh +13 -13
@@ -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" ) '
Signature · 1 line
2.31.1
PATCH v2 10/30 subtree: t7900: add a test for the -h flag
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
It's a dumb test, but it's surprisingly easy to break.
--- contrib/subtree/t/t7900-subtree.sh | 7 +++++++ 1 file changed, 7 insertions(+)
contrib/subtree/t/t7900-subtree.sh +7 -0
@@ -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' #
Signature · 1 line
2.31.1
PATCH v2 11/30 subtree: t7900: add porcelain tests for 'pull' and 'push'
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
The 'pull' and 'push' subcommands deserve their own sections in the tests. Add some basic tests for them.
---
v2:
- Don't switch unrelated uses of vanilla test_create_repo over to subtree_test_create_repo; this has been moved to happen in an earlier commit.
- Fix whitespace.
contrib/subtree/t/t7900-subtree.sh | 127 +++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+)
contrib/subtree/t/t7900-subtree.sh +127 -0
@@ -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 #
Signature · 1 line
2.31.1
PATCH v2 12/30 subtree: don't have loose code outside of a function
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
Shove all of the loose code inside of a main() function.
This comes down to personal preference more than anything else. A preference that I've developed over years of maintaining large Bash scripts, but still a mere personal preference.
In this specific case, it's also moving the set -- -h, the git rev-parse --parseopt, and the . git-sh-setup to be closer to all the rest of the argument parsing, which is a readability win on its own, IMO.
"Ignore space change" is probably helpful when viewing this diff.
---
v2:
- Include rationale in the the commit message.
contrib/subtree/git-subtree.sh | 245 +++++++++++++++++---------------- 1 file changed, 125 insertions(+), 120 deletions(-)
contrib/subtree/git-subtree.sh +125 -120
@@ -4,10 +4,7 @@ # # Copyright (C) 2009 Avery Pennarun <[email protected]> # -if test $# -eq 0 -then - set -- -h -fi + OPTS_SPEC="\ git subtree add --prefix=<prefix> <commit> git subtree add --prefix=<prefix> <repository> <ref>
@@ -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 "$@"
Signature · 1 line
2.31.1
PATCH v2 13/30 subtree: more consistent error propagation
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
contrib/subtree/git-subtree.sh +14 -14
@@ -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."
Signature · 1 line
2.31.1
PATCH v2 14/30 subtree: drop support for git < 1.7
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
Suport for Git versions older than 1.7.0 (older than February 2010) was nice to have when git-subtree lived out-of-tree. But now that it lives in git.git, it's not necessary to keep around. While it's technically in contrib, with the standard 'git' packages for common systems (including Arch Linux and macOS) including git-subtree, it seems vanishingly likely to me that people are separately installing git-subtree from git.git alongside an older 'git' install (although it also seems vanishingly likely that people are still using >11 year old git installs).
Not that there's much reason to remove it either, it's not much code, and none of my changes depend on a newer git (to my knowledge, anyway; I'm not actually testing against older git). I just figure it's an easy piece of fat to trim, in the journey to making the whole thing easier to hack on.
"Ignore space change" is probably helpful when viewing this diff.
---
v2:
- Include rationale in the the commit message.
contrib/subtree/git-subtree.sh | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
contrib/subtree/git-subtree.sh +4 -15
@@ -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 }
Signature · 1 line
2.31.1
PATCH v2 15/30 subtree: use `git merge-base --is-ancestor`
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
contrib/subtree/git-subtree.sh +1 -15
@@ -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
Signature · 1 line
2.31.1
PATCH v2 16/30 subtree: use git-sh-setup's `say`
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
subtree currently defines its own say implementation, rather than using git-sh-setups's implementation. Change that, don't re-invent the wheel.
--- contrib/subtree/git-subtree.sh | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
contrib/subtree/git-subtree.sh +7 -15
@@ -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 $?
Signature · 1 line
2.31.1
PATCH v2 17/30 subtree: use more explicit variable names for cmdline args
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
Make it painfully obvious when reading the code which variables are direct parsings of command line arguments.
--- contrib/subtree/git-subtree.sh | 132 ++++++++++++++++----------------- 1 file changed, 66 insertions(+), 66 deletions(-)
contrib/subtree/git-subtree.sh +66 -66
@@ -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'."
Signature · 1 line
2.31.1
PATCH v2 18/30 subtree: use "$*" instead of "$@" as appropriate
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
"$*" is for when you want to concatenate the args together, whitespace-separated; and "$@" is for when you want them to be separate strings.
There are several places in subtree that erroneously use $@ when concatenating args together into an error message.
For instance, if the args are argv[1]="dead" and argv[2]="beef", then the line
die "You must provide exactly one revision. Got: '$@'"
surely intends to call 'die' with the argument
argv[1]="You must provide exactly one revision. Got: 'dead beef'"
however, because the line used $@ instead of $*, it will actually call 'die' with the arguments
argv[1]="You must provide exactly one revision. Got: 'dead" argv[2]="beef'"
This isn't a big deal, because 'die' concatenates its arguments together anyway (using "$*"). But that doesn't change the fact that it was a mistake to use $@ instead of $*, even though in the end $@ still ended up doing the right thing.
---
v2:
- Improve the commit message with quoting and clearer explanation.
contrib/subtree/git-subtree.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
contrib/subtree/git-subtree.sh +3 -3
@@ -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 }
Signature · 1 line
2.31.1
PATCH v2 19/30 subtree: Don't fuss with PATH
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
Scripts needing to fuss with with adding $(git --exec-prefix) PATH before loading git-sh-setup is a thing of the past. As far as I can tell, it's been a thing of the past since since Git v1.2.0 (2006-02-12), or more specifically, since 77cb17e940 (Exec git programs without using PATH, 2006-01-10). However, it stuck around in contrib scripts and in third-party scripts for long enough that it wasn't unusual to see.
Originally git subtree didn't fuss with PATH, but when people (including the original subtree author) had problems, because it was a common thing to see, it seemed that having subtree fuss with PATH was a reasonable solution.
Here is an abridged history of fussing with PATH in subtree:
2987e6add3 (Add explicit path of git installation by 'git --exec-path', Gianluca Pacchiella, 2009-08-20)
As pointed out by documentation, the correct use of 'git-sh-setup' is
using $(git --exec-path) to avoid problems with not standard
installations.
-. git-sh-setup
+. $(git --exec-path)/git-sh-setup 33aaa697a2 (Improve patch to use git --exec-path: add to PATH instead, Avery Pennarun, 2009-08-26)
If you (like me) are using a modified git straight out of its source directory (ie. without installing), then --exec-path isn't actually correct. Add it to the PATH instead, so if it is correct, it'll work, but if it's not, we fall back to the previous behaviour.
-. $(git --exec-path)/git-sh-setup
+PATH=$(git --exec-path):$PATH
+. git-sh-setup
9c632ea29c ((Hopefully) fix PATH setting for msysgit, Avery Pennarun, 2010-06-24)
Reported by Evan Shaw. The problem is that $(git --exec-path) includes a 'git' binary which is incompatible with the one in /usr/bin; if you run it, it gives you an error about libiconv2.dll.
+OPATH=$PATH
PATH=$(git --exec-path):$PATH
. git-sh-setup
+PATH=$OPATH # apparently needed for some versions of msysgit
df2302d774 (Another fix for PATH and msysgit, Avery Pennarun, 2010-06-24)
Evan Shaw tells me the previous fix didn't work. Let's use this one instead, which he says does work.
This fix is kind of wrong because it will run the "correct" git-sh-setup *after* the one in /usr/bin, if there is one, which could be weird if you have multiple versions of git installed. But it works on my Linux and his msysgit, so it's obviously better than what we had before.
-OPATH=$PATH
-PATH=$(git --exec-path):$PATH
+PATH=$PATH:$(git --exec-path)
. git-sh-setup
-PATH=$OPATH # apparently needed for some versions of msysgit
First of all, I disagree with Gianluca's reading of the documentation:
- I haven't gone back to read what the documentation said in 2009, but in my reading of the 2021 documentation is that it includes "$(git --exec-path)/" in the synopsis for illustrative purposes, not to say it's the proper way.
- After being executed by git, the git exec path should be the very first entry in PATH, so it shouldn't matter.
- None of the scripts that are part of git do it that way.
But secondly, the root reason for fussing with PATH seems to be that Avery didn't know that he needs to set GIT_EXEC_PATH if he's going to use git from the source directory without installing.
And finally, Evan's issue is clearly just a bug in msysgit. I assume that msysgit has since fixed the issue, and also msysgit has been deprecated for 6 years now, so let's drop the workaround for it.
So, remove the line fussing with PATH. However, since subtree *is* in 'contrib/' and it might get installed in funny ways by users after-the-fact, add a sanity check to the top of the script, checking that it is installed correctly.
--- contrib/subtree/git-subtree.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
contrib/subtree/git-subtree.sh +16 -2
@@ -5,6 +5,22 @@ # Copyright (C) 2009 Avery Pennarun <[email protected]> # +if test -z "$GIT_EXEC_PATH" || test "${PATH#"${GIT_EXEC_PATH}:"}" = "$PATH" || ! test -f "$GIT_EXEC_PATH/git-sh-setup" +then + echo >&2 'It looks like either your git installation or your' + echo >&2 'git-subtree installation is broken.' + echo >&2 + echo >&2 "Tips:" + echo >&2 " - If \`git --exec-path\` does not print the correct path to" + echo >&2 " your git install directory, then set the GIT_EXEC_PATH" + echo >&2 " environment variable to the correct directory." + echo >&2 " - Make sure that your \`${0##*/}\` file is either in your" + echo >&2 " PATH or in your git exec path (\`$(git --exec-path)\`)." + echo >&2 " - You should run git-subtree as \`git ${0##*/git-}\`," + echo >&2 " not as \`${0##*/}\`." >&2 + exit 126 +fi + OPTS_SPEC="\ git subtree add --prefix=<prefix> <commit> git subtree add --prefix=<prefix> <repository> <ref>
@@ -28,8 +44,6 @@ rejoin merge the new branch back into HEAD squash merge subtree changes as a single commit " -PATH=$PATH:$(git --exec-path) - arg_debug= arg_command= arg_prefix=
Signature · 1 line
2.31.1
Re: [PATCH v2 19/30] subtree: Don't fuss with PATH
Quoted 1 line · Luke Shumaker
Subject: [PATCH v2 19/30] subtree: Don't fuss with PATH
Whoops, I shouldn't have capitalized "Don't".
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
PATCH v2 20/30 subtree: use "^{commit}" instead of "^0"
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
They are synonyms. Both are used in the file. ^{commit} is clearer, so "standardize" on that.
--- contrib/subtree/git-subtree.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
contrib/subtree/git-subtree.sh +2 -2
@@ -316,7 +316,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)
@@ -363,7 +363,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)
Signature · 1 line
2.31.1
PATCH v2 21/30 subtree: parse revs in individual cmd_ functions
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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'.
--- contrib/subtree/git-subtree.sh | 62 +++++++++++++--------------------- 1 file changed, 24 insertions(+), 38 deletions(-)
contrib/subtree/git-subtree.sh +24 -38
@@ -76,13 +76,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
@@ -164,11 +157,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'"
@@ -193,22 +183,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
@@ -714,14 +690,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 $?
@@ -752,6 +727,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 $?
@@ -768,12 +754,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
@@ -820,8 +806,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"
@@ -861,9 +849,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 () {
Signature · 1 line
2.31.1
PATCH v2 22/30 subtree: remove duplicate check
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 4 ---- 1 file changed, 4 deletions(-)
contrib/subtree/git-subtree.sh +0 -4
@@ -655,10 +655,6 @@ process_split_commit () { } cmd_add () { - if test -e "$dir" - then - die "'$dir' already exists. Cannot add." - fi ensure_clean
Signature · 1 line
2.31.1
PATCH v2 23/30 subtree: add comments and sanity checks
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
For each function in subtree, add a usage comment saying what the arguments are, and add an assert checking the number of arguments.
In figuring out each thing's arguments in order to write those comments and assertions, it turns out that find_existing_splits is written as if it takes multiple 'revs', but it is in fact only ever passed a single 'rev':
unrevs="$(find_existing_splits "$dir" "$rev")" || exit $?
So go ahead and codify that by documenting and asserting that it takes exactly two arguments, one dir and one rev.
---
v2:
- Expand on the the commit message.
- Fix capitalization in one of the comments.
contrib/subtree/git-subtree.sh | 64 ++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-)
contrib/subtree/git-subtree.sh +61 -3
@@ -55,6 +55,7 @@ arg_split_annotate= arg_addmerge_squash= arg_addmerge_message= +# Usage: debug [MSG...] debug () { if test -n "$arg_debug" then
@@ -62,6 +63,7 @@ debug () { fi } +# Usage: progress [MSG...] progress () { if test -z "$GIT_QUIET" then
@@ -69,6 +71,7 @@ progress () { fi } +# Usage: assert CMD... assert () { if ! "$@" then
@@ -192,7 +195,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"
@@ -203,6 +208,7 @@ cache_setup () { debug "Using cachedir: $cachedir" >&2 } +# Usage: cache_get [REVS...] cache_get () { for oldrev in "$@" do
@@ -214,6 +220,7 @@ cache_get () { done } +# Usage: cache_miss [REVS...] cache_miss () { for oldrev in "$@" do
@@ -224,7 +231,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
@@ -237,11 +246,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" &&
@@ -253,7 +266,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
@@ -262,17 +277,22 @@ rev_exists () { fi } -# if a commit doesn't have a parent, this might not work. But we only want +# 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=
@@ -316,10 +336,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/*\$"
@@ -328,7 +350,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
@@ -365,7 +387,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}"
@@ -391,7 +415,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"
@@ -410,7 +436,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"
@@ -419,7 +447,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"
@@ -438,7 +468,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"
@@ -460,12 +492,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" |
@@ -479,7 +515,9 @@ subtree_for_commit () { done || exit $? } +# Usage: tree_changed TREE [PARENTS...] tree_changed () { + assert test $# -gt 0 tree=$1 shift if test $# -ne 1
@@ -496,7 +534,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"
@@ -511,7 +551,9 @@ new_squash_commit () { fi } +# Usage: copy_or_skip REV TREE NEWPARENTS copy_or_skip () { + assert test $# = 3 rev="$1" tree="$2" newparents="$3"
@@ -586,7 +628,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."
@@ -597,12 +641,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
@@ -654,6 +702,8 @@ process_split_commit () { cache_set latest_old "$rev" } +# Usage: cmd_add REV +# Or: cmd_add REPOSITORY REF cmd_add () { ensure_clean
@@ -681,7 +731,9 @@ cmd_add () { fi } +# Usage: cmd_add_repository REPOSITORY REFSPEC cmd_add_repository () { + assert test $# = 2 echo "git fetch" "$@" repository=$1 refspec=$2
@@ -689,9 +741,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'..."
@@ -722,6 +776,7 @@ cmd_add_commit () { say >&2 "Added dir '$dir'" } +# Usage: cmd_split [REV] cmd_split () { if test $# -eq 0 then
@@ -801,6 +856,7 @@ cmd_split () { exit 0 } +# Usage: cmd_merge REV cmd_merge () { test $# -eq 1 || die "You must provide exactly one revision. Got: '$*'"
@@ -837,6 +893,7 @@ cmd_merge () { fi } +# Usage: cmd_pull REPOSITORY REMOTEREF cmd_pull () { if test $# -ne 2 then
@@ -848,6 +905,7 @@ cmd_pull () { cmd_merge FETCH_HEAD } +# Usage: cmd_push REPOSITORY REMOTEREF cmd_push () { if test $# -ne 2 then
Signature · 1 line
2.31.1
PATCH v2 24/30 subtree: don't let debug and progress output clash
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
Currently, debug output (triggered by passing '-d') and progress output stomp on each other. The debug output is just streamed as lines to stderr, and the progress output is sent to stderr as '%s\r'. When writing to a file, it is awkward to read and 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.
---
v2:
- Reword the commit message to be clearer.
- Add comments to the code.
- Flip the if and else cases around, so that the comments read better.
contrib/subtree/git-subtree.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
contrib/subtree/git-subtree.sh +21 -1
@@ -67,7 +67,27 @@ debug () { progress () { if test -z "$GIT_QUIET" then - printf "%s\r" "$*" >&2 + if test -z "$arg_debug" + then + # Debug mode is off. + # + # Print one progress line that we keep updating (use + # "\r" to return to the beginning of the line, rather + # than "\n" to start a new line). This only really + # works when stderr is a terminal. + printf "%s\r" "$*" >&2 + else + # Debug mode is on. The `debug` function is regularly + # printing to stderr. + # + # Don't do the one-line-with-"\r" thing, because on a + # terminal the debug output would overwrite and hide the + # progress output. Add a "progress:" prefix to make the + # progress output and the debug output easy to + # distinguish. This ensures maximum readability whether + # stderr is a terminal or a file. + printf "progress: %s\n" "$*" >&2 + fi fi }
Signature · 1 line
2.31.1
PATCH v2 25/30 subtree: have $indent actually affect indentation
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 42 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-)
contrib/subtree/git-subtree.sh +24 -18
@@ -55,11 +55,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 }
@@ -251,17 +253,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 }
@@ -314,6 +316,8 @@ try_remove_previous () { find_latest_squash () { assert test $# = 1 debug "Looking for latest squash ($dir)..." + local indent=$(($indent + 1)) + dir="$1" sq= main=
@@ -360,6 +364,8 @@ find_latest_squash () { find_existing_splits () { assert test $# = 2 debug "Looking for prior splits..." + local indent=$(($indent + 1)) + dir="$1" rev="$2" main=
@@ -385,7 +391,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
@@ -668,12 +674,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
@@ -688,20 +693,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?
@@ -716,7 +722,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"
@@ -820,7 +826,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
@@ -838,7 +844,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 $?
Signature · 1 line
2.31.1
PATCH v2 26/30 subtree: give the docs a once-over
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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 <variables> used to give command arguments, give slightly longer, descriptive names. Like <local-commit> instead of just <commit>.
- 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 ([<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.
- style: Since that line is getting edited anyway, switch "behaviour" to American "behavior".
---
v2:
- behaviour -> behavior
contrib/subtree/git-subtree.sh | 4 +- contrib/subtree/git-subtree.txt | 162 +++++++++++++++----------------- 2 files changed, 80 insertions(+), 86 deletions(-)
contrib/subtree/git-subtree.sh +2 -2
@@ -25,9 +25,9 @@ OPTS_SPEC="\ git subtree add --prefix=<prefix> <commit> git subtree add --prefix=<prefix> <repository> <ref> git subtree merge --prefix=<prefix> <commit> +git subtree split --prefix=<prefix> [<commit>] git subtree pull --prefix=<prefix> <repository> <ref> git subtree push --prefix=<prefix> <repository> <ref> -git subtree split --prefix=<prefix> <commit> -- h,help show the help q quiet
@@ -40,7 +40,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 "
contrib/subtree/git-subtree.txt +78 -84
279 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v2 27/30 subtree: allow --squash to be used with --rejoin
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
---
v2:
- In the added tests, use test_must_fail instead of !, as appropriate.
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(-)
contrib/subtree/git-subtree.sh +26 -7
@@ -33,15 +33,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 " arg_debug=
@@ -453,6 +453,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
@@ -775,7 +782,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 $?
@@ -815,6 +827,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 $?
@@ -857,10 +874,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
contrib/subtree/git-subtree.txt +11 -16
@@ -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 <repository> <remote-ref>:: Exactly like 'merge', but parallels 'git pull' in that
@@ -124,8 +121,8 @@ push <repository> <remote-ref>:: <remote-ref>. 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>:: ---message=<message>:: - This option is only valid for 'add', 'merge', 'pull', and 'split --rejoin'. - Specify <message> 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>:: +--message=<message>:: + Specify <message> 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
contrib/subtree/t/t7900-subtree.sh +35 -0
@@ -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) && + + test_must_fail git merge-base --is-ancestor $SUB HEAD && + test_must_fail 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" &&
Signature · 1 line
2.31.1
Re: [PATCH v2 27/30] subtree: allow --squash to be used with --rejoin
Quoted 7 lines · Luke Shumaker
contrib/subtree/git-subtree.sh +0
-3@@ -857,10 +874,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")" \
contrib/subtree/git-subtree.sh cmd_split () { · line 885
Quoted 10 lines
contrib/subtree/git-subtree.sh +6
-1- "$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
Whoops, that if ...; then should put the then on its own line.
Signature · 2 lines
Happy hacking, ~ Luke Shumaker
PATCH v2 28/30 subtree: allow 'split' flags to be passed to 'push'
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
'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.
---
v2:
- In the added tests, use test_must_fail instead of !, as appropriate.
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(-)
contrib/subtree/git-subtree.sh +3 -3
@@ -33,13 +33,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 "
@@ -962,7 +962,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'."
contrib/subtree/git-subtree.txt +8 -7
@@ -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=<message>:: Specify <message> 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=<annotation>:: When generating synthetic history, add <annotation> as a prefix to each
contrib/subtree/t/t7900-subtree.sh +212 -2
226 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v2 29/30 subtree: push: allow specifying a local rev other than HEAD
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
'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.
--- 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(-)
contrib/subtree/git-subtree.sh +17 -7
@@ -27,7 +27,7 @@ git subtree add --prefix=<prefix> <repository> <ref> git subtree merge --prefix=<prefix> <commit> git subtree split --prefix=<prefix> [<commit>] git subtree pull --prefix=<prefix> <repository> <ref> -git subtree push --prefix=<prefix> <repository> <ref> +git subtree push --prefix=<prefix> <repository> <refspec> -- h,help show the help q quiet
@@ -950,20 +950,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 <repository> <ref>" + die "You must provide <repository> <refspec>" 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
contrib/subtree/git-subtree.txt +8 -6
@@ -16,7 +16,7 @@ SYNOPSIS [verse] 'git subtree' [<options>] -P <prefix> pull <repository> <remote-ref> -'git subtree' [<options>] -P <prefix> push <repository> <remote-ref> +'git subtree' [<options>] -P <prefix> push <repository> <refspec> DESCRIPTION -----------
@@ -115,11 +115,13 @@ pull <repository> <remote-ref>:: it fetches the given ref from the specified remote repository. -push <repository> <remote-ref>:: - Does a 'split' using the <prefix> subtree of HEAD and then - does a 'git push' to push the result to the <repository> and - <remote-ref>. This can be used to push your subtree to - different branches of the remote repository. +push <repository> [+][<local-commit>:]<remote-ref>:: + Does a 'split' using the <prefix> subtree of <local-commit> + and then does a 'git push' to push the result to the + <repository> and <remote-ref>. This can be used to push your + subtree to different branches of the remote repository. Just + as with 'split', if no <local-commit> is given, then HEAD is + used. The optional leading '+' is ignored. OPTIONS FOR ALL COMMANDS ------------------------
contrib/subtree/t/t7900-subtree.sh +22 -0
@@ -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 #
Signature · 1 line
2.31.1
PATCH v2 30/30 subtree: be stricter about validating flags
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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.
--- contrib/subtree/git-subtree.sh | 89 ++++++++++++++++------- contrib/subtree/t/t7900-subtree.sh | 111 +++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 25 deletions(-)
contrib/subtree/git-subtree.sh +64 -25
@@ -44,17 +44,6 @@ squash merge subtree changes as a single commit m,message= use the given message as the commit message for the merge commit " -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...]
@@ -106,10 +95,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"
@@ -123,13 +163,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 ;;
@@ -138,6 +181,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 ;;
@@ -145,28 +189,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= ;; --)
@@ -177,19 +227,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."
contrib/subtree/t/t7900-subtree.sh +111 -0
147 lines not on this page · raw message
Signature · 1 line
2.31.1
v3 cover subtree: clean up, improve UX
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
The diff between v1 and v2 is largely stylistic. The only non-stylistic changes are fixing the tests to use test_must_fail instead of !, and re-thinking the commit about fussing with PATH.
The diff between v2 and v3 contains a few stylistic changes, but the meat of it is that it fixes a bug with --squash and --rejoin being used together, and that it fixes a mistake in the man page.
Ostensibly, this patch set is about improving various aspects of git subtree's user interface (and it is!), but it's also mostly about setting the foundation and being "batch 1" of a bunch more changes to subtree that I'm getting queued up. So please forgive the large amount of churn in the leading clean-up commits, I promise that there's more work coming on top of it (we've discovered lots of ways to break the "subtree split" algorithm, and come up with fixes for most of them). In the mean-time, I do think that the UX improvements in this patchset are already worth it themselves.
- The first 11 commits improve subtree's tests, largely around the code-quality of the tests, but a few of the commits do actually improve what's being tested.
- The middle 12 commits improve the code-quality of subtree's implementation.
- The final 7 commits improve various aspects of subtree's user experience, from readability of the debug output, to documentation, to option flag handling.
The very last commit is likely to be a little objectionable--it makes some option flag parsing more strict, so there will probably be worry that the change breaks existing users. However, it's being strict about arg combinations that were always invalid, the difference is that now it reports that to the users and bails. Those users were already broken, they just didn't know it. git subtree should tell them.
Luke Shumaker (30):
.gitignore: Ignore /git-subtree
subtree: t7900: update for having the default branch name be 'main'
subtree: t7900: use test-lib.sh's test_count
subtree: t7900: use consistent formatting
v2:
- Also normalize on test X instead of [ X ].
- Also normalize on >FILENAME with no spaces.
- Fix a few if statements with if and then on the same line that I missed in v1.
v3:
- Consistently put the do of a loop on its own line.
subtree: t7900: comment subtree_test_create_repo
v2:
- Also switch the few uses of vanilla test_create_repo over to subtree_test_create_repo. In v1 this was erroneously included in a different commit.
subtree: t7900: use 'test' for string equality
subtree: t7900: delete some dead code
subtree: t7900: fix 'verify one file change per commit'
v2:
- Fix whitespace.
subtree: t7900: rename last_commit_message to last_commit_subject
subtree: t7900: add a test for the -h flag
subtree: t7900: add porcelain tests for 'pull' and 'push'
v2:
- Don't switch unrelated uses of vanilla test_create_repo over to subtree_test_create_repo; this has been moved to happen in an earlier commit.
- Fix whitespace.
subtree: don't have loose code outside of a function
v2:
- Include rationale in the the commit message.
subtree: more consistent error propagation
subtree: drop support for git < 1.7
v2:
- Include rationale in the the commit message.
subtree: use git merge-base --is-ancestor
subtree: use git-sh-setup's say
subtree: use more explicit variable names for cmdline args
subtree: use "$*" instead of "$@" as appropriate
v2:
- Improve the commit message with quoting and clearer explanation.
subtree: don't fuss with PATH
v2:
- This commit changed entirely. In v1 it changed how git-subtree adjusts the PATH. In v2, it removes any fussing with the PATH, and in its place adds a pre-flight sanity check that it doesn't need to fuss with the PATH.
v3:
- Fix capitalization in the commit message.
subtree: use "^{commit}" instead of "^0"
subtree: parse revs in individual cmd_ functions
subtree: remove duplicate check
subtree: add comments and sanity checks
v2:
- Expand on the the commit message.
- Fix capitalization in one of the comments.
subtree: don't let debug and progress output clash
v2:
- Reword the commit message to be clearer.
- Add comments to the code.
- Flip the if and else cases around, so that the comments read better.
subtree: have $indent actually affect indentation
subtree: give the docs a once-over
v2:
- behaviour -> behavior
v3:
- Trim trailing whitespace.
- Fix the man page saying "--ignore-join" instead of "--ignore-joins".
subtree: allow --squash to be used with --rejoin
v2:
- In the added tests, use test_must_fail instead of !, as appropriate.
v3:
- Style: Put the then of an if/then on its own line.
- Fix a bug (and add a test) where the resulting commits confuse a subsequent git subtree merge --squash.
subtree: allow 'split' flags to be passed to 'push'
v2:
- In the added tests, use test_must_fail instead of !, as appropriate.
subtree: push: allow specifying a local rev other than HEAD
subtree: be stricter about validating flags
.gitignore | 1 + contrib/subtree/git-subtree.sh | 642 +++++++----- contrib/subtree/git-subtree.txt | 192 ++-- contrib/subtree/t/t7900-subtree.sh | 1450 ++++++++++++++++++---------- contrib/subtree/todo | 6 +- 5 files changed, 1425 insertions(+), 866 deletions(-)
Signature · 4 lines
2.31.1 Happy hacking, ~ Luke Shumaker
PATCH v3 1/30 .gitignore: Ignore /git-subtree
From: Luke Shumaker <[email protected]>
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.
--- .gitignore | 1 + 1 file changed, 1 insertion(+)
.gitignore +1 -0
@@ -162,6 +162,7 @@ /git-stripspace /git-submodule /git-submodule--helper +/git-subtree /git-svn /git-switch /git-symbolic-ref
Signature · 1 line
2.31.1
PATCH v3 2/30 subtree: t7900: update for having the default branch name be 'main'
In reply to Luke ShumakerFrom: Luke Shumaker <[email protected]>
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'.
--- contrib/subtree/t/t7900-subtree.sh | 117 +++++++++++++++-------------- 1 file changed, 59 insertions(+), 58 deletions(-)
contrib/subtree/t/t7900-subtree.sh +59 -58
@@ -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 )
Signature · 1 line
2.31.1
Re: [PATCH v3 02/30] subtree: t7900: update for having the default branch name be 'main'
Quoted 8 lines · Luke Shumaker
From: Luke Shumaker <[email protected]>
Most of the tests had been converted to support
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main, butcontrib/subtree/t/hadn't.Convert it. Most of the mentions of 'master' can just be replaced with 'HEAD'.
Looks good to me. FWIW (without having looked carefully) I'd have probably just set up a "sub-proj" remote and done a "git fetch" after configuring a refspec during the setup, but just s/master/HEAD/ is the smaller change to just fix the "bug".
contrib/subtree/t/t7900-subtree.sh test_expect_success 'push split to subproj' ' · line 1000
Quoted 9 lines
[...]
contrib/subtree/t/t7900-subtree.sh +1
-0@@ -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" &&
This though needlessly peeks into the raw refstore. Use branch=$(git symbolic-ref --short HEAD) instead. See e.g. my
https://lore.kernel.org/git/[email protected]/
Re: [PATCH v3 02/30] subtree: t7900: update for having the default branch name be 'main'
Quoted 4 lines · Ævar Arnfjörð Bjarmason
Quoted 4 lines
contrib/subtree/t/t7900-subtree.sh +0
-0@@ -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" &&
Quoted 8 lines
contrib/subtree/t/t7900-subtree.sh test_expect_success 'push split to subproj' ' · line 1000
Quoted 4 lines
contrib/subtree/t/t7900-subtree.sh +1
-0+ defaultBranch=$(sed "s,ref: refs/heads/,," "$subtree_test_count/.git/HEAD") && test_create_commit "$subtree_test_count" folder_subtree/a && ( cd "$subtree_test_count" &&This though needlessly peeks into the raw refstore. Use branch=$(git symbolic-ref --short HEAD) instead. See e.g. my
https://lore.kernel.org/git/[email protected]/
I was about to say that doesn't work with a freshly initialized repo without a commit yet, but I'm thinking of git rev-parse --abbrev-ref HEAD.
I'll change it if I have to re-roll for another reason.
Signature · 2 lines
Happy hacking, ~ Luke Shumaker