示例#1
0
        public static async ValueTask <string[]> HelpUsage(this GitPlumbingClient c, string name)
        {
            if (!typeof(GitPlumbing).GetMethods().Any(x => x.GetCustomAttribute <GitCommandAttribute>()?.Name == name) &&
                !typeof(GitPorcelain).GetMethods().Any(x => x.GetCustomAttribute <GitCommandAttribute>()?.Name == name))
            {
                throw new ArgumentOutOfRangeException();
            }

            List <string> results = new List <string>();
            bool          gotOne  = false;

            await foreach (var line in c.Repository.WalkPlumbingCommand(name, new[] { "-h" }, expectedResults: new[] { 129, 0 }))
            {
                results.Add(line);
                if (!gotOne && !string.IsNullOrWhiteSpace(line))
                {
                    gotOne = true;
                }
            }

            if (gotOne)
            {
                return(results.ToArray());
            }

            var(_, _, stderr) = await c.Repository.RunGitCommandErrAsync(name, new[] { "-h" }, expectedResults : new[] { 129 });

            return(stderr.Split('\n').Select(x => x.TrimEnd()).ToArray());
        }
示例#2
0
        public static async ValueTask CommitTree(this GitPlumbingClient c, GitCommitTreeArgs options)
        {
            options.Verify();
            //var (_, txt) = await c.Repository.RunPlumbingCommandOut("help", new[] { "-i", a.Command! ?? a.Guide! });

            await c.ThrowNotImplemented();
        }
示例#3
0
        public static async ValueTask <string> ListFiles(this GitPlumbingClient c, GitListFilesArgs options)
        {
            options.Verify();
            var(_, txt) = await c.Repository.RunGitCommandOutAsync("ls-files", new string[] { });

            return(txt);
        }
示例#4
0
        public static async ValueTask PackReferences(this GitPlumbingClient c, GitPackReferencesArgs options)
        {
            options.Verify();

            await c.Repository.RunGitCommandAsync("pack-refs", new [] {
                options.All ? "--all" : "",
                options.NoPrune ? "--no-prune" : ""
            }.Where(x => !string.IsNullOrEmpty(x)).ToArray());
        }
示例#5
0
        public static async ValueTask Repack(this GitPlumbingClient c, GitRepackArgs?options = null)
        {
            var args = new List <string>();


            options?.Verify();
            options ??= new();

            if (options.SinglePack)
            {
                if (options.UnreachableAsLoose)
                {
                    args.Add("-A");
                }
                else
                {
                    args.Add("-a");
                }
            }
            if (options.RemoveUnused)
            {
                args.Add("-d");
            }
            if (options.Quiet)
            {
                args.Add("-q");
            }
            if (options.WriteBitmap)
            {
                args.Add("--write-bitmap-index");
            }
            if (options.WriteMultiPack)
            {
                args.Add("--write-midx");
            }
            if (options.GeometricFactor.HasValue)
            {
                args.Add($"--geometric={options.GeometricFactor.Value}");
            }

            if (options.Window.HasValue)
            {
                args.Add($"--window={options.Window.Value}");
            }
            if (options.Depth.HasValue)
            {
                args.Add($"--depth={options.Depth.Value}");
            }
            if (options.Threads.HasValue)
            {
                args.Add($"--threads={options.Threads.Value}");
            }

            await c.Repository.RunGitCommandAsync("repack", args);

            Porcelain.GitPorcelain.RemoveReadOnlyIfNecessary(c.Repository);
        }
示例#6
0
        public static async ValueTask <string> ConsistencyCheck(this GitPlumbingClient c, GitConsistencyCheckArgs?options = null)
        {
            options ??= new();
            options.Verify();
            var args = new List <string>();

            if (options.Full)
            {
                args.Add("--full");
            }

            var(_, txt) = await c.Repository.RunGitCommandOutAsync("fsck", args);

            return(txt.Replace("\r", "", StringComparison.Ordinal).TrimEnd());
        }
示例#7
0
        public static async ValueTask MultiPackIndex(this GitPlumbingClient c, GitMultiPackIndexArgs?options = null)
        {
            options?.Verify();

            options ??= new();

            List <string> args = new();

            args.Add(options.Command switch
            {
                GitMultiPackIndexCommand.Write => "write",
                GitMultiPackIndexCommand.Verify => "verify",
                GitMultiPackIndexCommand.Repack => "repack",
                _ => throw new ArgumentException()
            });
示例#8
0
        public static async ValueTask <string> Help(this GitPlumbingClient c, GitHelpArgs options)
        {
            options.Verify();
            string[] args;

            if (options.Command == "-a")
            {
                args = new string[] { "-a" }
            }
            ;
            else
            {
                args = new string[] { "-i", options.Command ! ?? options.Guide ! }
            };

            var(_, txt) = await c.Repository.RunGitCommandOutAsync("help", args);

            return(txt ?? "");
        }
示例#9
0
        public static async ValueTask IndexPack(this GitPlumbingClient c, string path, GitIndexPackArgs?options = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            options ??= new GitIndexPackArgs();
            options.Verify();

            List <string> args = new();

            if (options.FixThin)
            {
                args.Add("--fix-thin");
            }

            if (options.ReverseIndex == true)
            {
                args.Add("--rev-index");
            }
            else if (options.ReverseIndex == false)
            {
                args.Add("--no-rev-index");
            }

            args.Add(path);

#if NET5_0_OR_GREATER
            if (OperatingSystem.IsWindows())
#endif
            {
                string idx = Path.ChangeExtension(path, ".idx");
                if (File.Exists(idx))
                {
                    File.SetAttributes(idx, FileAttributes.Normal);
                    File.Delete(idx);
                }
            }

            await c.Repository.RunGitCommandAsync("index-pack", args);
        }
示例#10
0
        public static async ValueTask UpdateIndex(this GitPlumbingClient c, GitUpdateIndexArgs?options = null)
        {
            options ??= new();
            options.Verify();

            List <string> args = new();

            if (options.SplitIndex == true)
            {
                args.Add("--split-index");
            }
            else if (options.SplitIndex == false)
            {
                args.Add("--no-split-index");
            }

            if (options.UntrackedCache == true)
            {
                args.Add("--untracked-cache");
            }
            else if (options.UntrackedCache == false)
            {
                args.Add("--no-untracked-cache");
            }

            if (options.Refresh)
            {
                args.Add("--refresh");
            }
            if (options.ReallyRefresh)
            {
                args.Add("--really-refresh");
            }
            if (options.Again)
            {
                args.Add("--again");
            }
            if (options.IndexVersion.HasValue)
            {
                args.AddRange(new[] { "--index-version", options.IndexVersion.ToString() ! });
示例#11
0
        public static async ValueTask CommitGraph(this GitPlumbingClient c, GitCommitGraphArgs options)
        {
            var args = new List <string>();

            options?.Verify();
            options ??= new();

            if (options.VerifyCommitGraph)
            {
                args.Add("verify");
            }
            else
            {
                args.Add("write");

                switch (options.Split)
                {
                case GitCommitGraphSplit.SingleFile:
                    break;

                case GitCommitGraphSplit.NoMerge:
                    args.Add("--split=no-merge");
                    break;

                case GitCommitGraphSplit.Replace:
                    args.Add("--split=replace");
                    break;

                default:
                    args.Add("--split");
                    break;
                }
            }

            await c.Repository.RunGitCommandAsync("commit-graph", args);

            Porcelain.GitPorcelain.RemoveReadOnlyIfNecessary(c.Repository);
        }
示例#12
0
        public static async ValueTask UpdateReference(this GitPlumbingClient c, GitUpdateReference[] updates, GitUpdateReferenceArgs?options = null)
        {
            options ??= new GitUpdateReferenceArgs();
            options.Verify();

            List <string> args = new List <string>
            {
                "--stdin",
                "-z"
            };

            if (options.CreateReferenceLog)
            {
                args.Add("--create-reflog");
            }
            if (!string.IsNullOrWhiteSpace(options.Message))
            {
                args.Add("-m");
                args.Add(options.Message !);
            }

            await c.Repository.RunGitCommandAsync("update-ref", args,
                                                  stdinText : string.Join("", updates.Select(x => x.ZeroString()).ToArray()));
        }
示例#13
0
 public static async ValueTask <(int ExitCode, string OutputText)> RunRawCommand(this GitPlumbingClient c, string command, params string[] args)
 {
     return(await c.Repository.RunGitCommandOutAsync(command, args));
 }
示例#14
0
        public static IAsyncEnumerable <GitId> RevisionList(this GitPlumbingClient c, GitRevisionListArgs options)
        {
            options.Verify();

            List <string> args = new List <string>();

            if (options.MaxCount != null)
            {
                args.Add($"--max-count={options.MaxCount}");
            }

            if (options.FirstParentOnly)
            {
                args.Add("--first-parent");
            }

            if (options.MaxParents != null)
            {
                args.Add($"--max-parents={options.MaxParents.Value}");
            }
            if (options.MinParents != null)
            {
                args.Add($"--max-parents={options.MinParents.Value}");
            }


            if (options.ShowPulls)
            {
                args.Add("--show-pulls");
            }
            if (options.FullHistory)
            {
                args.Add("--full-history");
            }
            if (options.Dense)
            {
                args.Add("--dense");
            }
            if (options.Sparse)
            {
                args.Add("--sparse");
            }
            if (options.SimplifyMerges)
            {
                args.Add("--simplify-merges");
            }
            if (options.AncestryPath)
            {
                args.Add("--ancestry-path");
            }
            if (options.Reverse)
            {
                args.Add("--reverse");
            }

            switch (options.Order)
            {
            case GitRevisionListOrder.ReverseChronological:
                break;     // Default

            case GitRevisionListOrder.Date:
                args.Add("--date-order");
                break;

            case GitRevisionListOrder.AuthorDate:
                args.Add("--author-date-order");
                break;

            case GitRevisionListOrder.Topological:
                args.Add("--topo-order");
                break;

            default:
                throw new InvalidOperationException();
            }


            if (!options.Commits?.Any() ?? true)
            {
                args.Add("HEAD");
            }
            else
            {
                args.Add("--");
                args.AddRange(options.Commits !);
            }

            return(c.Repository.WalkPlumbingCommand("rev-list", args).Select(x => GitId.TryParse(x, out var oid) ? oid : null !));
        }
示例#15
0
 public static async ValueTask UpdateReference(this GitPlumbingClient c, GitUpdateReference update, GitUpdateReferenceArgs?a = null)
 {
     await UpdateReference(c, new[] { update }, a);
 }