コード例 #1
0
        public void TestGitPull()
        {
            using (var tempRepo = new TempDirectory())
            {
                CreateTempRepo(tempRepo);
                CreateNewBranchInTempRepo(tempRepo, "newbranch");

                var remoteRepo = new GitRepository(Path.GetFileName(tempRepo.Path),
                                                   Directory.GetParent(tempRepo.Path).FullName, Log);
                {
                    using (var localRepo = new TempDirectory())
                    {
                        var repo = new GitRepository(Path.GetFileName(localRepo.Path),
                                                     Directory.GetParent(localRepo.Path).FullName, Log);
                        {
                            repo.Clone(tempRepo.Path.Replace("\\", "/"));

                            CommitIntoTempRepo(tempRepo, "newbranch");
                            var remoteSha = remoteRepo.CurrentLocalCommitHash();
                            repo.Pull("newbranch");
                            var localSha = repo.CurrentLocalCommitHash();


                            Assert.AreEqual(remoteSha, localSha);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public static int ChangeModule(Package package, string moduleName, string pushUrl, string fetchUrl)
        {
            using (var tempDir = new TempDirectory())
            {
                var repo = new GitRepository("modules_git", tempDir.Path, Log);
                repo.Clone(package.Url);

                var toChange = FindModule(repo, moduleName);
                if (toChange == null)
                {
                    ConsoleWriter.WriteError("Unable to find module " + moduleName + " in package " + package.Name);
                    return(-1);
                }
                if (toChange.Url == fetchUrl && toChange.Pushurl == pushUrl)
                {
                    ConsoleWriter.WriteInfo("Your changes were already made");
                    return(0);
                }

                ChangeModuleDescription(repo, toChange, new Module(moduleName, fetchUrl, pushUrl));

                var message = "(!)cement comment: changed module '" + moduleName + "'";
                repo.Commit(new[] { "-am", message });
                repo.Push("master");
            }

            ConsoleWriter.WriteOk("Success changed " + moduleName + " in " + package.Name);
            return(0);
        }
コード例 #3
0
        public static int AddModule(Package package, string moduleName, string pushUrl, string fetchUrl)
        {
            if (fetchUrl.StartsWith("https://git.skbkontur.ru/"))
            {
                throw new CementException("HTTPS url not allowed for gitlab. You should use SSH url.");
            }
            using (var tempDir = new TempDirectory())
            {
                var repo = new GitRepository("modules_git", tempDir.Path, Log);
                repo.Clone(package.Url);
                if (FindModule(repo, moduleName) != null)
                {
                    ConsoleWriter.WriteError("Module " + moduleName + " already exists in " + package.Name);
                    return(-1);
                }
                WriteModuleDescription(moduleName, pushUrl, fetchUrl, repo);

                var message = "(!)cement comment: added module '" + moduleName + "'";
                repo.Commit(new[] { "-am", message });
                repo.Push("master");
            }

            ConsoleWriter.WriteOk("Success added " + moduleName + " to " + package.Name);
            return(0);
        }
コード例 #4
0
ファイル: DependencyTraverser.cs プロジェクト: macro187/nugit
 Clone(string parentPath, GitUrl url)
 {
     using (LogicalOperation.Start($"Cloning {url}"))
     {
         GitRepository.Clone(parentPath, url);
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: q4chrisj/EuroPull
        static void Main(string[] args)
        {
            string        gitBranch = ConfigurationManager.AppSettings["GitBranch"].ToString();
            string        localPath = ConfigurationManager.AppSettings["LocalRepoPath"].ToString();
            GitRepository repo      = new GitRepository(ConfigurationManager.AppSettings["GithubRepoUrl"].ToString(), localPath, ConfigurationManager.AppSettings["GithubToken"].ToString());

            if (!Directory.Exists(Path.GetFullPath(localPath)))
            {
                Directory.CreateDirectory(Path.GetFullPath(localPath));
            }

            try
            {
                repo.Clone();
            }
            catch (Exception ex)
            {
                //System.Console.WriteLine(ex);
            }

            if (!string.Equals(repo.CurrentBranch(), gitBranch))
            {
                repo.Checkout(gitBranch);
            }

            var result = repo.Pull();

            if (!result.Equals("UpToDate"))
            {
                System.Console.WriteLine("Invalidate cloudfront distribution.");
            }
        }
コード例 #6
0
 public void TestGitLocalCommitHashEqualsRemote()
 {
     using (var tempRepo = new TempDirectory())
     {
         CreateTempRepo(tempRepo);
         var remoteRepo = new GitRepository(
             Path.GetFileName(tempRepo.Path),
             Directory.GetParent(tempRepo.Path).FullName, Log);
         {
             var remoteCommit = remoteRepo.CurrentLocalCommitHash();
             using (var localRepo = new TempDirectory())
             {
                 var repo = new GitRepository(
                     Path.GetFileName(localRepo.Path),
                     Directory.GetParent(localRepo.Path).FullName, Log);
                 {
                     repo.Clone(tempRepo.Path);
                     var localCommit = repo.RemoteCommitHashAtBranch("master");
                     Assert.AreEqual(localCommit, remoteCommit);
                     Assert.AreEqual(localCommit, repo.RemoteCommitHashAtTreeish("master"));
                 }
             }
         }
     }
 }
コード例 #7
0
 public void TestGitCloneUnexistingRepo()
 {
     using (var tempDirectory = new TempDirectory())
     {
         var repo = new GitRepository("unexisting_directory", tempDirectory.Path, Log);
         Assert.Throws <GitCloneException>(() => repo.Clone("SOME/REPO"));
     }
 }
コード例 #8
0
 public void TestInitialize()
 {
     if (Directory.Exists(wrkroot))
     {
         Directory.Delete(wrkroot, true);
     }
     Directory.CreateDirectory(wrkroot);
     wrkRepoA = GitRepository.Clone(wrkroot, srcUrlA);
 }
コード例 #9
0
 public void TestGitCloneUnexistingBranch()
 {
     using (var url = new TempDirectory())
     {
         CreateTempRepo(url);
         using (var tempDirectory = new TempDirectory())
         {
             var repo = new GitRepository("unexisting_directory", tempDirectory.Path, Log);
             Assert.Throws <GitCloneException>(() => repo.Clone(url.Path, "unexisting_branch"));
         }
     }
 }
コード例 #10
0
 public void TestGitClone()
 {
     using (var url = new TempDirectory())
     {
         CreateTempRepo(url);
         using (var tempDirectory = new TempDirectory())
         {
             var repo = new GitRepository("unexisting_directory", tempDirectory.Path, Log);
             repo.Clone(url.Path);
             Assert.IsTrue(Directory.Exists(Path.Combine(tempDirectory.Path, "unexisting_directory")));
         }
     }
 }
コード例 #11
0
 public void TestGitHasUnExistingTreeishOnRemote()
 {
     using (var tempRepo = new TempDirectory())
     {
         CreateTempRepo(tempRepo);
         using (var localRepo = new TempDirectory())
         {
             var repo = new GitRepository(Path.GetFileName(localRepo.Path),
                                          Directory.GetParent(localRepo.Path).FullName, Log);
             repo.Clone(tempRepo.Path);
         }
     }
 }
コード例 #12
0
 public void TestGitCloneToNotEmptyFolder()
 {
     using (var url = new TempDirectory())
     {
         CreateTempRepo(url);
         using (var tempDirectory = new TempDirectory())
         {
             Directory.CreateDirectory(Path.Combine(tempDirectory.Path, "unexisting_directory"));
             File.WriteAllText(Path.Combine(tempDirectory.Path, "unexisting_directory", "README.txt"), "README");
             var repo = new GitRepository("unexisting_directory", tempDirectory.Path, Log);
             Assert.Throws <GitCloneException>(() => repo.Clone(url.Path));
         }
     }
 }
コード例 #13
0
 public void TestPullForRealRepo()
 {
     using (var tempRepo = new TempDirectory())
     {
         var repo = new GitRepository(Path.GetFileName(tempRepo.Path),
                                      Directory.GetParent(tempRepo.Path).FullName, Log);
         {
             repo.Clone("https://github.com/skbkontur/cement", "master");
             repo.Fetch("master");
             repo.HasRemoteBranch("master");
             repo.Checkout("master");
         }
     }
 }
コード例 #14
0
 public void TestGitRemoteCommitHash40Symbols()
 {
     using (var tempRepo = new TempDirectory())
     {
         CreateTempRepo(tempRepo);
         using (var localRepo = new TempDirectory())
         {
             var repo = new GitRepository(Path.GetFileName(localRepo.Path),
                                          Directory.GetParent(localRepo.Path).FullName, Log);
             repo.Clone(tempRepo.Path);
             Assert.AreEqual(40, repo.RemoteCommitHashAtBranch("master").Length);
         }
     }
 }
コード例 #15
0
 public void TestGitIsKnownRemoteBranch()
 {
     using (var tempRepo = new TempDirectory())
     {
         CreateTempRepo(tempRepo);
         CreateNewBranchInTempRepo(tempRepo, "newbranch");
         using (var localRepo = new TempDirectory())
         {
             var repo = new GitRepository(Path.GetFileName(localRepo.Path),
                                          Directory.GetParent(localRepo.Path).FullName, Log);
             {
                 repo.Clone(tempRepo.Path);
                 Assert.True(repo.IsKnownRemoteBranch("newbranch"));
             }
         }
     }
 }