Merge branch 'sg/t3701-tighten-trace' into maint
[gitweb.git] / t / t5318-commit-graph.sh
index 4f17d7701e456bbb0992efdba2861e1dac8f7c23..2799969f3e2a15fc636ed042c96d8a846e01ebe8 100755 (executable)
@@ -134,7 +134,7 @@ test_expect_success 'Add one more commit' '
        git branch commits/8 &&
        ls $objdir/pack | grep idx >existing-idx &&
        git repack &&
-       ls $objdir/pack| grep idx | grep -v --file=existing-idx >new-idx
+       ls $objdir/pack| grep idx | grep -v -existing-idx >new-idx
 '
 
 # Current graph structure:
@@ -254,9 +254,69 @@ test_expect_success 'check that gc computes commit-graph' '
        git config gc.writeCommitGraph true &&
        git gc &&
        cp $objdir/info/commit-graph commit-graph-after-gc &&
-       ! test_cmp commit-graph-before-gc commit-graph-after-gc &&
+       ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
        git commit-graph write --reachable &&
-       test_cmp commit-graph-after-gc $objdir/info/commit-graph
+       test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
+'
+
+test_expect_success 'replace-objects invalidates commit-graph' '
+       cd "$TRASH_DIRECTORY" &&
+       test_when_finished rm -rf replace &&
+       git clone full replace &&
+       (
+               cd replace &&
+               git commit-graph write --reachable &&
+               test_path_is_file .git/objects/info/commit-graph &&
+               git replace HEAD~1 HEAD~2 &&
+               git -c core.commitGraph=false log >expect &&
+               git -c core.commitGraph=true log >actual &&
+               test_cmp expect actual &&
+               git commit-graph write --reachable &&
+               git -c core.commitGraph=false --no-replace-objects log >expect &&
+               git -c core.commitGraph=true --no-replace-objects log >actual &&
+               test_cmp expect actual &&
+               rm -rf .git/objects/info/commit-graph &&
+               git commit-graph write --reachable &&
+               test_path_is_file .git/objects/info/commit-graph
+       )
+'
+
+test_expect_success 'commit grafts invalidate commit-graph' '
+       cd "$TRASH_DIRECTORY" &&
+       test_when_finished rm -rf graft &&
+       git clone full graft &&
+       (
+               cd graft &&
+               git commit-graph write --reachable &&
+               test_path_is_file .git/objects/info/commit-graph &&
+               H1=$(git rev-parse --verify HEAD~1) &&
+               H3=$(git rev-parse --verify HEAD~3) &&
+               echo "$H1 $H3" >.git/info/grafts &&
+               git -c core.commitGraph=false log >expect &&
+               git -c core.commitGraph=true log >actual &&
+               test_cmp expect actual &&
+               git commit-graph write --reachable &&
+               git -c core.commitGraph=false --no-replace-objects log >expect &&
+               git -c core.commitGraph=true --no-replace-objects log >actual &&
+               test_cmp expect actual &&
+               rm -rf .git/objects/info/commit-graph &&
+               git commit-graph write --reachable &&
+               test_path_is_missing .git/objects/info/commit-graph
+       )
+'
+
+test_expect_success 'replace-objects invalidates commit-graph' '
+       cd "$TRASH_DIRECTORY" &&
+       test_when_finished rm -rf shallow &&
+       git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
+       (
+               cd shallow &&
+               git commit-graph write --reachable &&
+               test_path_is_missing .git/objects/info/commit-graph &&
+               git fetch origin --unshallow &&
+               git commit-graph write --reachable &&
+               test_path_is_file .git/objects/info/commit-graph
+       )
 '
 
 # the verify tests below expect the commit-graph to contain
@@ -444,25 +504,27 @@ test_expect_success 'setup non-the_repository tests' '
 test_expect_success 'parse_commit_in_graph works for non-the_repository' '
        test-tool repository parse_commit_in_graph \
                repo/.git repo "$(git -C repo rev-parse two)" >actual &&
-       echo $(git -C repo log --pretty="%ct" -1) \
-               $(git -C repo rev-parse one) >expect &&
+       {
+               git -C repo log --pretty=format:"%ct " -1 &&
+               git -C repo rev-parse one
+       } >expect &&
        test_cmp expect actual &&
 
        test-tool repository parse_commit_in_graph \
                repo/.git repo "$(git -C repo rev-parse one)" >actual &&
-       echo $(git -C repo log --pretty="%ct" -1 one) >expect &&
+       git -C repo log --pretty="%ct" -1 one >expect &&
        test_cmp expect actual
 '
 
 test_expect_success 'get_commit_tree_in_graph works for non-the_repository' '
        test-tool repository get_commit_tree_in_graph \
                repo/.git repo "$(git -C repo rev-parse two)" >actual &&
-       echo $(git -C repo rev-parse two^{tree}) >expect &&
+       git -C repo rev-parse two^{tree} >expect &&
        test_cmp expect actual &&
 
        test-tool repository get_commit_tree_in_graph \
                repo/.git repo "$(git -C repo rev-parse one)" >actual &&
-       echo $(git -C repo rev-parse one^{tree}) >expect &&
+       git -C repo rev-parse one^{tree} >expect &&
        test_cmp expect actual
 '