Skip to content

Commit 87fb349

Browse files
committed
Fix stash deletion failing when trash is disabled
backupStash() called Trash.newFile(), which raises Trash.BackupSkipped when the trash is disabled (maxTrashFiles == 0). backupStash did not catch it, so DropStash and 'apply and delete' aborted with an error and the stash was never removed. The dead 'if not trashFile' guard assumed newFile() returns None, which it never does. Catch Trash.BackupSkipped and skip the backup, matching how DiscardFiles handles the same exception.
1 parent 8998236 commit 87fb349

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

gitfourchette/tasks/stashtasks.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# -----------------------------------------------------------------------------
66

77
import itertools
8+
import logging
89

910
from gitfourchette.forms.stashdialog import StashDialog
1011
from gitfourchette.localization import *
@@ -15,6 +16,8 @@
1516
from gitfourchette.toolbox import *
1617
from gitfourchette.trash import Trash
1718

19+
logger = logging.getLogger(__name__)
20+
1821
_indexStatusTable = {
1922
"A": FileStatus.INDEX_NEW,
2023
"D": FileStatus.INDEX_DELETED,
@@ -40,9 +43,10 @@
4043

4144

4245
def backupStash(repo: Repo, stashCommitId: Oid):
43-
trashFile = Trash.instance().newFile(repo.workdir, ext=".txt", originalPath="DELETED_STASH")
44-
45-
if not trashFile:
46+
try:
47+
trashFile = Trash.instance().newFile(repo.workdir, ext=".txt", originalPath="DELETED_STASH")
48+
except Trash.BackupSkipped as ex:
49+
logger.warning(f"Stash backup skipped: {ex}")
4650
return
4751

4852
text = F"""\

0 commit comments

Comments
 (0)