Beispiel #1
0
        public override void PullFromRemote(string remoteUrl, string directory, ScmCredentials credentials)
        {
            if (!this.DirectoryIsRepository(directory))
            {
                if (Directory.Exists(directory) && !this.FileSystemHelper.DirectoryIsEmpty(directory))
                {
                    throw new InvalidOperationException(string.Format(Resource.ScmTargetDirectoryNotEmpty, directory));
                }

                this.CreateRepository(directory);
            }

            remoteUrl = this.RemoveCredentialsFromUrl(remoteUrl, credentials);

            string cmd = string.Format("pull {0} -R \"{1}\"", remoteUrl, directory);

            if (credentials != null)
            {
                cmd += this.CreateParametersWithCredentials(credentials, remoteUrl);
            }

            var result = this.ExecuteCommand(cmd);

            if (!result.Successful)
            {
                throw new InvalidOperationException(result.Output);
            }
        }
Beispiel #2
0
        public override void PullFromRemote(string remoteUrl, string directory, ScmCredentials credentials)
        {
            if (!this.DirectoryIsRepository(directory))
            {
                if (Directory.Exists(directory) && !this.FileSystemHelper.DirectoryIsEmpty(directory))
                {
                    throw new InvalidOperationException(string.Format(Resource.ScmTargetDirectoryNotEmpty, directory));
                }

                this.CreateRepository(directory);
            }

            if (credentials != null)
            {
                remoteUrl = this.CreateRepoUrlWithCredentials(remoteUrl, credentials);
            }

            string cmd    = string.Format("-C \"{0}\" fetch --force --prune {1} refs/heads/*:refs/heads/* refs/tags/*:refs/tags/*", directory, remoteUrl);
            var    result = this.ExecuteCommand(cmd);

            if (!result.Successful)
            {
                throw new InvalidOperationException(result.Output);
            }
        }
Beispiel #3
0
        public string CreateRepoUrlWithCredentials(string url, ScmCredentials credentials)
        {
            // https://stackoverflow.com/a/10054470/6884
            var uri = new UriBuilder(url);

            uri.UserName = credentials.User;
            uri.Password = credentials.Password;
            return(uri.ToString());
        }
Beispiel #4
0
        private string CreateParametersWithCredentials(ScmCredentials credentials, string url)
        {
            // pass credentials via command line instead of putting them into the URL: https://stackoverflow.com/a/22126365/6884

            // Note: we need to pass the host from the URL (e.g. https://bitbucket.org) as the first parameter, otherwise
            // authentication won't work when there's an actual entry in the local config file for the same hoster.
            var    uri     = new Uri(url);
            string baseurl = new UriBuilder(uri.Scheme, uri.Host).ToString();

            return(string.Format(" --config auth.x.prefix={0} --config auth.x.username={1} --config auth.x.password={2}", baseurl, credentials.User, credentials.Password));
        }
Beispiel #5
0
        private string RemoveCredentialsFromUrl(string url, ScmCredentials credentials)
        {
            // Issue #19: if credentials are passed via --config, remove the username from the URL (the Bitbucket API returns the clone URL with username, for example).
            // Some HG versions stop when the username is in the URL *and* passed via --config
            if (credentials != null)
            {
                return(this.UrlHelper.RemoveCredentialsFromUrl(url));
            }

            return(url);
        }
Beispiel #6
0
        public override bool RemoteRepositoryExists(string remoteUrl, ScmCredentials credentials)
        {
            if (credentials != null)
            {
                remoteUrl = this.CreateRepoUrlWithCredentials(remoteUrl, credentials);
            }

            string cmd    = "ls-remote " + remoteUrl;
            var    result = this.ExecuteCommand(cmd);

            return(result.Successful);
        }
Beispiel #7
0
        public override bool RemoteRepositoryExists(string remoteUrl, ScmCredentials credentials)
        {
            remoteUrl = this.RemoveCredentialsFromUrl(remoteUrl, credentials);

            string cmd = "identify " + remoteUrl;

            if (credentials != null)
            {
                cmd += this.CreateParametersWithCredentials(credentials, remoteUrl);
            }

            var result = this.ExecuteCommand(cmd);

            return(result.Successful);
        }
Beispiel #8
0
 /// <summary>
 /// Checks whether a repository exists under the given URL
 /// </summary>
 public abstract bool RemoteRepositoryExists(string remoteUrl, ScmCredentials credentials);
Beispiel #9
0
 /// <summary>
 /// Pulls from a remote repository into a local folder.
 /// If the folder doesn't exist or is not a repository, it's created first.
 /// Must be implemented in the child classes by calling ExecuteCommand and checking the result.
 /// </summary>
 public abstract void PullFromRemote(string remoteUrl, string directory, ScmCredentials credentials);