コード例 #1
0
        /// <summary>
        /// Connects to the configured repository, cloning it if it has not yet been downloaded.
        /// </summary>
        public static LibGit2Sharp.Repository InitRepo(Business.Config.Repository repoConfig)
        {
            // Verify repo exists, else clone it.
            var repoPath = RepoFolder + "\\" + repoConfig.name;

            if (!Directory.Exists(repoPath + "\\.git"))
            {
                Logger.Log("Repo doesn't exist, cloning...");
                CloneRepo(repoConfig);
            }

            // Reset the repo back to a clean state.
            Logger.Log("Resetting repo...");
            var repo = new LibGit2Sharp.Repository(repoPath);

            repo.Reset(ResetMode.Hard);

            // Fetch latest refs.
            Logger.Log("Fetching...");
            var fetchOptions = new FetchOptions()
            {
                CredentialsProvider = (url, user, cred) => GetCredentials(repoConfig)
            };

            foreach (var remote in repo.Network.Remotes)
            {
                var logMessage = "";
                var refSpecs   = remote.FetchRefSpecs.Select(x => x.Specification);

                Commands.Fetch(repo, remote.Name, refSpecs, fetchOptions, logMessage);
            }

            Logger.Log("Repo initialized.");
            return(repo);
        }
コード例 #2
0
        /// <summary>
        /// Clones a git repository from the specified repository config.
        /// </summary>
        private static void CloneRepo(Business.Config.Repository repoConfig)
        {
            var co = new CloneOptions();

            co.CredentialsProvider = (url, user, cred) => GetCredentials(repoConfig);

            var repoPath = RepoFolder + "\\" + repoConfig.name;

            if (!Directory.Exists(repoPath))
            {
                Directory.CreateDirectory(repoPath);
            }

            LibGit2Sharp.Repository.Clone("https://[email protected]/MartinBlore/testrepo.git", repoPath, co);
        }
コード例 #3
0
        /// <summary>
        /// Initialize a credentials object from config for a repository.
        /// </summary>
        private static Credentials GetCredentials(Business.Config.Repository repoConfig)
        {
            Credentials creds = null;

            if (repoConfig.useDefaultCredentials)
            {
                creds = new DefaultCredentials();
            }
            else
            {
                creds = new UsernamePasswordCredentials
                {
                    Username = repoConfig.username,
                    Password = repoConfig.password
                };
            }

            return(creds);
        }
コード例 #4
0
ファイル: BranchManager.cs プロジェクト: MBlore/GitLighthouse
 public BranchManager(Repository repo, Business.Config.Repository repoConfig)
 {
     this.repo       = repo;
     this.repoConfig = repoConfig;
 }