Skip to content

Commit 6f44aca

Browse files
committed
Combine non-"slashes" (i.e. trees) scripts and make it a fixture
At least for now, this does not test the creation of multiple files at a time outside of a repository, nor multi-step upward traversal with many `../../..` components, since tests using such fixtures would be complicated, and may or may not be warranted in the test suite. However, this combines substantial elements of the scripts that create repositories with unexpected tree objects (e.g., `..` trees) to make a make_traverse_trees.sh script that, when run, produces repositories for testing that traverse: - Upward with a `..` tree: `traverse_dotdot_tree` - Downward with `.git` and `hooks` trees: `traverse_dotgit_trees` - Similar but with an NTFS stream alias: `traverse_dotgit_stream` This replaces the `make_traverse_dotdot_trees.sh` and `make_traverse_ntfs_streams.sh` scripts with one script that takes no command-line arguments and creates multiple repos by calling a function. This is thus architecturally similar, broadly speaking, to `make_traverse_literal_slashes.sh`, but that produces repos with very strangely named blobs, rather than with strangly named trees.
1 parent 7e9c769 commit 6f44aca

File tree

3 files changed

+39
-61
lines changed

3 files changed

+39
-61
lines changed

gix-worktree/tests/fixtures/make_traverse_dotdot_trees.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

gix-worktree/tests/fixtures/make_traverse_ntfs_stream.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
# Makes a repo carrying a tree structure representing the given path to a blob.
5+
# File content is from stdin. Args are repo name, path, -x or +x, and tr sets.
6+
function make_repo() (
7+
local repo="$1" path="$2" xbit="$3" set1="$4" set2="$5"
8+
local dir dir_standin path_standin path_standin_pattern path_replacement
9+
10+
git init -- "$repo"
11+
cd -- "$repo" # Temporary, as the function body is a ( ) subshell.
12+
13+
dir="${path%/*}"
14+
dir_standin="$(tr "$set1" "$set2" <<<"$dir")"
15+
path_standin="$(tr "$set1" "$set2" <<<"$path")"
16+
mkdir -p -- "$dir_standin"
17+
cat >"$path_standin"
18+
git add --chmod="$xbit" -- "$path_standin"
19+
path_standin_pattern="$(sed 's/[|.*^$\]/\\&/g' <<<"$path_standin")"
20+
path_replacement="$(sed 's/[|&\]/\\&/g' <<<"$path")"
21+
cp .git/index old_index
22+
LC_ALL=C sed "s|$path_standin_pattern|$path_replacement|g" old_index >.git/index
23+
git commit -m 'Initial commit'
24+
)
25+
26+
make_repo traverse_dotdot_trees '../outside' -x '.' '@' \
27+
<<<'A file outside the working tree, somehow.'
28+
29+
make_repo traverse_dotgit_trees '.git/hooks/pre-commit' +x '.' '@' <<'EOF'
30+
#!/bin/sh
31+
printf 'Vulnerable!\n'
32+
date >vulnerable
33+
EOF
34+
35+
make_repo traverse_dotgit_stream '.git::$INDEX_ALLOCATION/hooks/pre-commit' +x ':' ',' <<'EOF'
36+
#!/bin/sh
37+
printf 'Vulnerable!\n'
38+
date >vulnerable
39+
EOF

0 commit comments

Comments
 (0)