blob: 4421dfdacdd3d7bc797d1dfc083792aeba447ef2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#!/bin/bash
set -e
# Setup: Add src directory to PATH and create isolated test directory
SRCDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../src" && pwd)"
export PATH="$SRCDIR:$PATH"
TESTDIR=$(mktemp -d)
trap "rm -rf '$TESTDIR'" EXIT
cd "$TESTDIR"
echo "=== Test: subgit helper commands ==="
# Step 1: Create two upstream repositories
mkdir -p upstream/repo1 upstream/repo2
cd upstream/repo1
git init
echo "test1" > file1.txt
git add file1.txt
git commit -m "Initial commit"
cd ../repo2
git init
echo "test2" > file2.txt
git add file2.txt
git commit -m "Initial commit"
cd "$TESTDIR"
# Step 2: Create parent repo and add both upstreams as subrepos
mkdir parent
cd parent
git init
subgit add ../upstream/repo1 subrepo1
subgit add ../upstream/repo2 subrepo2
# Step 3: Test 'subgit ls' - lists all tracked subrepos
echo "=== Test: subgit ls ==="
OUTPUT=$(subgit ls | sort)
EXPECTED=$(printf "subrepo1\nsubrepo2" | sort)
if [ "$OUTPUT" != "$EXPECTED" ]; then
echo "FAIL: ls output incorrect"
echo "Expected: $EXPECTED"
echo "Got: $OUTPUT"
exit 1
fi
# Step 4: Test 'subgit root' - finds the subgit container root
echo "=== Test: subgit root ==="
# From current directory
ROOT=$(subgit root .)
if [ "$ROOT" != "$PWD" ]; then
echo "FAIL: root should be $PWD, got $ROOT"
exit 1
fi
# From a path inside a subrepo
ROOT=$(subgit root subrepo1/file1.txt)
if [ "$ROOT" != "$PWD" ]; then
echo "FAIL: root from subrepo path should be $PWD, got $ROOT"
exit 1
fi
# Step 5: Test 'subgit parent' - finds which container tracks a path
echo "=== Test: subgit parent ==="
cd subrepo1
PARENT=$(subgit parent .)
if [ "$PARENT" != "$TESTDIR/parent" ]; then
echo "FAIL: parent should be $TESTDIR/parent, got $PARENT"
exit 1
fi
cd ..
# Step 6: Test 'subgit relpath' - finds the tracking root for a path
echo "=== Test: subgit relpath ==="
# Direct subrepo path
RELPATH=$(subgit relpath "$PWD" "$PWD/subrepo1")
if [ "$RELPATH" != "subrepo1" ]; then
echo "FAIL: relpath should be subrepo1, got $RELPATH"
exit 1
fi
# Nested path within subrepo (should still return subrepo root)
RELPATH=$(subgit relpath "$PWD" "$PWD/subrepo1/subdir")
if [ "$RELPATH" != "subrepo1" ]; then
echo "FAIL: relpath for nested path should be subrepo1, got $RELPATH"
exit 1
fi
# Step 7: Test 'subgit subrepo' - resolves paths to subrepos
echo "=== Test: subgit subrepo ==="
# Without arguments, lists all subrepos as absolute paths
OUTPUT=$(subgit subrepo | sort)
EXPECTED=$(printf "$PWD/subrepo1\n$PWD/subrepo2" | sort)
if [ "$OUTPUT" != "$EXPECTED" ]; then
echo "FAIL: subrepo output incorrect"
echo "Expected: $EXPECTED"
echo "Got: $OUTPUT"
exit 1
fi
# With argument, normalizes path to its subrepo root
SUBREPO=$(subgit subrepo subrepo1)
if [ "$SUBREPO" != "$PWD/subrepo1" ]; then
echo "FAIL: subrepo with path should return $PWD/subrepo1, got $SUBREPO"
exit 1
fi
echo "PASS: helper commands test"
|