Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup GetAllBranchesWhichContainGivenCommit #10836

Merged
merged 2 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions GitCommands/Git/GitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3141,12 +3141,18 @@ public IReadOnlyList<string> GetAllBranchesWhichContainGivenCommit(ObjectId obje
return Array.Empty<string>();
}

var result = exec.StandardOutput.Split(new[] { '\r', '\n', '*', '+' }, StringSplitOptions.RemoveEmptyEntries);
string[] result = exec.StandardOutput.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a comment explaining what information git may provide and what transformation we do.
IIRC, * denotes the current branch, but I can't remember what + may be used for...

Copy link
Member

@gerhardol gerhardol Mar 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RussKie that would be a link to Git documentation
Documentation is poor, does not statate that the line starts with two chars before branch
So something should be added below (this line is fine).

https://git-scm.com/docs/git-branch#_description

+ is used for linked work trees, similar to *


// Remove symlink targets as in "origin/HEAD -> origin/master"
for (var i = 0; i < result.Length; i++)
for (int i = 0; i < result.Length; i++)
{
var item = result[i].Trim();
string item = result[i];

// remove prepended branch state "* ", "+ ", " "
if (item.Length >= 2 && item[1] == ' ' && item[0] is (' ' or '*' or '+'))
{
item = item[2..];
}

if (getRemote)
{
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/GitCommands.Tests/GitModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ public void ParseRefs()
[TestCase("branch -a --contains",
true,
true,
" aaa\n* current\n+ feature/worktree\n feature/zzz_another\n remotes/origin/master\n remotes/origin/current\n remotes/upstream/master\n",
new string[] { "aaa", "current", "feature/worktree", "feature/zzz_another", "remotes/origin/master", "remotes/origin/current", "remotes/upstream/master" })]
" aaa\n* current\n+ feature/worktree\n feature/zzz_another\n remotes/origin/master\n remotes/origin/current\n remotes/upstream/master\n a+b",
new string[] { "aaa", "current", "feature/worktree", "feature/zzz_another", "remotes/origin/master", "remotes/origin/current", "remotes/upstream/master", "a+b" })]
[TestCase("branch --contains",
true,
false,
Expand Down