当前位置: 首页>>代码示例>>C#>>正文


C# Repository.Unstage方法代码示例

本文整理汇总了C#中LibGit2Sharp.Repository.Unstage方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Unstage方法的具体用法?C# Repository.Unstage怎么用?C# Repository.Unstage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LibGit2Sharp.Repository的用法示例。


在下文中一共展示了Repository.Unstage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main(string[] args)
        {
            try
            {

                log("started...");
                var repoUrl = args[0];
                var branchName = "master";
                var username = args[1];
                var password = "";
                if (args.Length == 3)
                {
                    password = args[2];
                }
                var fileSpec = args[3];
                if (fileSpec.Contains('/'))
                {
                    fileSpec = fileSpec.Replace("/", "\\");
                }
                var pathSplit = repoUrl.Split('/');
                var repoName = pathSplit.Last();
                var fileInfo = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), repoName, fileSpec));
                var author = new Signature("scarletapi", "@gmail", DateTime.Now);
                var repoDir = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), repoName));
                var repoPath = repoDir.FullName;

                if (String.IsNullOrEmpty(username))
                {
                    throw new Exception("Must have username");
                }

                if (String.IsNullOrEmpty(password))
                {
                    repoUrl = repoUrl.Replace(pathSplit[2], String.Format("{0}@{2}", username, password, pathSplit[2]));
                }
                else
                {
                    repoUrl = repoUrl.Replace(pathSplit[2], String.Format("{0}:{1}@{2}", username, password, pathSplit[2]));
                }

                log("checking if repo is valid");
                if (Repository.IsValid(repoPath))
                {
                    log("repo is valid");
                    using (var repo = new LibGit2Sharp.Repository(repoPath))
                    {
                        var remoteBranch = repo.Branches[branchName];

                        repo.Stage(fileInfo.FullName);

                        repo.Checkout(remoteBranch, new CheckoutOptions());
                        repo.Network.Pull( author, new PullOptions());

                        repo.Unstage(fileInfo.FullName);

                        if (!fileInfo.Exists)
                        {
                            log("WARNING: file does not exist {0}", fileInfo.FullName);
                        }

                        log("attempting to get latest, add, commit and pushing to {0}", repoName);

                        var uri = new Uri(repo.Info.WorkingDirectory);

                        log("working directory uri: {0}", uri.OriginalString);
                        log("adding file: {0}", fileInfo.FullName);

                        uri = uri.MakeRelativeUri(new Uri(fileInfo.FullName));
                        repo.Index.Add(uri.OriginalString);
                        var commit = repo.Commit("API Auto Commit", author, author);
                        repo.Refs.UpdateTarget(repo.Refs.Head, commit.Id);
                        var options = new LibGit2Sharp.PushOptions();
                        repo.Network.Push(remoteBranch, options);

                        log("file {0} was pushed to {1}", fileSpec, repoName);
                    }
                }
                else
                {
                    log("repo is NOT valid");
                }
            }
            catch (Exception e)
            {
                log("ERROR: {0}", e.Message);
            }
        }
开发者ID:marchuanv,项目名称:HostFromRepo,代码行数:87,代码来源:Entry.cs


注:本文中的LibGit2Sharp.Repository.Unstage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。