From 038ba7f8a927c2ca951ac428d484cba3cdc0e2e5 Mon Sep 17 00:00:00 2001 From: Zach Rammell Date: Mon, 2 Feb 2026 23:43:41 -0800 Subject: [PATCH 1/2] Unstage both addition and deletion when unstaging rename --- gitfourchette/tasks/indextasks.py | 7 ++++++- test/test_filelist.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/gitfourchette/tasks/indextasks.py b/gitfourchette/tasks/indextasks.py index 49b314fe..e446531b 100644 --- a/gitfourchette/tasks/indextasks.py +++ b/gitfourchette/tasks/indextasks.py @@ -234,7 +234,12 @@ def flow(self, deltas: list[GitDelta]): QApplication.beep() raise AbortTask() - paths = [delta.new.path for delta in deltas] + paths = [] + for delta in deltas: + paths.append(delta.new.path) + if delta.status == "R": + paths.append(delta.old.path) + self.effects |= TaskEffects.Workdir # Not using 'restore --staged' because it doesn't work in an empty repo yield from self.flowCallGit("reset", "--", *paths) diff --git a/test/test_filelist.py b/test/test_filelist.py index e19ea369..efadfce6 100644 --- a/test/test_filelist.py +++ b/test/test_filelist.py @@ -660,3 +660,33 @@ def testFileListNaturalSort(tempDir, mainWindow): rw = mainWindow.openRepo(wd) assert qlvGetRowData(rw.dirtyFiles) == names + + +def testUnstageRenamedFile(tempDir, mainWindow): + wd = unpackRepo(tempDir) + writeFile(f"{wd}/a.txt", "content") + + with RepoContext(wd) as repo: + repo.index.add("a.txt") + repo.create_commit_on_head("initial", TEST_SIGNATURE, TEST_SIGNATURE) + + os.rename(f"{wd}/a.txt", f"{wd}/b.txt") + + with RepoContext(wd) as repo: + repo.index.add_all() + repo.index.write() + + rw = mainWindow.openRepo(wd) + + staged = list(qlvGetRowData(rw.stagedFiles)) + assert staged == ["b.txt"] + + rw.diffArea.stagedFiles.selectAll() + triggerContextMenuAction(rw.diffArea.stagedFiles.viewport(), "unstage") + + rw.refreshRepo() + + status = rw.repo.status() + + assert status['a.txt'] == FileStatus.WT_DELETED + assert status['b.txt'] == FileStatus.WT_NEW From 57d1f0b8cbd2767dd7cc970c3685b4a1914f5c9f Mon Sep 17 00:00:00 2001 From: Iliyas Jorio Date: Mon, 9 Feb 2026 22:00:22 +0100 Subject: [PATCH 2/2] Make ruff happy (testUnstageRenamedFile) --- test/test_filelist.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/test/test_filelist.py b/test/test_filelist.py index efadfce6..79bd6e2d 100644 --- a/test/test_filelist.py +++ b/test/test_filelist.py @@ -665,28 +665,23 @@ def testFileListNaturalSort(tempDir, mainWindow): def testUnstageRenamedFile(tempDir, mainWindow): wd = unpackRepo(tempDir) writeFile(f"{wd}/a.txt", "content") - + with RepoContext(wd) as repo: repo.index.add("a.txt") repo.create_commit_on_head("initial", TEST_SIGNATURE, TEST_SIGNATURE) - os.rename(f"{wd}/a.txt", f"{wd}/b.txt") - - with RepoContext(wd) as repo: + os.rename(f"{wd}/a.txt", f"{wd}/b.txt") repo.index.add_all() repo.index.write() rw = mainWindow.openRepo(wd) - - staged = list(qlvGetRowData(rw.stagedFiles)) + + staged = qlvGetRowData(rw.stagedFiles) assert staged == ["b.txt"] - + rw.diffArea.stagedFiles.selectAll() triggerContextMenuAction(rw.diffArea.stagedFiles.viewport(), "unstage") - - rw.refreshRepo() - + status = rw.repo.status() - assert status['a.txt'] == FileStatus.WT_DELETED assert status['b.txt'] == FileStatus.WT_NEW