Beispiel #1
0
        private static void HandleMasterCopyWithExistingGitDir(string masterGitRepoPath, string masterRepoGitDirPath, ILogger log, string gitDirRedirect)
        {
            log.LogDebug($"Master .gitdir {masterRepoGitDirPath} exists");

            // the master folder doesn't exist yet.  Create it.
            if (!Directory.Exists(masterGitRepoPath))
            {
                log.LogDebug($"Master .gitdir exists and master folder {masterGitRepoPath} does not.  Creating master folder.");
                Directory.CreateDirectory(masterGitRepoPath);
                File.WriteAllText(Path.Combine(masterGitRepoPath, ".git"), gitDirRedirect);
                Local masterLocal = new Local(log, masterGitRepoPath);
                log.LogDebug($"Checking out default commit in {masterGitRepoPath}");
                masterLocal.Checkout(null, true);
            }
            // The master folder already exists.  Redirect it to the .gitdir we expect.
            else
            {
                log.LogDebug($"Master .gitdir exists and master folder {masterGitRepoPath} also exists.  Redirecting master folder.");

                string masterRepoPossibleGitDirPath = Path.Combine(masterGitRepoPath, ".git");
                if (Directory.Exists(masterRepoPossibleGitDirPath))
                {
                    Directory.Delete(masterRepoPossibleGitDirPath);
                }
                if (File.Exists(masterRepoPossibleGitDirPath))
                {
                    File.Delete(masterRepoPossibleGitDirPath);
                }
                File.WriteAllText(masterRepoPossibleGitDirPath, gitDirRedirect);
            }
        }
Beispiel #2
0
        private static Local HandleRepoAtSpecificHash(string repoPath, string commit, string masterRepoGitDirPath, ILogger log)
        {
            Local local;

            if (Directory.Exists(repoPath))
            {
                log.LogDebug($"Repo path {repoPath} already exists, assuming we cloned already and skipping");
                local = new Local(log, repoPath);
            }
            else
            {
                log.LogDebug($"Setting up {repoPath} with .gitdir redirect");
                Directory.CreateDirectory(repoPath);
                File.WriteAllText(Path.Combine(repoPath, ".git"), GetGitDirRedirectString(masterRepoGitDirPath));
                log.LogInformation($"Checking out {commit} in {repoPath}");
                local = new Local(log, repoPath);
                local.Checkout(commit, true);
            }

            return(local);
        }