mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-25 21:07:20 -08:00
enhance: try to use friendly name instead of commit hash
This commit is contained in:
parent
3b5d87391d
commit
2dd9cab695
2 changed files with 41 additions and 27 deletions
|
@ -62,6 +62,19 @@ namespace SourceGit.ViewModels
|
|||
Args = $"{Cmd} --continue",
|
||||
}.Exec();
|
||||
}
|
||||
|
||||
protected string GetFriendlyNameOfCommit(Models.Commit commit)
|
||||
{
|
||||
var branchDecorator = commit.Decorators.Find(x => x.Type == Models.DecoratorType.LocalBranchHead || x.Type == Models.DecoratorType.RemoteBranchHead);
|
||||
if (branchDecorator != null)
|
||||
return branchDecorator.Name;
|
||||
|
||||
var tagDecorator = commit.Decorators.Find(x => x.Type == Models.DecoratorType.Tag);
|
||||
if (tagDecorator != null)
|
||||
return tagDecorator.Name;
|
||||
|
||||
return commit.SHA.Substring(0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
public class CherryPickInProgress : InProgressContext
|
||||
|
@ -72,6 +85,11 @@ namespace SourceGit.ViewModels
|
|||
private set;
|
||||
}
|
||||
|
||||
public string HeadName
|
||||
{
|
||||
get => GetFriendlyNameOfCommit(Head);
|
||||
}
|
||||
|
||||
public CherryPickInProgress(Repository repo) : base(repo.FullPath, "cherry-pick", true)
|
||||
{
|
||||
var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "CHERRY_PICK_HEAD")).Trim();
|
||||
|
@ -87,18 +105,32 @@ namespace SourceGit.ViewModels
|
|||
private set;
|
||||
}
|
||||
|
||||
public string BaseName
|
||||
{
|
||||
get => GetFriendlyNameOfCommit(Onto);
|
||||
}
|
||||
|
||||
public Models.Commit StoppedAt
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public Models.Commit Onto
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase", true)
|
||||
{
|
||||
_gitDir = repo.GitDir;
|
||||
|
||||
var stoppedSHA = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "stopped-sha")).Trim();
|
||||
StoppedAt = new Commands.QuerySingleCommit(repo.FullPath, stoppedSHA).Result();
|
||||
StoppedAt = new Commands.QuerySingleCommit(repo.FullPath, stoppedSHA).Result() ?? new Models.Commit() { SHA = stoppedSHA };
|
||||
|
||||
var ontoSHA = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "onto")).Trim();
|
||||
Onto = new Commands.QuerySingleCommit(repo.FullPath, ontoSHA).Result() ?? new Models.Commit() { SHA = ontoSHA };
|
||||
|
||||
HeadName = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "head-name")).Trim();
|
||||
if (HeadName.StartsWith("refs/heads/"))
|
||||
|
@ -150,16 +182,15 @@ namespace SourceGit.ViewModels
|
|||
private set;
|
||||
}
|
||||
|
||||
public string SourceName
|
||||
public Models.Commit Source
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public Models.Commit Source
|
||||
public string SourceName
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
get => GetFriendlyNameOfCommit(Source);
|
||||
}
|
||||
|
||||
public MergeInProgress(Repository repo) : base(repo.FullPath, "merge", false)
|
||||
|
@ -167,24 +198,7 @@ namespace SourceGit.ViewModels
|
|||
Current = Commands.Branch.ShowCurrent(repo.FullPath);
|
||||
|
||||
var sourceSHA = File.ReadAllText(Path.Combine(repo.GitDir, "MERGE_HEAD")).Trim();
|
||||
Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).Result();
|
||||
if (Source == null)
|
||||
return;
|
||||
|
||||
var branchDecorator = Source.Decorators.Find(x => x.Type == Models.DecoratorType.LocalBranchHead || x.Type == Models.DecoratorType.RemoteBranchHead);
|
||||
if (branchDecorator != null)
|
||||
{
|
||||
SourceName = branchDecorator.Name;
|
||||
return;
|
||||
}
|
||||
|
||||
var tagDecorator = Source.Decorators.Find(x => x.Type == Models.DecoratorType.Tag);
|
||||
if (tagDecorator != null)
|
||||
{
|
||||
SourceName = tagDecorator.Name;
|
||||
}
|
||||
|
||||
SourceName = Source.SHA.Substring(0, 10);
|
||||
Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).Result() ?? new Models.Commit() { SHA = sourceSHA };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -572,11 +572,11 @@ namespace SourceGit.ViewModels
|
|||
if (_inProgressContext is RebaseInProgress rebase)
|
||||
{
|
||||
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.HeadName);
|
||||
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.StoppedAt.SHA.Substring(0, 10));
|
||||
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.BaseName);
|
||||
}
|
||||
else if (_inProgressContext is CherryPickInProgress cherryPick)
|
||||
{
|
||||
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", cherryPick.Head.SHA.Substring(0, 10));
|
||||
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", cherryPick.HeadName);
|
||||
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
}
|
||||
else if (_inProgressContext is MergeInProgress merge)
|
||||
|
@ -912,11 +912,11 @@ namespace SourceGit.ViewModels
|
|||
if (_inProgressContext is RebaseInProgress rebase)
|
||||
{
|
||||
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.HeadName);
|
||||
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.StoppedAt.SHA.Substring(0, 10));
|
||||
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.BaseName);
|
||||
}
|
||||
else if (_inProgressContext is CherryPickInProgress cherryPick)
|
||||
{
|
||||
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", cherryPick.Head.SHA.Substring(0, 10));
|
||||
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", cherryPick.HeadName);
|
||||
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
}
|
||||
else if (_inProgressContext is MergeInProgress merge)
|
||||
|
|
Loading…
Reference in a new issue