Skip to content

Commit ca6d41e

Browse files
committed
enhance: try to get stopped at revision info from .git/rebase-merge/head
Signed-off-by: leo <longshuang@msn.cn>
1 parent 773e27f commit ca6d41e

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace SourceGit.Commands
2+
{
3+
public class QueryRevisionByRefName : Command
4+
{
5+
public QueryRevisionByRefName(string repo, string refname)
6+
{
7+
WorkingDirectory = repo;
8+
Context = repo;
9+
Args = $"rev-parse {refname}";
10+
}
11+
12+
public string Result()
13+
{
14+
var rs = ReadToEnd();
15+
if (rs.IsSuccess && !string.IsNullOrEmpty(rs.StdOut))
16+
return rs.StdOut.Trim();
17+
18+
return null;
19+
}
20+
}
21+
}

src/ViewModels/InProgressContexts.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,24 @@ public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase")
107107
{
108108
_gitDir = repo.GitDir;
109109

110+
HeadName = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "head-name")).Trim();
111+
if (HeadName.StartsWith("refs/heads/"))
112+
HeadName = HeadName.Substring(11);
113+
else if (HeadName.StartsWith("refs/tags/"))
114+
HeadName = HeadName.Substring(10);
115+
110116
var stoppedSHAPath = Path.Combine(repo.GitDir, "rebase-merge", "stopped-sha");
117+
var stoppedSHA = string.Empty;
111118
if (File.Exists(stoppedSHAPath))
112-
{
113-
var stoppedSHA = File.ReadAllText(stoppedSHAPath).Trim();
119+
stoppedSHA = File.ReadAllText(stoppedSHAPath).Trim();
120+
else
121+
stoppedSHA = new Commands.QueryRevisionByRefName(repo.FullPath, HeadName).Result();
122+
123+
if (!string.IsNullOrEmpty(stoppedSHA))
114124
StoppedAt = new Commands.QuerySingleCommit(repo.FullPath, stoppedSHA).Result() ?? new Models.Commit() { SHA = stoppedSHA };
115-
}
116125

117126
var ontoSHA = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "onto")).Trim();
118127
Onto = new Commands.QuerySingleCommit(repo.FullPath, ontoSHA).Result() ?? new Models.Commit() { SHA = ontoSHA };
119-
120-
HeadName = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "head-name")).Trim();
121-
if (HeadName.StartsWith("refs/heads/"))
122-
HeadName = HeadName.Substring(11);
123128
}
124129

125130
public override bool Continue()

0 commit comments

Comments
 (0)