Skip to content

Commit 3275dd0

Browse files
committed
enhance: auto stash and re-apply local changes before squashing (#1141)
Signed-off-by: leo <[email protected]>
1 parent 67fb0b3 commit 3275dd0

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/ViewModels/Histories.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,6 @@ public ContextMenu MakeContextMenu(ListBox list)
419419
squash.Icon = App.CreateMenuIcon("Icons.SquashIntoParent");
420420
squash.Click += (_, e) =>
421421
{
422-
if (_repo.LocalChangesCount > 0)
423-
{
424-
App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first.");
425-
return;
426-
}
427-
428422
if (_repo.CanCreatePopup())
429423
_repo.ShowPopup(new Squash(_repo, commit, commit.SHA));
430424

@@ -458,12 +452,6 @@ public ContextMenu MakeContextMenu(ListBox list)
458452
squash.IsEnabled = commit.Parents.Count == 1;
459453
squash.Click += (_, e) =>
460454
{
461-
if (_repo.LocalChangesCount > 0)
462-
{
463-
App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first.");
464-
return;
465-
}
466-
467455
if (commit.Parents.Count == 1)
468456
{
469457
var parent = _commits.Find(x => x.SHA == commit.Parents[0]);

src/ViewModels/Squash.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,28 @@ public override Task<bool> Sure()
3333

3434
return Task.Run(() =>
3535
{
36-
var succ = new Commands.Reset(_repo.FullPath, Target.SHA, "--soft").Exec();
36+
var autoStashed = false;
37+
var succ = false;
38+
39+
if (_repo.LocalChangesCount > 0)
40+
{
41+
succ = new Commands.Stash(_repo.FullPath).Push("SQUASH_AUTO_STASH");
42+
if (!succ)
43+
{
44+
CallUIThread(() => _repo.SetWatcherEnabled(true));
45+
return false;
46+
}
47+
48+
autoStashed = true;
49+
}
50+
51+
succ = new Commands.Reset(_repo.FullPath, Target.SHA, "--soft").Exec();
3752
if (succ)
3853
succ = new Commands.Commit(_repo.FullPath, _message, true, _repo.Settings.EnableSignOffForCommit).Run();
54+
55+
if (succ && autoStashed)
56+
new Commands.Stash(_repo.FullPath).Pop("stash@{0}");
57+
3958
CallUIThread(() => _repo.SetWatcherEnabled(true));
4059
return succ;
4160
});

0 commit comments

Comments
 (0)