blob: 28db5676ed3a8c617910e6d1dcf54cdeff6d3774 (
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
|
#!/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 add and init ==="
# Step 1: Create an upstream repository to track
mkdir -p upstream/repo1
cd upstream/repo1
git init
echo "test content" > file1.txt
git add file1.txt
git commit -m "Initial commit"
REPO1_COMMIT=$(git rev-parse HEAD)
cd "$TESTDIR"
# Step 2: Create a parent repository and add the upstream repo as a subrepo
mkdir parent
cd parent
git init
subgit add ../upstream/repo1 subrepo1
# Step 3: Verify that subgit add created the necessary files and directories
# Check that .subgitrc configuration file was created
if [ ! -f .subgitrc ]; then
echo "FAIL: .subgitrc not created"
exit 1
fi
# Check that subrepo is tracked in .subgitrc
source .subgitrc
if [ -z "${subgit[subrepo1]}" ]; then
echo "FAIL: subrepo1 not in subgit array"
exit 1
fi
# Check that bare repository was created in .subgit/
if [ ! -d .subgit/subrepo1 ]; then
echo "FAIL: bare repo not created"
exit 1
fi
# Check that working directory was created
if [ ! -d subrepo1 ]; then
echo "FAIL: working directory not created"
exit 1
fi
# Check that .git is a symlink to the bare repo
if [ ! -L subrepo1/.git ]; then
echo "FAIL: .git symlink not created"
exit 1
fi
# Check that files from upstream were checked out
if [ ! -f subrepo1/file1.txt ]; then
echo "FAIL: file1.txt not present in working directory"
exit 1
fi
# Check that the correct commit was cloned
ACTUAL_COMMIT=$(git -C .subgit/subrepo1 rev-parse HEAD)
if [ "$ACTUAL_COMMIT" != "$REPO1_COMMIT" ]; then
echo "FAIL: commit mismatch (expected $REPO1_COMMIT, got $ACTUAL_COMMIT)"
exit 1
fi
# Step 4: Test that init can restore a deleted working directory
echo "=== Test: reinit should work ==="
rm -rf subrepo1
subgit init -f
# Verify that files were restored
if [ ! -f subrepo1/file1.txt ]; then
echo "FAIL: reinit did not restore working directory"
exit 1
fi
echo "PASS: add and init test"
|