Skip to content
Closed
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
98 changes: 60 additions & 38 deletions src/ViewModels/Histories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public void Dispose()

public Models.BisectState UpdateBisectInfo()
{
if (_repo == null)
{
Bisect = null;
return Models.BisectState.None;
}

var test = Path.Combine(_repo.GitDir, "BISECT_START");
if (!File.Exists(test))
{
Expand Down Expand Up @@ -182,6 +188,9 @@ public void NavigateTo(string commitSHA)
return;
}

if (_repo == null)
return;

Task.Run(async () =>
{
var c = await new Commands.QuerySingleCommit(_repo.FullPath, commitSHA)
Expand All @@ -190,6 +199,9 @@ public void NavigateTo(string commitSHA)

Dispatcher.UIThread.Post(() =>
{
if (_repo == null)
return;

_ignoreSelectionChange = true;
SelectedCommit = null;

Expand Down Expand Up @@ -263,7 +275,7 @@ public void Select(IList commits)

public async Task<bool> CheckoutBranchByDecoratorAsync(Models.Decorator decorator)
{
if (decorator == null)
if (decorator == null || _repo == null)
return false;

if (decorator.Type == Models.DecoratorType.CurrentBranchHead ||
Expand Down Expand Up @@ -310,7 +322,7 @@ public async Task<bool> CheckoutBranchByDecoratorAsync(Models.Decorator decorato

public async Task CheckoutBranchByCommitAsync(Models.Commit commit)
{
if (commit.IsCurrentHead)
if (commit.IsCurrentHead || _repo == null)
return;

Models.Branch firstRemoteBranch = null;
Expand Down Expand Up @@ -355,61 +367,64 @@ public async Task CheckoutBranchByCommitAsync(Models.Commit commit)

public async Task CherryPickAsync(Models.Commit commit)
{
if (_repo.CanCreatePopup())
if (_repo == null || !_repo.CanCreatePopup())
return;

if (commit.Parents.Count <= 1)
{
if (commit.Parents.Count <= 1)
{
_repo.ShowPopup(new CherryPick(_repo, [commit]));
}
else
_repo.ShowPopup(new CherryPick(_repo, [commit]));
}
else
{
var parents = new List<Models.Commit>();
foreach (var sha in commit.Parents)
{
var parents = new List<Models.Commit>();
foreach (var sha in commit.Parents)
{
var parent = _commits.Find(x => x.SHA.Equals(sha, StringComparison.Ordinal));
if (parent == null)
parent = await new Commands.QuerySingleCommit(_repo.FullPath, sha).GetResultAsync();

if (parent != null)
parents.Add(parent);
}
var parent = _commits.Find(x => x.SHA.Equals(sha, StringComparison.Ordinal));
if (parent == null)
parent = await new Commands.QuerySingleCommit(_repo.FullPath, sha).GetResultAsync();

_repo.ShowPopup(new CherryPick(_repo, commit, parents));
if (parent != null)
parents.Add(parent);
}

_repo.ShowPopup(new CherryPick(_repo, commit, parents));
}
}

public async Task RewordHeadAsync(Models.Commit head)
{
if (_repo.CanCreatePopup())
{
var message = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).GetResultAsync();
_repo.ShowPopup(new Reword(_repo, head, message));
}
if (_repo == null || !_repo.CanCreatePopup())
return;

var message = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).GetResultAsync();
_repo.ShowPopup(new Reword(_repo, head, message));
}

public async Task SquashOrFixupHeadAsync(Models.Commit head, bool fixup)
{
if (head.Parents.Count == 1)
{
var parent = await new Commands.QuerySingleCommit(_repo.FullPath, head.Parents[0]).GetResultAsync();
if (parent == null)
return;
if (_repo == null || head.Parents.Count != 1)
return;

string message = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.Parents[0]).GetResultAsync();
if (!fixup)
{
var headMessage = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).GetResultAsync();
message = $"{message}\n\n{headMessage}";
}
var parent = await new Commands.QuerySingleCommit(_repo.FullPath, head.Parents[0]).GetResultAsync();
if (parent == null)
return;

if (_repo.CanCreatePopup())
_repo.ShowPopup(new SquashOrFixupHead(_repo, parent, message, fixup));
string message = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.Parents[0]).GetResultAsync();
if (!fixup)
{
var headMessage = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).GetResultAsync();
message = $"{message}\n\n{headMessage}";
}

if (_repo.CanCreatePopup())
_repo.ShowPopup(new SquashOrFixupHead(_repo, parent, message, fixup));
}

public async Task DropHeadAsync(Models.Commit head)
{
if (_repo == null)
return;

var parent = _commits.Find(x => x.SHA.Equals(head.Parents[0]));
if (parent == null)
parent = await new Commands.QuerySingleCommit(_repo.FullPath, head.Parents[0]).GetResultAsync();
Expand All @@ -420,13 +435,19 @@ public async Task DropHeadAsync(Models.Commit head)

public async Task<string> GetCommitFullMessageAsync(Models.Commit commit)
{
if (_repo == null)
return string.Empty;

return await new Commands.QueryCommitFullMessage(_repo.FullPath, commit.SHA)
.GetResultAsync()
.ConfigureAwait(false);
}

public async Task<Models.Commit> CompareWithHeadAsync(Models.Commit commit)
{
if (_repo == null)
return null;

var head = _commits.Find(x => x.IsCurrentHead);
if (head == null)
{
Expand All @@ -443,7 +464,8 @@ public async Task<string> GetCommitFullMessageAsync(Models.Commit commit)

public void CompareWithWorktree(Models.Commit commit)
{
DetailContext = new RevisionCompare(_repo, commit, null);
if (_repo != null)
DetailContext = new RevisionCompare(_repo, commit, null);
}

private Repository _repo = null;
Expand Down