Merge branch 'pm/build-persistent-https-with-recent-go' into maint
[gitweb.git] / contrib / subtree / t / t7900-subtree.sh
index 2683d7d479083994eb5032b391b203b3598fc2d0..9751cfe9e63d6510dd7af0b6be5f7028df49bf88 100755 (executable)
@@ -16,16 +16,16 @@ export TEST_DIRECTORY
 
 subtree_test_create_repo()
 {
-       test_create_repo "$1"
+       test_create_repo "$1" &&
        (
-               cd $1
+               cd "$1" &&
                git config log.date relative
        )
 }
 
 create()
 {
-       echo "$1" >"$1"
+       echo "$1" >"$1" &&
        git add "$1"
 }
 
@@ -71,12 +71,12 @@ join_commits()
 }
 
 test_create_commit() (
-       repo=$1
-       commit=$2
-       cd "$repo"
-       mkdir -p $(dirname "$commit") \
+       repo=$1 &&
+       commit=$2 &&
+       cd "$repo" &&
+       mkdir -p "$(dirname "$commit")" \
        || error "Could not create directory for commit"
-       echo "$commit" >"$commit"
+       echo "$commit" >"$commit" &&
        git add "$commit" || error "Could not add commit"
        git commit -m "$commit" || error "Could not commit"
 )
@@ -257,6 +257,26 @@ 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" &&
+       test_create_commit "$test_count" main1 &&
+       test_create_commit "$test_count/subproj" sub1 &&
+       (
+               cd "$test_count" &&
+               git fetch ./subproj master &&
+               git subtree add --prefix=subdir/ FETCH_HEAD
+       ) &&
+       test_create_commit "$test_count/subproj" sub2 &&
+       (
+               cd "$test_count" &&
+               git fetch ./subproj master &&
+               git subtree merge --prefix=subdir/ FETCH_HEAD &&
+               check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
+       )
+'
+
 #
 # Tests for 'git subtree split'
 #
@@ -326,6 +346,22 @@ 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 &&
+       (
+               cd "$subtree_test_count" &&
+               mkdir "sub dir" &&
+               echo file >"sub dir"/file &&
+               git add "sub dir/file" &&
+               git commit -m"sub dir file" &&
+               split_hash=$(git subtree split --prefix="sub dir" --rejoin) &&
+               git subtree split --prefix="sub dir" --rejoin &&
+               check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
+       )
+ '
+
 next_test
 test_expect_success 'split sub dir/ with --rejoin and --message' '
        subtree_test_create_repo "$subtree_test_count" &&
@@ -994,4 +1030,64 @@ test_expect_success 'push split to subproj' '
        )
 '
 
+#
+# This test covers 2 cases in subtree split copy_or_skip code
+# 1) Merges where one parent is a superset of the changes of the other
+#    parent regarding changes to the subtree, in this case the merge
+#    commit should be copied
+# 2) Merges where only one parent operate on the subtree, and the merge
+#    commit should be skipped
+#
+# (1) is checked by ensuring subtree_tip is a descendent of subtree_branch
+# (2) should have a check added (not_a_subtree_change shouldn't be present
+#     on the produced subtree)
+#
+# Other related cases which are not tested (or currently handled correctly)
+# - Case (1) where there are more than 2 parents, it will sometimes correctly copy
+#   the merge, and sometimes not
+# - Merge commit where both parents have same tree as the merge, currently
+#   will always be skipped, even if they reached that state via different
+#   set of commits.
+#
+
+next_test
+test_expect_success 'subtree descendant check' '
+       subtree_test_create_repo "$subtree_test_count" &&
+       test_create_commit "$subtree_test_count" folder_subtree/a &&
+       (
+               cd "$subtree_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) &&
+       (
+               cd "$subtree_test_count" &&
+               git checkout branch
+       ) &&
+       test_create_commit "$subtree_test_count" commit_on_branch &&
+       (
+               cd "$subtree_test_count" &&
+               git cherry-pick $cherry &&
+               git checkout master &&
+               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 &&
+       (
+               cd "$subtree_test_count" &&
+               git checkout no_subtree_work_branch
+       ) &&
+       test_create_commit "$subtree_test_count" not_a_subtree_change &&
+       (
+               cd "$subtree_test_count" &&
+               git checkout master &&
+               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_branch branch &&
+               check_equal $(git rev-list --count subtree_tip..subtree_branch) 0
+       )
+'
+
 test_done