mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 04:34:59 +00:00
feature: add a button to see which branches and tags that contains selected commit (#388)
This commit is contained in:
parent
fcc8a41ad1
commit
6ab0900b20
14 changed files with 171 additions and 18 deletions
37
src/Commands/QueryRefsContainsCommit.cs
Normal file
37
src/Commands/QueryRefsContainsCommit.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SourceGit.Commands
|
||||
{
|
||||
public class QueryRefsContainsCommit : Command
|
||||
{
|
||||
public QueryRefsContainsCommit(string repo, string commit)
|
||||
{
|
||||
WorkingDirectory = repo;
|
||||
RaiseError = false;
|
||||
Args = $"for-each-ref --format=\"%(refname)\" --contains {commit}";
|
||||
}
|
||||
|
||||
public List<Models.Decorator> Result()
|
||||
{
|
||||
var rs = new List<Models.Decorator>();
|
||||
|
||||
var output = ReadToEnd();
|
||||
if (!output.IsSuccess)
|
||||
return rs;
|
||||
|
||||
var lines = output.StdOut.Split('\n');
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line.StartsWith("refs/heads/", StringComparison.Ordinal))
|
||||
rs.Add(new() { Name = line.Substring("refs/heads/".Length), Type = Models.DecoratorType.LocalBranchHead });
|
||||
else if (line.StartsWith("refs/remotes/", StringComparison.Ordinal))
|
||||
rs.Add(new() { Name = line.Substring("refs/remotes/".Length), Type = Models.DecoratorType.RemoteBranchHead });
|
||||
else if (line.StartsWith("refs/tags/", StringComparison.Ordinal))
|
||||
rs.Add(new() { Name = line.Substring("refs/tags/".Length), Type = Models.DecoratorType.Tag });
|
||||
}
|
||||
|
||||
return rs;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue