Skip to content

Instantly share code, notes, and snippets.

@KosarevDmitry
Created August 15, 2025 15:03
Show Gist options
  • Select an option

  • Save KosarevDmitry/f1da0ac48c83ecc6715899e54ab66a03 to your computer and use it in GitHub Desktop.

Select an option

Save KosarevDmitry/f1da0ac48c83ecc6715899e54ab66a03 to your computer and use it in GitHub Desktop.

Revisions

  1. KosarevDmitry created this gist Aug 15, 2025.
    66 changes: 66 additions & 0 deletions getGits.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    #nullable enable

    //dotnet-script getGits.cs "D:\src" "D:\temp\gits.txt"

    string src ="";
    string dest="";
    if (Args.Count() > 0)
    {
    src = Args[0].Trim(new char[] { '"','\'', ' '}); //@"D:\src"
    Console.WriteLine(src);
    dest = Args[1].Trim(new char[] { '"','\'', ' '}); //@"D:\temp\gits.txt"
    Console.WriteLine(dest);
    }

    else
    {
    Console.WriteLine("Args are not specified.");
    return;
    }

    List<string> list = new();

    IEnumerable<string> GitDir(string dir)
    {
    Console.WriteLine("root dir: " + dir);
    IEnumerable<string>? dirs = default;
    dirs = Directory.EnumerateDirectories(dir, ".git", SearchOption.TopDirectoryOnly).ToArray();
    if (dirs.Any())
    {
    list.AddRange(dirs);
    }
    else
    {
    dirs = Directory.EnumerateDirectories(dir, "*", SearchOption.TopDirectoryOnly);
    foreach (var d in dirs)
    {
    GitDir(d);
    }
    }
    return list;
    }

    void GetLinks(IEnumerable<string> dirs)
    {
    List<string> list = new();

    foreach (var dir in dirs)
    {
    var files = Directory.EnumerateFiles(dir, "config", SearchOption.TopDirectoryOnly);
    foreach (var f in files)
    {
    var url = File.ReadAllLines(f).FirstOrDefault(x => x.TrimStart().StartsWith("url"));
    if (url is not null)
    {
    url = url.Split("=")?[1].Trim();
    list.Add($"{dir} ; {url}");
    }
    }
    }

    File.WriteAllLines(dest, list);
    }

    var dirs = GitDir(src);
    GetLinks(dirs);