Skip to content

Commit 2dd9cab

Browse files
committed
enhance: try to use friendly name instead of commit hash
1 parent 3b5d873 commit 2dd9cab

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

src/ViewModels/InProgressContexts.cs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ public virtual bool Continue()
6262
Args = $"{Cmd} --continue",
6363
}.Exec();
6464
}
65+
66+
protected string GetFriendlyNameOfCommit(Models.Commit commit)
67+
{
68+
var branchDecorator = commit.Decorators.Find(x => x.Type == Models.DecoratorType.LocalBranchHead || x.Type == Models.DecoratorType.RemoteBranchHead);
69+
if (branchDecorator != null)
70+
return branchDecorator.Name;
71+
72+
var tagDecorator = commit.Decorators.Find(x => x.Type == Models.DecoratorType.Tag);
73+
if (tagDecorator != null)
74+
return tagDecorator.Name;
75+
76+
return commit.SHA.Substring(0, 10);
77+
}
6578
}
6679

6780
public class CherryPickInProgress : InProgressContext
@@ -72,6 +85,11 @@ public Models.Commit Head
7285
private set;
7386
}
7487

88+
public string HeadName
89+
{
90+
get => GetFriendlyNameOfCommit(Head);
91+
}
92+
7593
public CherryPickInProgress(Repository repo) : base(repo.FullPath, "cherry-pick", true)
7694
{
7795
var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "CHERRY_PICK_HEAD")).Trim();
@@ -87,18 +105,32 @@ public string HeadName
87105
private set;
88106
}
89107

108+
public string BaseName
109+
{
110+
get => GetFriendlyNameOfCommit(Onto);
111+
}
112+
90113
public Models.Commit StoppedAt
91114
{
92115
get;
93116
private set;
94117
}
95118

119+
public Models.Commit Onto
120+
{
121+
get;
122+
private set;
123+
}
124+
96125
public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase", true)
97126
{
98127
_gitDir = repo.GitDir;
99128

100129
var stoppedSHA = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "stopped-sha")).Trim();
101-
StoppedAt = new Commands.QuerySingleCommit(repo.FullPath, stoppedSHA).Result();
130+
StoppedAt = new Commands.QuerySingleCommit(repo.FullPath, stoppedSHA).Result() ?? new Models.Commit() { SHA = stoppedSHA };
131+
132+
var ontoSHA = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "onto")).Trim();
133+
Onto = new Commands.QuerySingleCommit(repo.FullPath, ontoSHA).Result() ?? new Models.Commit() { SHA = ontoSHA };
102134

103135
HeadName = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "head-name")).Trim();
104136
if (HeadName.StartsWith("refs/heads/"))
@@ -150,41 +182,23 @@ public string Current
150182
private set;
151183
}
152184

153-
public string SourceName
185+
public Models.Commit Source
154186
{
155187
get;
156188
private set;
157189
}
158190

159-
public Models.Commit Source
191+
public string SourceName
160192
{
161-
get;
162-
private set;
193+
get => GetFriendlyNameOfCommit(Source);
163194
}
164195

165196
public MergeInProgress(Repository repo) : base(repo.FullPath, "merge", false)
166197
{
167198
Current = Commands.Branch.ShowCurrent(repo.FullPath);
168199

169200
var sourceSHA = File.ReadAllText(Path.Combine(repo.GitDir, "MERGE_HEAD")).Trim();
170-
Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).Result();
171-
if (Source == null)
172-
return;
173-
174-
var branchDecorator = Source.Decorators.Find(x => x.Type == Models.DecoratorType.LocalBranchHead || x.Type == Models.DecoratorType.RemoteBranchHead);
175-
if (branchDecorator != null)
176-
{
177-
SourceName = branchDecorator.Name;
178-
return;
179-
}
180-
181-
var tagDecorator = Source.Decorators.Find(x => x.Type == Models.DecoratorType.Tag);
182-
if (tagDecorator != null)
183-
{
184-
SourceName = tagDecorator.Name;
185-
}
186-
187-
SourceName = Source.SHA.Substring(0, 10);
201+
Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).Result() ?? new Models.Commit() { SHA = sourceSHA };
188202
}
189203
}
190204
}

src/ViewModels/WorkingCopy.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,11 @@ public ContextMenu CreateContextMenuForUnstagedChanges()
572572
if (_inProgressContext is RebaseInProgress rebase)
573573
{
574574
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.HeadName);
575-
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.StoppedAt.SHA.Substring(0, 10));
575+
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.BaseName);
576576
}
577577
else if (_inProgressContext is CherryPickInProgress cherryPick)
578578
{
579-
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", cherryPick.Head.SHA.Substring(0, 10));
579+
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", cherryPick.HeadName);
580580
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
581581
}
582582
else if (_inProgressContext is MergeInProgress merge)
@@ -912,11 +912,11 @@ public ContextMenu CreateContextMenuForUnstagedChanges()
912912
if (_inProgressContext is RebaseInProgress rebase)
913913
{
914914
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.HeadName);
915-
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.StoppedAt.SHA.Substring(0, 10));
915+
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", rebase.BaseName);
916916
}
917917
else if (_inProgressContext is CherryPickInProgress cherryPick)
918918
{
919-
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", cherryPick.Head.SHA.Substring(0, 10));
919+
useTheirs.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", cherryPick.HeadName);
920920
useMine.Header = new Views.NameHighlightedTextBlock("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
921921
}
922922
else if (_inProgressContext is MergeInProgress merge)

0 commit comments

Comments
 (0)