Created
May 19, 2017 14:23
-
-
Save jorupp/fdaf773d8a0573fc894bdf4d8370e27c to your computer and use it in GitHub Desktop.
Find all git repos under a directory and check what branches they have that aren't merged into origin/master
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string target = ".git"; | |
string[] ignored = new [] { "node_modules", "bower_components" }; | |
void Main() | |
{ | |
var start = @"c:\projects"; | |
var maxDepth = 4; | |
var dirs = Scan(start, maxDepth).ToList(); | |
var results = dirs.AsParallel().Select(i => new { dir = i, data = GitStatus(i) }).ToDictionary(i => i.dir, i => i.data); | |
results.Dump(); | |
} | |
string GitStatus(string directory) { | |
var proc = Process.Start(new ProcessStartInfo() { | |
RedirectStandardOutput = true, | |
WorkingDirectory = directory, | |
FileName = @"C:\Program Files\Git\cmd\git.exe", | |
Arguments = "branch --no-merge origin/master", | |
UseShellExecute = false, | |
}); | |
var data = ""; | |
proc.OutputDataReceived += (s, e) => { | |
data += e.Data; | |
}; | |
proc.BeginOutputReadLine(); | |
proc.WaitForExit(); | |
return data; | |
} | |
IEnumerable<string> Scan(string start, int depth) { | |
string[] dirs = new string[0]; | |
try { | |
dirs = Directory.GetDirectories(start); | |
} catch { | |
} | |
foreach(var dir in dirs) { | |
var name = Path.GetFileName(dir); | |
if(name == target) { | |
yield return start; | |
} | |
if(ignored.Contains(name)) { | |
continue; | |
} | |
if(depth > 1) { | |
foreach(var x in Scan(dir, depth-1)) { | |
yield return x; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The .Dump() is for LinqPad - if you use this elsewhere, just replace that with some calls to write out to console or wherever.