summaryrefslogtreecommitdiffstats
path: root/tests/test-check.sh
blob: df73c0028ef783f5001ec011daaa9cc0b8a6f2db (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
#!/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 check ==="

# 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"
cd "$TESTDIR"

# Step 2: Create parent repo and add upstream as subrepo
mkdir parent
cd parent
git init

subgit add "$TESTDIR/upstream/repo1" subrepo1

# Step 3: Test that clean repo produces no check warnings
echo "=== Test: clean repo should have no output ==="
OUTPUT=$(subgit check subrepo1)
if [ ! -z "$OUTPUT" ]; then
	echo "FAIL: clean repo should have no check output, got: $OUTPUT"
	exit 1
fi

# Step 4: Test detection of uncommitted changes (dirty tree)
echo "=== Test: dirty tree detection ==="
echo "modified" > subrepo1/file1.txt
OUTPUT=$(subgit check subrepo1)
if ! echo "$OUTPUT" | grep -q "dirty tree"; then
	echo "FAIL: dirty tree not detected"
	exit 1
fi

# Restore file to clean state
git -C subrepo1 checkout file1.txt

# Step 5: Test detection of new commits in bare repo
echo "=== Test: new commit detection ==="

# Add a new commit to upstream
cd "$TESTDIR/upstream/repo1"
echo "new content" > file2.txt
git add file2.txt
git commit -m "Second commit"

# Fetch and update bare repo to have the new commit
cd "$TESTDIR/parent"
git -C .subgit/subrepo1 fetch
git -C .subgit/subrepo1 update-ref refs/heads/master refs/remotes/origin/master

# Check should report that bare repo has a newer commit than .subgitrc
OUTPUT=$(subgit check subrepo1)
if ! echo "$OUTPUT" | grep -q "new commit"; then
	echo "FAIL: new commit not detected"
	exit 1
fi

echo "PASS: check test"