| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1218,30 +1218,48 @@ def test_index_add_non_normalized_path(self, rw_repo): | |||
| 1218 | 1218 | ||
| 1219 | 1219 | rw_repo.index.add(non_normalized_path) | |
| 1220 | 1220 | ||
| 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 | + tmpfile = tempfile.mktemp() | ||
| 1230 | + index.write(tmpfile) | ||
| 1231 | + assert Path(tmpfile).read_bytes() == Path(fixture_path("index_extended_flags")).read_bytes() | ||
| 1232 | + os.remove(tmpfile) | ||
| 1233 | + | ||
| 1221 | 1234 | @with_rw_directory | |
| 1222 | - def test_index_version_v3(self, tmp_dir): | ||
| 1235 | + def test_index_file_v3_with_git_command(self, tmp_dir): | ||
| 1223 | 1236 | tmp_dir = Path(tmp_dir) | |
| 1224 | 1237 | with cwd(tmp_dir): | |
| 1225 | - subprocess.run(["git", "init", "-q"], check=True) | ||
| 1238 | + git = Git(tmp_dir) | ||
| 1239 | + git.init() | ||
| 1240 | + | ||
| 1226 | 1241 | file = tmp_dir / "file.txt" | |
| 1227 | 1242 | file.write_text("hello") | |
| 1228 | - subprocess.run(["git", "add", "-N", "file.txt"], check=True) | ||
| 1243 | + git.add("--intent-to-add", "file.txt") # intent-to-add sets extended flag | ||
| 1229 | 1244 | ||
| 1230 | 1245 | repo = Repo(tmp_dir) | |
| 1246 | + index = repo.index | ||
| 1231 | 1247 | ||
| 1232 | - assert len(repo.index.entries) == 1 | ||
| 1233 | - entry = list(repo.index.entries.values())[0] | ||
| 1248 | + assert len(index.entries) == 1 | ||
| 1249 | + assert index.version == 3 | ||
| 1250 | + entry = list(index.entries.values())[0] | ||
| 1234 | 1251 | assert entry.path == "file.txt" | |
| 1235 | 1252 | assert entry.intent_to_add | |
| 1236 | 1253 | ||
| 1237 | 1254 | file2 = tmp_dir / "file2.txt" | |
| 1238 | 1255 | file2.write_text("world") | |
| 1239 | - repo.index.add(["file2.txt"]) | ||
| 1240 | - repo.index.write() | ||
| 1256 | + index.add(["file2.txt"]) | ||
| 1257 | + index.write() | ||
| 1241 | 1258 | ||
| 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 | ||
| 1259 | + status_str = git.status(porcelain=True) | ||
| 1260 | + status_lines = status_str.splitlines() | ||
| 1261 | + assert " A file.txt" in status_lines | ||
| 1262 | + assert "A file2.txt" in status_lines | ||
| 1245 | 1263 | ||
| 1246 | 1264 | ||
| 1247 | 1265 | class TestIndexUtils: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments