Skip to content

Commit c355b64

Browse files
ttaylorrgitster
authored andcommitted
t/lib-commit-graph.sh: allow graph_read_expect() in sub-directories
The `graph_read_expect()` function is used to ensure that the output of the "read-graph" test helper matches certain parameters (e.g., how many commits are in the graph, which chunks were written, etc.). It expects the Git repository being tested to be at the current working directory. However, a handful of t5318 tests use different repositories stored in sub-directories. To work around this, several tests in t5318 change into the relevant repository outside of a sub-shell, altering the context for the rest of the suite. Prepare to remove these globally-scoped directory changes by teaching `graph_read_expect()` to take an optional "-C dir" to specify where the repository containing the commit-graph being tested is. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6016ee0 commit c355b64

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

t/lib-commit-graph.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ graph_git_behavior() {
3232
graph_read_expect() {
3333
OPTIONAL=""
3434
NUM_CHUNKS=3
35+
DIR="."
36+
if test "$1" = -C
37+
then
38+
shift
39+
DIR="$1"
40+
shift
41+
fi
3542
if test -n "$2"
3643
then
3744
OPTIONAL=" $2"
@@ -47,12 +54,15 @@ graph_read_expect() {
4754
then
4855
OPTIONS=" read_generation_data"
4956
fi
50-
cat >expect <<- EOF
57+
cat >"$DIR/expect" <<-EOF
5158
header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0
5259
num_commits: $1
5360
chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
5461
options:$OPTIONS
5562
EOF
56-
test-tool read-graph >output &&
57-
test_cmp expect output
63+
(
64+
cd "$DIR" &&
65+
test-tool read-graph >output &&
66+
test_cmp expect output
67+
)
5868
}

0 commit comments

Comments
 (0)