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..79bd6e2d 100644 --- a/test/test_filelist.py +++ b/test/test_filelist.py @@ -660,3 +660,28 @@ 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") + repo.index.add_all() + repo.index.write() + + rw = mainWindow.openRepo(wd) + + staged = qlvGetRowData(rw.stagedFiles) + assert staged == ["b.txt"] + + rw.diffArea.stagedFiles.selectAll() + triggerContextMenuAction(rw.diffArea.stagedFiles.viewport(), "unstage") + + status = rw.repo.status() + assert status['a.txt'] == FileStatus.WT_DELETED + assert status['b.txt'] == FileStatus.WT_NEW