Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,15 +565,22 @@ public void Close()
SelectedView = null; // Do NOT modify. Used to remove exists widgets for GC.Collect
Logs.Clear();

if (!_isWorktree)
if (!_isWorktree && Directory.Exists(_gitCommonDir))
{
if (_workingCopy.InProgressContext != null && !string.IsNullOrEmpty(_workingCopy.CommitMessage))
File.WriteAllText(Path.Combine(GitDir, "MERGE_MSG"), _workingCopy.CommitMessage);
else
_settings.LastCommitMessage = _workingCopy.CommitMessage;
try
{
if (_workingCopy.InProgressContext != null && !string.IsNullOrEmpty(_workingCopy.CommitMessage))
File.WriteAllText(Path.Combine(GitDir, "MERGE_MSG"), _workingCopy.CommitMessage);
else
_settings.LastCommitMessage = _workingCopy.CommitMessage;

using var stream = File.Create(Path.Combine(_gitCommonDir, "sourcegit.settings"));
JsonSerializer.Serialize(stream, _settings, JsonCodeGen.Default.RepositorySettings);
using var stream = File.Create(Path.Combine(_gitCommonDir, "sourcegit.settings"));
JsonSerializer.Serialize(stream, _settings, JsonCodeGen.Default.RepositorySettings);
}
catch (Exception)
{
// Ignore
}
}

if (_cancellationRefreshBranches is { IsCancellationRequested: false })
Expand Down
15 changes: 11 additions & 4 deletions src/Views/BranchCompare.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
try
{
var saveTo = storageFile.Path.LocalPath;
await vm.SaveChangesAsPatchAsync(selected, saveTo);
var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
{
var saveTo = storageFile.Path.LocalPath;
await vm.SaveChangesAsPatchAsync(selected, saveTo);
}
}
catch (Exception exception)
{
App.RaiseException(repo, $"Failed to save as patch: {exception.Message}");
}

e.Handled = true;
Expand Down
45 changes: 33 additions & 12 deletions src/Views/CommitDetail.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@ public ContextMenu CreateChangeContextMenuByFolder(ViewModels.ChangeTreeNode nod
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
try
{
var saveTo = storageFile.Path.LocalPath;
await vm.SaveChangesAsPatchAsync(changes, saveTo);
var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
{
var saveTo = storageFile.Path.LocalPath;
await vm.SaveChangesAsPatchAsync(changes, saveTo);
}
}
catch (Exception exception)
{
App.RaiseException(repo.FullPath, $"Failed to save as patch: {exception.Message}");
}

e.Handled = true;
Expand Down Expand Up @@ -117,11 +124,18 @@ public ContextMenu CreateMultipleChangesContextMenu(List<Models.Change> changes)
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
try
{
var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
{
var saveTo = storageFile.Path.LocalPath;
await vm.SaveChangesAsPatchAsync(changes, saveTo);
}
}
catch (Exception exception)
{
var saveTo = storageFile.Path.LocalPath;
await vm.SaveChangesAsPatchAsync(changes, saveTo);
App.RaiseException(repo.FullPath, $"Failed to save as patch: {exception.Message}");
}

e.Handled = true;
Expand Down Expand Up @@ -259,11 +273,18 @@ public ContextMenu CreateChangeContextMenu(Models.Change change)
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
try
{
var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
{
var saveTo = storageFile.Path.LocalPath;
await vm.SaveChangesAsPatchAsync([change], saveTo);
}
}
catch (Exception exception)
{
var saveTo = storageFile.Path.LocalPath;
await vm.SaveChangesAsPatchAsync([change], saveTo);
App.RaiseException(repo.FullPath, $"Failed to save as patch: {exception.Message}");
}

e.Handled = true;
Expand Down
16 changes: 12 additions & 4 deletions src/Views/FileHistories.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ private async void OnSaveAsPatch(object sender, RoutedEventArgs e)
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await StorageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await compare.SaveAsPatch(storageFile.Path.LocalPath);
try
{
var storageFile = await StorageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await compare.SaveAsPatch(storageFile.Path.LocalPath);

NotifyDonePanel.IsVisible = true;
}
catch (Exception exception)
{
App.RaiseException(string.Empty, $"Failed to save as patch: {exception.Message}");
}

NotifyDonePanel.IsVisible = true;
e.Handled = true;
}
}
Expand Down
28 changes: 21 additions & 7 deletions src/Views/RevisionCompare.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
try
{
var saveTo = storageFile.Path.LocalPath;
await vm.SaveChangesAsPatchAsync(selected, saveTo);
var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
{
var saveTo = storageFile.Path.LocalPath;
await vm.SaveChangesAsPatchAsync(selected, saveTo);
}
}
catch (Exception exception)
{
App.RaiseException(string.Empty, $"Failed to save as patch: {exception.Message}");
}

e.Handled = true;
Expand Down Expand Up @@ -166,9 +173,16 @@ private async void OnSaveAsPatch(object sender, RoutedEventArgs e)
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await storage.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveChangesAsPatchAsync(null, storageFile.Path.LocalPath);
try
{
var storageFile = await storage.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveChangesAsPatchAsync(null, storageFile.Path.LocalPath);
}
catch (Exception exception)
{
App.RaiseException(string.Empty, $"Failed to save as patch: {exception.Message}");
}

e.Handled = true;
}
Expand Down
13 changes: 10 additions & 3 deletions src/Views/StashesPage.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ private void OnStashContextRequested(object sender, ContextRequestedEventArgs e)
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveStashAsPatchAsync(stash, storageFile.Path.LocalPath);
try
{
var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveStashAsPatchAsync(stash, storageFile.Path.LocalPath);
}
catch (Exception exception)
{
App.RaiseException(string.Empty, $"Failed to save as patch: {exception.Message}");
}

ev.Handled = true;
};
Expand Down
52 changes: 40 additions & 12 deletions src/Views/WorkingCopy.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,16 @@ private ContextMenu CreateContextMenuForUnstagedChanges(ViewModels.WorkingCopy v
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveChangesToPatchAsync(selectedUnstaged, true, storageFile.Path.LocalPath);
try
{
var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveChangesToPatchAsync(selectedUnstaged, true, storageFile.Path.LocalPath);
}
catch (Exception exception)
{
App.RaiseException(repo.FullPath, $"Failed to save as patch: {exception.Message}");
}

e.Handled = true;
};
Expand Down Expand Up @@ -788,9 +795,16 @@ private ContextMenu CreateContextMenuForUnstagedChanges(ViewModels.WorkingCopy v
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveChangesToPatchAsync(selectedUnstaged, true, storageFile.Path.LocalPath);
try
{
var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveChangesToPatchAsync(selectedUnstaged, true, storageFile.Path.LocalPath);
}
catch (Exception exception)
{
App.RaiseException(repo.FullPath, $"Failed to save as patch: {exception.Message}");
}

e.Handled = true;
};
Expand Down Expand Up @@ -975,9 +989,16 @@ public ContextMenu CreateContextMenuForStagedChanges(ViewModels.WorkingCopy vm,
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveChangesToPatchAsync(selectedStaged, false, storageFile.Path.LocalPath);
try
{
var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveChangesToPatchAsync(selectedStaged, false, storageFile.Path.LocalPath);
}
catch (Exception exception)
{
App.RaiseException(repo.FullPath, $"Failed to save as patch: {exception.Message}");
}

e.Handled = true;
};
Expand Down Expand Up @@ -1183,9 +1204,16 @@ public ContextMenu CreateContextMenuForStagedChanges(ViewModels.WorkingCopy vm,
options.DefaultExtension = ".patch";
options.FileTypeChoices = [new FilePickerFileType("Patch File") { Patterns = ["*.patch"] }];

var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveChangesToPatchAsync(selectedStaged, false, storageFile.Path.LocalPath);
try
{
var storageFile = await storageProvider.SaveFilePickerAsync(options);
if (storageFile != null)
await vm.SaveChangesToPatchAsync(selectedStaged, false, storageFile.Path.LocalPath);
}
catch (Exception exception)
{
App.RaiseException(repo.FullPath, $"Failed to save as patch: {exception.Message}");
}

e.Handled = true;
};
Expand Down