Skip to content

Commit a53787c

Browse files
committed
fix: git rebase --continue fail (#693)
* fix the exit code when start `SourceGit` as core editor (rebasing). * redesign the layout of working copy page for in-progress states. Signed-off-by: leo <[email protected]>
1 parent bb90c86 commit a53787c

File tree

6 files changed

+119
-76
lines changed

6 files changed

+119
-76
lines changed

src/App.axaml.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,17 +478,20 @@ private static bool TryLaunchedAsRebaseMessageEditor(string[] args, out int exit
478478
if (args.Length <= 1 || !args[0].Equals("--rebase-message-editor", StringComparison.Ordinal))
479479
return false;
480480

481+
exitCode = 0;
482+
481483
var file = args[1];
482484
var filename = Path.GetFileName(file);
483485
if (!filename.Equals("COMMIT_EDITMSG", StringComparison.OrdinalIgnoreCase))
484486
return true;
485487

486-
var jobsFile = Path.Combine(Path.GetDirectoryName(file)!, "sourcegit_rebase_jobs.json");
488+
var gitDir = Path.GetDirectoryName(file)!;
489+
var jobsFile = Path.Combine(gitDir, "sourcegit_rebase_jobs.json");
487490
if (!File.Exists(jobsFile))
488491
return true;
489492

490493
var collection = JsonSerializer.Deserialize(File.ReadAllText(jobsFile), JsonCodeGen.Default.InteractiveRebaseJobCollection);
491-
var doneFile = Path.Combine(Path.GetDirectoryName(file)!, "rebase-merge", "done");
494+
var doneFile = Path.Combine(gitDir, "rebase-merge", "done");
492495
if (!File.Exists(doneFile))
493496
return true;
494497

@@ -499,7 +502,6 @@ private static bool TryLaunchedAsRebaseMessageEditor(string[] args, out int exit
499502
var job = collection.Jobs[done.Length - 1];
500503
File.WriteAllText(file, job.Message);
501504

502-
exitCode = 0;
503505
return true;
504506
}
505507

src/Resources/Styles.axaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,12 @@
512512
<Style Selector="Button.flat.primary ToolTip TextBlock">
513513
<Setter Property="Foreground" Value="{DynamicResource Brush.FG1}"/>
514514
</Style>
515+
<Style Selector="Button.flat:disabled /template/ ContentPresenter#PART_ContentPresenter">
516+
<Setter Property="Background" Value="Transparent"/>
517+
</Style>
518+
<Style Selector="Button.flat:disabled">
519+
<Setter Property="Background" Value="{DynamicResource Brush.FlatButton.Background}"/>
520+
</Style>
515521

516522
<Style Selector="aes|SearchPanel">
517523
<Setter Property="Template">

src/ViewModels/Repository.cs

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,7 @@ public bool IsWorktreeGroupExpanded
336336

337337
public InProgressContext InProgressContext
338338
{
339-
get => _inProgressContext;
340-
private set => SetProperty(ref _inProgressContext, value);
341-
}
342-
343-
public bool HasUnsolvedConflicts
344-
{
345-
get => _hasUnsolvedConflicts;
346-
private set => SetProperty(ref _hasUnsolvedConflicts, value);
339+
get => _workingCopy?.InProgressContext;
347340
}
348341

349342
public Models.Commit SearchResultSelectedCommit
@@ -395,8 +388,6 @@ public void Open()
395388
_stashesPage = new StashesPage(this);
396389
_selectedView = _histories;
397390
_selectedViewIndex = 0;
398-
_inProgressContext = null;
399-
_hasUnsolvedConflicts = false;
400391

401392
_autoFetchTimer = new Timer(AutoFetchImpl, null, 5000, 5000);
402393
RefreshAll();
@@ -429,7 +420,6 @@ public void Close()
429420
_histories = null;
430421
_workingCopy = null;
431422
_stashesPage = null;
432-
_inProgressContext = null;
433423

434424
_localChangesCount = 0;
435425
_stashesCount = 0;
@@ -732,40 +722,9 @@ public void GotoResolve()
732722
SelectedViewIndex = 1;
733723
}
734724

735-
public async void ContinueMerge()
736-
{
737-
if (_inProgressContext != null)
738-
{
739-
SetWatcherEnabled(false);
740-
var succ = await Task.Run(_inProgressContext.Continue);
741-
if (succ && _workingCopy != null)
742-
{
743-
_workingCopy.CommitMessage = string.Empty;
744-
}
745-
SetWatcherEnabled(true);
746-
}
747-
else
748-
{
749-
MarkWorkingCopyDirtyManually();
750-
}
751-
}
752-
753-
public async void AbortMerge()
725+
public void AbortMerge()
754726
{
755-
if (_inProgressContext != null)
756-
{
757-
SetWatcherEnabled(false);
758-
var succ = await Task.Run(_inProgressContext.Abort);
759-
if (succ && _workingCopy != null)
760-
{
761-
_workingCopy.CommitMessage = string.Empty;
762-
}
763-
SetWatcherEnabled(true);
764-
}
765-
else
766-
{
767-
MarkWorkingCopyDirtyManually();
768-
}
727+
_workingCopy?.AbortMerge();
769728
}
770729

771730
public void RefreshBranches()
@@ -869,23 +828,12 @@ public void RefreshWorkingCopyChanges()
869828
if (_workingCopy == null)
870829
return;
871830

872-
var hasUnsolvedConflict = _workingCopy.SetData(changes);
873-
var inProgress = null as InProgressContext;
874-
875-
if (File.Exists(Path.Combine(_gitDir, "CHERRY_PICK_HEAD")))
876-
inProgress = new CherryPickInProgress(_fullpath);
877-
else if (File.Exists(Path.Combine(_gitDir, "REBASE_HEAD")) && Directory.Exists(Path.Combine(_gitDir, "rebase-merge")))
878-
inProgress = new RebaseInProgress(this);
879-
else if (File.Exists(Path.Combine(_gitDir, "REVERT_HEAD")))
880-
inProgress = new RevertInProgress(_fullpath);
881-
else if (File.Exists(Path.Combine(_gitDir, "MERGE_HEAD")))
882-
inProgress = new MergeInProgress(_fullpath);
831+
_workingCopy.SetData(changes);
883832

884833
Dispatcher.UIThread.Invoke(() =>
885834
{
886-
InProgressContext = inProgress;
887-
HasUnsolvedConflicts = hasUnsolvedConflict;
888835
LocalChangesCount = changes.Count;
836+
OnPropertyChanged(nameof(InProgressContext));
889837
});
890838
}
891839

@@ -2173,10 +2121,7 @@ private void AutoFetchImpl(object sender)
21732121
private List<Models.Submodule> _visibleSubmodules = new List<Models.Submodule>();
21742122

21752123
private bool _includeUntracked = true;
2176-
private InProgressContext _inProgressContext = null;
2177-
private bool _hasUnsolvedConflicts = false;
21782124
private Models.Commit _searchResultSelectedCommit = null;
2179-
21802125
private Timer _autoFetchTimer = null;
21812126
private DateTime _lastFetchTime = DateTime.MinValue;
21822127
}

src/ViewModels/WorkingCopy.cs

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ public bool CanCommitWithPush
5656
}
5757
}
5858

59+
public bool HasUnsolvedConflicts
60+
{
61+
get => _hasUnsolvedConflicts;
62+
set => SetProperty(ref _hasUnsolvedConflicts, value);
63+
}
64+
65+
public InProgressContext InProgressContext
66+
{
67+
get => _inProgressContext;
68+
private set => SetProperty(ref _inProgressContext, value);
69+
}
70+
5971
public bool IsStaging
6072
{
6173
get => _isStaging;
@@ -191,6 +203,7 @@ public WorkingCopy(Repository repo)
191203
public void Cleanup()
192204
{
193205
_repo = null;
206+
_inProgressContext = null;
194207

195208
_selectedUnstaged.Clear();
196209
OnPropertyChanged(nameof(SelectedUnstaged));
@@ -208,7 +221,7 @@ public void Cleanup()
208221
_commitMessage = string.Empty;
209222
}
210223

211-
public bool SetData(List<Models.Change> changes)
224+
public void SetData(List<Models.Change> changes)
212225
{
213226
if (!IsChanged(_cached, changes))
214227
{
@@ -221,9 +234,22 @@ public bool SetData(List<Models.Change> changes)
221234
SetDetail(_selectedStaged[0], false);
222235
else
223236
SetDetail(null, false);
237+
238+
var inProgress = null as InProgressContext;
239+
if (File.Exists(Path.Combine(_repo.GitDir, "CHERRY_PICK_HEAD")))
240+
inProgress = new CherryPickInProgress(_repo.FullPath);
241+
else if (File.Exists(Path.Combine(_repo.GitDir, "REBASE_HEAD")) && Directory.Exists(Path.Combine(_repo.GitDir, "rebase-merge")))
242+
inProgress = new RebaseInProgress(_repo);
243+
else if (File.Exists(Path.Combine(_repo.GitDir, "REVERT_HEAD")))
244+
inProgress = new RevertInProgress(_repo.FullPath);
245+
else if (File.Exists(Path.Combine(_repo.GitDir, "MERGE_HEAD")))
246+
inProgress = new MergeInProgress(_repo.FullPath);
247+
248+
HasUnsolvedConflicts = _cached.Find(x => x.IsConflit) != null;
249+
InProgressContext = inProgress;
224250
});
225251

226-
return _cached.Find(x => x.IsConflit) != null;
252+
return;
227253
}
228254

229255
_cached = changes;
@@ -268,6 +294,7 @@ public bool SetData(List<Models.Change> changes)
268294
Dispatcher.UIThread.Invoke(() =>
269295
{
270296
_isLoadingData = true;
297+
HasUnsolvedConflicts = hasConflict;
271298
Unstaged = unstaged;
272299
Staged = staged;
273300
SelectedUnstaged = selectedUnstaged;
@@ -281,6 +308,18 @@ public bool SetData(List<Models.Change> changes)
281308
else
282309
SetDetail(null, false);
283310

311+
var inProgress = null as InProgressContext;
312+
if (File.Exists(Path.Combine(_repo.GitDir, "CHERRY_PICK_HEAD")))
313+
inProgress = new CherryPickInProgress(_repo.FullPath);
314+
else if (File.Exists(Path.Combine(_repo.GitDir, "REBASE_HEAD")) && Directory.Exists(Path.Combine(_repo.GitDir, "rebase-merge")))
315+
inProgress = new RebaseInProgress(_repo);
316+
else if (File.Exists(Path.Combine(_repo.GitDir, "REVERT_HEAD")))
317+
inProgress = new RevertInProgress(_repo.FullPath);
318+
else if (File.Exists(Path.Combine(_repo.GitDir, "MERGE_HEAD")))
319+
inProgress = new MergeInProgress(_repo.FullPath);
320+
321+
InProgressContext = inProgress;
322+
284323
// Try to load merge message from MERGE_MSG
285324
if (string.IsNullOrEmpty(_commitMessage))
286325
{
@@ -289,8 +328,6 @@ public bool SetData(List<Models.Change> changes)
289328
CommitMessage = File.ReadAllText(mergeMsgFile);
290329
}
291330
});
292-
293-
return hasConflict;
294331
}
295332

296333
public void OpenAssumeUnchanged()
@@ -403,6 +440,52 @@ public void Discard(List<Models.Change> changes)
403440
}
404441
}
405442

443+
public void ContinueMerge()
444+
{
445+
if (_inProgressContext != null)
446+
{
447+
_repo.SetWatcherEnabled(false);
448+
Task.Run(() =>
449+
{
450+
var succ = _inProgressContext.Continue();
451+
Dispatcher.UIThread.Invoke(() =>
452+
{
453+
if (succ)
454+
CommitMessage = string.Empty;
455+
456+
_repo.SetWatcherEnabled(true);
457+
});
458+
});
459+
}
460+
else
461+
{
462+
_repo.MarkWorkingCopyDirtyManually();
463+
}
464+
}
465+
466+
public void AbortMerge()
467+
{
468+
if (_inProgressContext != null)
469+
{
470+
_repo.SetWatcherEnabled(false);
471+
Task.Run(() =>
472+
{
473+
var succ = _inProgressContext.Abort();
474+
Dispatcher.UIThread.Invoke(() =>
475+
{
476+
if (succ)
477+
CommitMessage = string.Empty;
478+
479+
_repo.SetWatcherEnabled(true);
480+
});
481+
});
482+
}
483+
else
484+
{
485+
_repo.MarkWorkingCopyDirtyManually();
486+
}
487+
}
488+
406489
public void Commit()
407490
{
408491
DoCommit(false, false, false);
@@ -1475,5 +1558,8 @@ private bool IsChanged(List<Models.Change> old, List<Models.Change> cur)
14751558
private int _count = 0;
14761559
private object _detailContext = null;
14771560
private string _commitMessage = string.Empty;
1561+
1562+
private bool _hasUnsolvedConflicts = false;
1563+
private InProgressContext _inProgressContext = null;
14781564
}
14791565
}

src/Views/Repository.axaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@
524524

525525
<!-- Right -->
526526
<Grid Grid.Column="2" RowDefinitions="Auto,Auto,*">
527-
<Grid Grid.Row="0" Height="28" ColumnDefinitions="*,Auto,Auto,Auto" Background="{DynamicResource Brush.Conflict}" IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNotNull}}">
527+
<Grid Grid.Row="0" Height="28" ColumnDefinitions="*,Auto,Auto" Background="{DynamicResource Brush.Conflict}" IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNotNull}}">
528528
<ContentControl Grid.Column="0" Margin="8,0" Content="{Binding InProgressContext}">
529529
<ContentControl.DataTemplates>
530530
<DataTemplate DataType="vm:CherryPickInProgress">
@@ -557,14 +557,6 @@
557557
</Button.IsVisible>
558558
</Button>
559559
<Button Grid.Column="2"
560-
Classes="flat primary"
561-
FontWeight="Regular"
562-
BorderThickness="0"
563-
Content="{DynamicResource Text.Repository.Continue}"
564-
Padding="8,0" Margin="4,0"
565-
Command="{Binding ContinueMerge}"
566-
IsVisible="{Binding !HasUnsolvedConflicts}"/>
567-
<Button Grid.Column="3"
568560
Classes="flat"
569561
FontWeight="Regular"
570562
BorderThickness="0"

src/Views/WorkingCopy.axaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,21 @@
239239
Margin="8,0,0,0"
240240
HorizontalAlignment="Left"
241241
IsChecked="{Binding UseAmend, Mode=TwoWay}"
242+
IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNull}}"
242243
Content="{DynamicResource Text.WorkingCopy.Amend}"/>
243244

244245
<v:LoadingIcon Grid.Column="5" Width="18" Height="18" IsVisible="{Binding IsCommitting}"/>
245246

247+
<Button Grid.Column="6"
248+
Classes="flat primary"
249+
Content="{DynamicResource Text.Repository.Continue}"
250+
Height="28"
251+
Margin="8,0,0,0"
252+
Padding="8,0"
253+
Command="{Binding ContinueMerge}"
254+
IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNotNull}}"
255+
IsEnabled="{Binding !HasUnsolvedConflicts}"/>
256+
246257
<Button Grid.Column="6"
247258
Classes="flat primary"
248259
Content="{DynamicResource Text.WorkingCopy.Commit}"
@@ -251,6 +262,7 @@
251262
Padding="8,0"
252263
Command="{Binding Commit}"
253264
HotKey="{OnPlatform Ctrl+Enter, macOS=⌘+Enter}"
265+
IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNull}}"
254266
ToolTip.Placement="Top"
255267
ToolTip.VerticalOffset="0">
256268
<ToolTip.Tip>

0 commit comments

Comments
 (0)