Skip to content

Commit a6245ae

Browse files
committed
tests/cmd/git(test): Add test for stash pop with specific index
why: Commit 12065f6 changed stash pop() to use stash@{N} format instead of pathspec separator. This test verifies that popping a stash by index works correctly when multiple stashes exist. what: - Add test_stash_pop_by_specific_index that creates 3 stashes - Pop stash@{1} (middle one) to verify stash@{N} format works - Include LIFO ordering note in docstring for clarity
1 parent 46e9c1f commit a6245ae

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

tests/cmd/test_git.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,51 @@ def test_stash_apply_pop(
12151215
assert len(stashes_after) >= 1
12161216

12171217

1218+
def test_stash_pop_by_specific_index(git_repo: GitSync) -> None:
1219+
"""Test GitStashEntryCmd.pop() with specific stash index.
1220+
1221+
Verifies commit 12065f6: pop() uses stash@{N} format instead of
1222+
pathspec separator (-- N) which caused 'is not a valid reference' errors.
1223+
1224+
Note: git stash uses LIFO ordering:
1225+
- stash@{0} = most recent
1226+
- stash@{1} = second most recent
1227+
- stash@{2} = oldest
1228+
"""
1229+
# Clear any existing stashes
1230+
git_repo.cmd.stashes.clear()
1231+
1232+
# Create a tracked file
1233+
test_file = git_repo.path / "stash_pop_index_test.txt"
1234+
test_file.write_text("initial content")
1235+
git_repo.cmd.run(["add", "stash_pop_index_test.txt"])
1236+
git_repo.cmd.run(["commit", "-m", "Add test file"])
1237+
1238+
# Create multiple stashes
1239+
# Note: stash@{0} is most recent, stash@{2} is oldest
1240+
for msg in ["oldest", "middle", "newest"]:
1241+
test_file.write_text(f"modified for {msg}")
1242+
git_repo.cmd.stashes.push(message=msg)
1243+
1244+
# Verify we have 3 stashes
1245+
stashes = git_repo.cmd.stashes.ls()
1246+
assert len(stashes) == 3
1247+
1248+
# Pop stash@{1} (the middle one)
1249+
# This tests that the stash@{N} format works correctly
1250+
middle_stash = git_repo.cmd.stashes.get(index=1)
1251+
assert middle_stash is not None
1252+
assert "middle" in middle_stash.message
1253+
1254+
# Pop should NOT produce "is not a valid reference" error
1255+
result = middle_stash.pop()
1256+
assert "is not a valid reference" not in result.lower()
1257+
1258+
# Verify we now have 2 stashes
1259+
stashes_after = git_repo.cmd.stashes.ls()
1260+
assert len(stashes_after) == 2
1261+
1262+
12181263
def test_stash_drop(git_repo: GitSync) -> None:
12191264
"""Test GitStashEntryCmd.drop()."""
12201265
# Clear any existing stashes

0 commit comments

Comments
 (0)