static string CreateDynamicRepository(string targetPath, RepositoryInfo repositoryInfo, string targetBranch, string targetCommit) { Log.Info(string.Format("Creating dynamic repository at '{0}'", targetPath)); var gitDirectory = Path.Combine(targetPath, ".git"); if (Directory.Exists(gitDirectory)) { Log.Info("Git repository already exists"); using (var repo = new Repository(gitDirectory)) { // We need to fetch before we can checkout the commit var remote = GitRepositoryHelper.EnsureOnlyOneRemoteIsDefined(repo); GitRepositoryHelper.Fetch(repositoryInfo.Authentication, remote, repo); CheckoutCommit(repo, targetCommit); } GitRepositoryHelper.NormalizeGitDirectory(gitDirectory, repositoryInfo.Authentication, noFetch: true, currentBranch: targetBranch); return(gitDirectory); } CloneRepository(repositoryInfo.Url, gitDirectory, repositoryInfo.Authentication); using (var repo = new Repository(gitDirectory)) { CheckoutCommit(repo, targetCommit); } // Normalize (download branches) before using the branch GitRepositoryHelper.NormalizeGitDirectory(gitDirectory, repositoryInfo.Authentication, noFetch: true, currentBranch: targetBranch); return(gitDirectory); }
static string CreateDynamicRepository(string targetPath, AuthenticationInfo authentication, string repositoryUrl, string targetBranch, bool noFetch) { if (string.IsNullOrWhiteSpace(targetBranch)) { throw new GitToolsException("Dynamic Git repositories must have a target branch (/b)"); } Log.Info(string.Format("Creating dynamic repository at '{0}'", targetPath)); var gitDirectory = Path.Combine(targetPath, ".git"); if (Directory.Exists(targetPath)) { Log.Info("Git repository already exists"); GitRepositoryHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch, targetBranch); return gitDirectory; } CloneRepository(repositoryUrl, gitDirectory, authentication); // Normalize (download branches) before using the branch GitRepositoryHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch, targetBranch); return gitDirectory; }