blob: 54efa0db35ced05575cc4f52be8260b219772969 (
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
|
#!/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 save ==="
# Step 1: Create an upstream repository with an initial commit
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"
COMMIT1=$(git rev-parse HEAD)
cd "$TESTDIR"
# Step 2: Create parent repo and add upstream, pinned to specific commit
mkdir parent
cd parent
git init
subgit add -c "$COMMIT1" "$TESTDIR/upstream/repo1" subrepo1
# Verify the initial commit was recorded in .subgitrc
source .subgitrc
if [ "${subgitinfo[subrepo1/commit]}" != "$COMMIT1" ]; then
echo "FAIL: initial commit not recorded correctly"
exit 1
fi
# Step 3: Add a new commit to upstream repository
cd "$TESTDIR/upstream/repo1"
echo "new content" > file2.txt
git add file2.txt
git commit -m "Second commit"
COMMIT2=$(git rev-parse HEAD)
# Step 4: Fetch the new commit and update bare repo to point to it
cd "$TESTDIR/parent"
git -C .subgit/subrepo1 fetch
git -C .subgit/subrepo1 update-ref refs/heads/master refs/remotes/origin/master
# Step 5: Use 'subgit save' to update .subgitrc with the new commit
subgit save subrepo1
# Step 6: Verify that .subgitrc was updated with the new commit
# Check in-memory after sourcing
source .subgitrc
if [ "${subgitinfo[subrepo1/commit]}" != "$COMMIT2" ]; then
echo "FAIL: save did not update commit (expected $COMMIT2, got ${subgitinfo[subrepo1/commit]})"
exit 1
fi
# Check that file was actually written with new commit
if ! grep -q "$COMMIT2" .subgitrc; then
echo "FAIL: .subgitrc does not contain new commit"
exit 1
fi
echo "PASS: save test"
|