]> git.ipfire.org Git - thirdparty/git.git/blob - t/lib-commit-graph.sh
The third batch
[thirdparty/git.git] / t / lib-commit-graph.sh
1 #!/bin/sh
2
3 # Helper functions for testing commit-graphs.
4
5 # Initialize OID cache with oid_version
6 test_oid_cache <<-EOF
7 oid_version sha1:1
8 oid_version sha256:2
9 EOF
10
11 graph_git_two_modes() {
12 git -c core.commitGraph=true $1 >output &&
13 git -c core.commitGraph=false $1 >expect &&
14 test_cmp expect output
15 }
16
17 # graph_git_behavior <name> <directory> <branch> <compare>
18 #
19 # Ensures that a handful of traversal operations produce the same
20 # results with and without the commit-graph in use.
21 #
22 # NOTE: it is a bug to call this function with <directory> containing
23 # any characters in $IFS.
24 graph_git_behavior() {
25 MSG=$1
26 DIR=$2
27 BRANCH=$3
28 COMPARE=$4
29 test_expect_success "check normal git operations: $MSG" '
30 graph_git_two_modes "${DIR:+-C $DIR} log --oneline $BRANCH" &&
31 graph_git_two_modes "${DIR:+-C $DIR} log --topo-order $BRANCH" &&
32 graph_git_two_modes "${DIR:+-C $DIR} log --graph $COMPARE..$BRANCH" &&
33 graph_git_two_modes "${DIR:+-C $DIR} branch -vv" &&
34 graph_git_two_modes "${DIR:+-C $DIR} merge-base -a $BRANCH $COMPARE"
35 '
36 }
37
38 graph_read_expect() {
39 OPTIONAL=""
40 NUM_CHUNKS=3
41 DIR="."
42 if test "$1" = -C
43 then
44 shift
45 DIR="$1"
46 shift
47 fi
48 if test -n "$2"
49 then
50 OPTIONAL=" $2"
51 NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
52 fi
53 GENERATION_VERSION=2
54 if test -n "$3"
55 then
56 GENERATION_VERSION=$3
57 fi
58 OPTIONS=
59 if test $GENERATION_VERSION -gt 1
60 then
61 OPTIONS=" read_generation_data"
62 fi
63 cat >"$DIR/expect" <<-EOF
64 header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0
65 num_commits: $1
66 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
67 options:$OPTIONS
68 EOF
69 (
70 cd "$DIR" &&
71 test-tool read-graph >output &&
72 test_cmp expect output
73 )
74 }