public IEnumerable<string> GetAllBranchesWhichContainGivenCommit(string sha1, bool getLocal, bool getRemote)
{
string args = "--contains " + sha1;
if (getRemote && getLocal)
args = "-a " + args;
else if (getRemote)
args = "-r " + args;
else if (!getLocal)
return new string[] { };
string info = RunGitCmd("branch " + args);
if (info.Trim().StartsWith("fatal") || info.Trim().StartsWith("error:"))
return new List<string>();
string[] result = info.Split(new[] { '\r', '\n', '*' }, StringSplitOptions.RemoveEmptyEntries);
// Remove symlink targets as in "origin/HEAD -> origin/master"
for (int i = 0; i < result.Length; i++)
{
string item = result[i].Trim();
int idx;
if (getRemote && ((idx = item.IndexOf(" ->")) >= 0))
{
item = item.Substring(0, idx);
}
result[i] = item;
}
return result;
}