Skip to content

Commit d288b91

Browse files
committed
fix: stash local shared untracked on update
Signed-off-by: Josef Andersson <josef.andersson@digg.se>
1 parent 9096cac commit d288b91

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

scripts/setup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ update_to_version() {
2929
local version="$1"
3030
# Fetch only the specific tag, shallow
3131
git -C "$DIR" fetch --depth 1 origin tag "$version" --quiet
32-
# Stash any local changes to avoid checkout conflicts
33-
git -C "$DIR" stash --quiet 2>/dev/null || true
32+
# Stash any local changes (including untracked files) to avoid checkout conflicts
33+
git -C "$DIR" stash --include-untracked --quiet 2>/dev/null || true
3434
git -C "$DIR" checkout "$version" --quiet
3535
print_success "Updated to $version"
3636
}

tests/setup.bats

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,64 @@ teardown() {
109109
marker_age=$(find "$fake_dir/.last-update-check" -mmin +1 2>/dev/null || true)
110110
assert_equal "$marker_age" ""
111111
}
112+
113+
# =============================================================================
114+
# Update with untracked files tests
115+
# =============================================================================
116+
117+
@test "setup.sh update handles untracked files without failing" {
118+
setup_isolated_home
119+
local fake_dir="${TEST_DIR}/devtools"
120+
local remote_dir="${TEST_DIR}/remote.git"
121+
122+
# Create local repo with two commits and tags
123+
mkdir -p "$fake_dir"
124+
cd "$fake_dir"
125+
export GIT_CONFIG_NOSYSTEM=1
126+
export GIT_CONFIG_GLOBAL="${HOME}/.gitconfig"
127+
export GIT_EDITOR=true # Prevent editor from opening
128+
git init -q --initial-branch=main
129+
git config user.email "test@example.com"
130+
git config user.name "Test"
131+
echo "initial" > README.md
132+
git add README.md
133+
git commit -q -m "Initial commit"
134+
git tag -a v1.0.0 -m "v1.0.0" # Use annotated tag with message
135+
136+
# Make a new commit and tag v1.0.1
137+
echo "updated" > README.md
138+
git add README.md
139+
git commit -q -m "Update"
140+
git tag -a v1.0.1 -m "v1.0.1"
141+
142+
# Create a bare remote and push everything
143+
git init -q --bare "$remote_dir"
144+
git remote add origin "$remote_dir"
145+
git push --all origin 2>/dev/null
146+
git push --tags origin 2>/dev/null
147+
148+
# Go back to v1.0.0 (simulating outdated install)
149+
git checkout v1.0.0 --quiet
150+
151+
# Create untracked files (simulating user's local experiments)
152+
# These would conflict with checkout if not handled properly
153+
echo "my local test" > untracked-test-file.txt
154+
mkdir -p new-utils
155+
echo "local utility" > new-utils/my-util.sh
156+
157+
# Create old marker to trigger update check
158+
touch "$fake_dir/.last-update-check"
159+
touch -d "61 minutes ago" "$fake_dir/.last-update-check"
160+
161+
# Run setup in non-interactive mode (CI=true auto-updates)
162+
export CI=true
163+
run "$SCRIPT_DIR/setup.sh" "$remote_dir" "$fake_dir"
164+
165+
assert_success
166+
assert_output --partial "Updated to v1.0.1"
167+
168+
# Verify we're now on v1.0.1
169+
cd "$fake_dir"
170+
run git describe --tags --abbrev=0
171+
assert_output "v1.0.1"
172+
}

0 commit comments

Comments
 (0)