Skip to content

Commit 3d4e488

Browse files
committed
Better prompt for discarding old file changes
Lazygit knows what kind of file change this is, so there doesn't have to be any "if" in the prompt text.
1 parent b4ddb12 commit 3d4e488

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

pkg/commands/models/commit_file.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ func (f *CommitFile) ID() string {
1515
func (f *CommitFile) Description() string {
1616
return f.Name
1717
}
18+
19+
func (f *CommitFile) Added() bool {
20+
return f.ChangeStatus == "A"
21+
}
22+
23+
func (f *CommitFile) Deleted() bool {
24+
return f.ChangeStatus == "D"
25+
}

pkg/gui/controllers/commits_files_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,16 @@ func (self *CommitFilesController) discard(node *filetree.CommitFileNode) error
161161
return err
162162
}
163163

164+
prompt := self.c.Tr.DiscardFileChangesPrompt
165+
if node.File.Added() {
166+
prompt = self.c.Tr.DiscardAddedFileChangesPrompt
167+
} else if node.File.Deleted() {
168+
prompt = self.c.Tr.DiscardDeletedFileChangesPrompt
169+
}
170+
164171
return self.c.Confirm(types.ConfirmOpts{
165172
Title: self.c.Tr.DiscardFileChangesTitle,
166-
Prompt: self.c.Tr.DiscardFileChangesPrompt,
173+
Prompt: prompt,
167174
HandleConfirm: func() error {
168175
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error {
169176
self.c.LogAction(self.c.Tr.Actions.DiscardOldFileChange)

pkg/i18n/english.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ type TranslationSet struct {
268268
DiscardOldFileChange string
269269
DiscardFileChangesTitle string
270270
DiscardFileChangesPrompt string
271+
DiscardAddedFileChangesPrompt string
272+
DiscardDeletedFileChangesPrompt string
271273
DiscardNotSupportedForDirectory string
272274
DisabledForGPG string
273275
CreateRepo string
@@ -955,7 +957,9 @@ func EnglishTranslationSet() TranslationSet {
955957
CheckoutCommitFile: "Checkout file",
956958
DiscardOldFileChange: "Discard this commit's changes to this file",
957959
DiscardFileChangesTitle: "Discard file changes",
958-
DiscardFileChangesPrompt: "Are you sure you want to discard this commit's changes to this file? If this file was created in this commit, it will be deleted",
960+
DiscardFileChangesPrompt: "Are you sure you want to discard this commit's changes to this file?",
961+
DiscardAddedFileChangesPrompt: "Are you sure you want to discard this commit's changes to this file? The file was added in this commit, so it will be deleted again.",
962+
DiscardDeletedFileChangesPrompt: "Are you sure you want to discard this commit's changes to this file? The file was deleted in this commit, so it will reappear.",
959963
DiscardNotSupportedForDirectory: "Discarding changes is not supported for entire directories. Please use a custom patch for this.",
960964
DisabledForGPG: "Feature not available for users using GPG",
961965
CreateRepo: "Not in a git repository. Create a new git repository? (y/n): ",

pkg/integration/tests/commit/discard_old_file_change.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var DiscardOldFileChange = NewIntegrationTest(NewIntegrationTestArgs{
4343

4444
t.ExpectPopup().Confirmation().
4545
Title(Equals("Discard file changes")).
46-
Content(Contains("Are you sure you want to discard this commit's changes to this file?")).
46+
Content(Equals("Are you sure you want to discard this commit's changes to this file? The file was added in this commit, so it will be deleted again.")).
4747
Confirm()
4848

4949
t.Views().CommitFiles().

0 commit comments

Comments
 (0)