blob: 3a6a6a7ecefeb10bb7c031fec80e6044e3e5850d (
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
114
|
#!/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 with single path argument ==="
# Step 1: Create an upstream repository
mkdir -p upstream/repo1
cd upstream/repo1
git init
git config user.email "test@test.com"
git config user.name "Test User"
echo "test content" > file1.txt
git add file1.txt
git commit -m "Initial commit"
REPO_COMMIT=$(git rev-parse HEAD)
REPO_BRANCH=$(git branch --show-current)
UPSTREAM_PATH=$(pwd)
cd "$TESTDIR"
# Step 2: Create parent repo
mkdir parent
cd parent
git init
# Step 3: Clone the repo inside parent to create a local copy with .git
git clone ../upstream/repo1 myrepo
# Step 4: Add the local copy using single-path syntax
subgit add myrepo
# Step 5: Verify that the repo was added correctly
# Check that .subgitrc was created
if [ ! -f .subgitrc ]; then
echo "FAIL: .subgitrc not created"
exit 1
fi
# Check that remote was extracted correctly (git clone sets it to the path cloned from)
source .subgitrc
EXPECTED_REMOTE="$TESTDIR/parent/../upstream/repo1"
if [ "${subgitinfo[myrepo/remote]}" != "$EXPECTED_REMOTE" ]; then
echo "FAIL: remote not extracted correctly (expected $EXPECTED_REMOTE, got ${subgitinfo[myrepo/remote]})"
exit 1
fi
# Check that branch was extracted correctly
if [ "${subgitinfo[myrepo/branch]}" != "$REPO_BRANCH" ]; then
echo "FAIL: branch not extracted correctly (expected $REPO_BRANCH, got ${subgitinfo[myrepo/branch]})"
exit 1
fi
# Check that commit was extracted correctly
if [ "${subgitinfo[myrepo/commit]}" != "$REPO_COMMIT" ]; then
echo "FAIL: commit not extracted correctly (expected $REPO_COMMIT, got ${subgitinfo[myrepo/commit]})"
exit 1
fi
# Check that .git was moved to .subgit/
if [ ! -d .subgit/myrepo ]; then
echo "FAIL: bare repo not created in .subgit/"
exit 1
fi
# Check that .git is now a symlink
if [ ! -L myrepo/.git ]; then
echo "FAIL: .git symlink not created"
exit 1
fi
# Check that files are still accessible
if [ ! -f myrepo/file1.txt ]; then
echo "FAIL: file1.txt not present in working directory"
exit 1
fi
echo "=== Test: add path with explicit commit override ==="
# Clone another repo inside parent
git clone ../upstream/repo1 myrepo2
cd myrepo2
echo "new content" > file2.txt
git add file2.txt
git commit -m "Second commit"
SECOND_COMMIT=$(git rev-parse HEAD)
cd ..
# Add with explicit commit (should use the specified commit, not HEAD)
subgit add -c "$REPO_COMMIT" myrepo2
source .subgitrc
if [ "${subgitinfo[myrepo2/commit]}" != "$REPO_COMMIT" ]; then
echo "FAIL: explicit commit not used (expected $REPO_COMMIT, got ${subgitinfo[myrepo2/commit]})"
exit 1
fi
# Working directory should be at the specified commit
ACTUAL_COMMIT=$(git -C myrepo2 rev-parse HEAD)
if [ "$ACTUAL_COMMIT" != "$REPO_COMMIT" ]; then
echo "FAIL: working directory not at specified commit"
exit 1
fi
echo "PASS: add path test"
|