Skip to content

Commit 8a884fe

Browse files
committed
improve unit test
1 parent 74ff8e5 commit 8a884fe

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

test/fixtures/index_extended_flags

436 Bytes
Binary file not shown.

test/test_index.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,30 +1218,47 @@ def test_index_add_non_normalized_path(self, rw_repo):
12181218

12191219
rw_repo.index.add(non_normalized_path)
12201220

1221+
def test_index_file_v3(self):
1222+
index = IndexFile(self.rorepo, fixture_path("index_extended_flags"))
1223+
assert index.entries
1224+
assert index.version == 3
1225+
assert len(index.entries) == 4
1226+
assert index.entries[('init.t', 0)].skip_worktree
1227+
1228+
# Write the data - it must match the original.
1229+
with tempfile.NamedTemporaryFile() as tmpfile:
1230+
index.write(tmpfile.name)
1231+
assert Path(tmpfile.name).read_bytes() == Path(fixture_path("index_extended_flags")).read_bytes()
1232+
12211233
@with_rw_directory
1222-
def test_index_version_v3(self, tmp_dir):
1234+
def test_index_file_v3_with_git_command(self, tmp_dir):
12231235
tmp_dir = Path(tmp_dir)
12241236
with cwd(tmp_dir):
1225-
subprocess.run(["git", "init", "-q"], check=True)
1237+
git = Git(tmp_dir)
1238+
git.init()
1239+
12261240
file = tmp_dir / "file.txt"
12271241
file.write_text("hello")
1228-
subprocess.run(["git", "add", "-N", "file.txt"], check=True)
1242+
git.add("--intent-to-add", "file.txt") # intent-to-add sets extended flag
12291243

12301244
repo = Repo(tmp_dir)
1245+
index = repo.index
12311246

1232-
assert len(repo.index.entries) == 1
1233-
entry = list(repo.index.entries.values())[0]
1247+
assert len(index.entries) == 1
1248+
assert index.version == 3
1249+
entry = list(index.entries.values())[0]
12341250
assert entry.path == "file.txt"
12351251
assert entry.intent_to_add
12361252

12371253
file2 = tmp_dir / "file2.txt"
12381254
file2.write_text("world")
1239-
repo.index.add(["file2.txt"])
1240-
repo.index.write()
1255+
index.add(["file2.txt"])
1256+
index.write()
12411257

1242-
status_str = subprocess.check_output(["git", "status", "--porcelain"], text=True)
1243-
assert " A file.txt\n" in status_str
1244-
assert "A file2.txt\n" in status_str
1258+
status_str = git.status(porcelain=True)
1259+
status_lines = status_str.splitlines()
1260+
assert " A file.txt" in status_lines
1261+
assert "A file2.txt" in status_lines
12451262

12461263

12471264
class TestIndexUtils:

0 commit comments

Comments
 (0)