Skip to content

Commit 3a7f32a

Browse files
committed
lib-commit-graph: teach --bare to graph helpers
Once `safe.bareRepository` defaults to `explicit`, bare repositories can no longer be discovered implicitly via directory walking. The commit-graph helpers `graph_git_behavior` and `graph_read_expect` in lib-commit-graph.sh currently use `-C $DIR` to enter the bare repository, which triggers implicit discovery. Teach both helpers to accept a `--bare` flag. When set, `graph_git_behavior` passes `--git-dir=$DIR` instead of `-C $DIR`, and `graph_read_expect` sets `GIT_DIR=. && export GIT_DIR` inside the subshell that runs `test-tool read-graph`. See 8d1a744 (setup.c: create `safe.bareRepository`, 2022-07-14) for the background on why implicit bare repo discovery may be rejected. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 1f8a88e commit 3a7f32a

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

t/lib-commit-graph.sh

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,41 @@ graph_git_two_modes() {
2222
# NOTE: it is a bug to call this function with <directory> containing
2323
# any characters in $IFS.
2424
graph_git_behavior() {
25+
BARE=
26+
if test "$1" = "--bare"
27+
then
28+
BARE=t
29+
shift
30+
fi
2531
MSG=$1
2632
DIR=$2
2733
BRANCH=$3
2834
COMPARE=$4
2935
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"
36+
if test -n "$BARE"
37+
then
38+
DIR_ARGS="${DIR:+--git-dir=$DIR}"
39+
else
40+
DIR_ARGS="${DIR:+-C $DIR}"
41+
fi &&
42+
graph_git_two_modes "$DIR_ARGS log --oneline $BRANCH" &&
43+
graph_git_two_modes "$DIR_ARGS log --topo-order $BRANCH" &&
44+
graph_git_two_modes "$DIR_ARGS log --graph $COMPARE..$BRANCH" &&
45+
graph_git_two_modes "$DIR_ARGS branch -vv" &&
46+
graph_git_two_modes "$DIR_ARGS merge-base -a $BRANCH $COMPARE"
3547
'
3648
}
3749

3850
graph_read_expect() {
3951
OPTIONAL=""
4052
NUM_CHUNKS=3
4153
DIR="."
54+
BARE=
55+
if test "$1" = "--bare"
56+
then
57+
BARE=t
58+
shift
59+
fi
4260
if test "$1" = -C
4361
then
4462
shift
@@ -68,6 +86,10 @@ graph_read_expect() {
6886
EOF
6987
(
7088
cd "$DIR" &&
89+
if test -n "$BARE"
90+
then
91+
GIT_DIR=. && export GIT_DIR
92+
fi &&
7193
test-tool read-graph >output &&
7294
test_cmp expect output
7395
)

0 commit comments

Comments
 (0)