Beispiel #1
0
 public override RepositoryBase CreateFromForm()
 {
     this.EnsureChildControls();
     return(new GitRepository
     {
         RepositoryPath = GitPath.BuildPathFromUrl(this.txtRemoteRepoPath.Text),
         RemoteRepositoryUrl = this.txtRemoteRepoPath.Text
     });
 }
        public byte[] GetCurrentRevision(string path)
        {
            var gitSourcePath = new GitPath(this, path);
            if (gitSourcePath.Repository == null)
                throw new ArgumentException(path + " does not represent a valid Git path.", "sourcePath");

            this.EnsureRepoIsPresent(gitSourcePath.Repository);
            this.GitClient.UpdateLocalRepo(gitSourcePath.Repository, gitSourcePath.Branch, null);
            return this.GitClient.GetLastCommit(gitSourcePath.Repository, gitSourcePath.Branch);
        }
        private DirectoryEntryInfo GetDirectoryEntryInfo(GitPath path)
        {
            if (path.Repository == null)
            {
                return(new DirectoryEntryInfo(
                           string.Empty,
                           string.Empty,
                           Repositories.Select(repo => new DirectoryEntryInfo(repo.RepositoryName, repo.RepositoryName, null, null)).ToArray(),
                           null
                           ));
            }
            else if (path.PathSpecifiedBranch == null)
            {
                this.EnsureRepoIsPresent(path.Repository);

                return(new DirectoryEntryInfo(
                           path.Repository.RepositoryName,
                           path.Repository.RepositoryName,
                           this.GitClient.EnumBranches(path.Repository)
                           .Select(branch => new DirectoryEntryInfo(branch, GitPath.BuildSourcePath(path.Repository.RepositoryName, branch, null), null, null))
                           .ToArray(),
                           null
                           ));
            }
            else
            {
                this.EnsureRepoIsPresent(path.Repository);
                this.GitClient.UpdateLocalRepo(path.Repository, path.PathSpecifiedBranch, null);

                var de = this.Agent.GetDirectoryEntry(new GetDirectoryEntryCommand()
                {
                    Path            = path.PathOnDisk,
                    Recurse         = false,
                    IncludeRootPath = false
                }).Entry;

                var subDirs = de.SubDirectories
                              .Where(entry => !entry.Name.StartsWith(".git"))
                              .Select(subdir => new DirectoryEntryInfo(subdir.Name, GitPath.BuildSourcePath(path.Repository.RepositoryName, path.PathSpecifiedBranch, subdir.Path.Replace('\\', '/')), null, null))
                              .ToArray();

                var files = de.Files
                            .Select(file => new FileEntryInfo(file.Name, GitPath.BuildSourcePath(path.Repository.RepositoryName, path.PathSpecifiedBranch, file.Path.Replace('\\', '/'))))
                            .ToArray();

                return(new DirectoryEntryInfo(
                           de.Name,
                           path.ToString(),
                           subDirs,
                           files
                           ));
            }
        }
        public object GetCurrentRevision(string path)
        {
            var gitSourcePath = new GitPath(this, path);

            if (gitSourcePath.Repository == null)
            {
                throw new ArgumentException(path + " does not represent a valid Git path.", "sourcePath");
            }

            this.EnsureRepoIsPresent(gitSourcePath.Repository);
            this.GitClient.UpdateLocalRepo(gitSourcePath.Repository, gitSourcePath.Branch, null);
            return(this.GitClient.GetLastCommit(gitSourcePath.Repository, gitSourcePath.Branch));
        }
        public void ApplyLabel(string label, string sourcePath)
        {
            if (string.IsNullOrEmpty(label))
                throw new ArgumentNullException("label");

            var gitSourcePath = new GitPath(this, sourcePath);
            if (gitSourcePath.Repository == null)
                throw new ArgumentException(sourcePath + " does not represent a valid Git path.", "sourcePath");

            this.EnsureRepoIsPresent(gitSourcePath.Repository);
            this.GitClient.UpdateLocalRepo(gitSourcePath.Repository, gitSourcePath.Branch, null);
            this.GitClient.ApplyTag(gitSourcePath.Repository, label);
        }
        public byte[] GetFileContents(string filePath)
        {
            var gitSourcePath = new GitPath(this, filePath);

            if (gitSourcePath.Repository == null)
            {
                throw new ArgumentException(filePath + " does not represent a valid Git path.", "filePath");
            }

            this.EnsureRepoIsPresent(gitSourcePath.Repository);
            this.GitClient.UpdateLocalRepo(gitSourcePath.Repository, gitSourcePath.Branch, null);

            return(this.Agent.ReadFileBytes(gitSourcePath.PathOnDisk));
        }
        public void ApplyLabel(string label, string sourcePath)
        {
            if (string.IsNullOrEmpty(label))
            {
                throw new ArgumentNullException("label");
            }

            var gitSourcePath = new GitPath(this, sourcePath);

            if (gitSourcePath.Repository == null)
            {
                throw new ArgumentException(sourcePath + " does not represent a valid Git path.", "sourcePath");
            }

            this.EnsureRepoIsPresent(gitSourcePath.Repository);
            this.GitClient.UpdateLocalRepo(gitSourcePath.Repository, gitSourcePath.Branch, null);
            this.GitClient.ApplyTag(gitSourcePath.Repository, label);
        }
        public void GetLatest(string sourcePath, string targetPath)
        {
            if (targetPath == null)
            {
                throw new ArgumentNullException("targetPath");
            }

            var gitSourcePath = new GitPath(this, sourcePath);

            if (gitSourcePath.Repository == null)
            {
                throw new ArgumentException(sourcePath + " does not represent a valid Git path.", "sourcePath");
            }

            this.EnsureRepoIsPresent(gitSourcePath.Repository);
            this.GitClient.UpdateLocalRepo(gitSourcePath.Repository, gitSourcePath.Branch, null);
            this.CopyNonGitFiles(gitSourcePath.PathOnDisk, targetPath);
        }
        private DirectoryEntryInfo GetDirectoryEntryInfo(GitPath context)
        {
            if (context.Repository == null)
            {
                return new DirectoryEntryInfo(
                    string.Empty,
                    string.Empty,
                    Repositories.Select(repo => new DirectoryEntryInfo(repo.Name, repo.Name, null, null)).ToArray(),
                    null
                );
            }
            else if (context.PathSpecifiedBranch == null)
            {
                this.EnsureLocalRepository(context);

                return new DirectoryEntryInfo(
                    context.Repository.Name,
                    context.Repository.Name,
                    this.GitClient.EnumBranches(context.Repository)
                        .Select(branch => new DirectoryEntryInfo(branch, GitPath.BuildSourcePath(context.Repository.Name, branch, null), null, null))
                        .ToArray(),
                    null
                );
            }
            else
            {
                this.EnsureLocalRepository(context);
                this.UpdateLocalRepository(context, null);

                var de = this.Agent.GetDirectoryEntry(new GetDirectoryEntryCommand()
                {
                    Path = context.WorkspaceDiskPath,
                    Recurse = false,
                    IncludeRootPath = false
                }).Entry;

                var subDirs = de.SubDirectories
                    .Where(entry => !entry.Name.StartsWith(".git"))
                    .Select(subdir => new DirectoryEntryInfo(subdir.Name, GitPath.BuildSourcePath(context.Repository.Name, context.PathSpecifiedBranch, subdir.Path.Replace('\\', '/')), null, null))
                    .ToArray();

                var files = de.Files
                    .Select(file => new FileEntryInfo(file.Name, GitPath.BuildSourcePath(context.Repository.Name, context.PathSpecifiedBranch, file.Path.Replace('\\', '/'))))
                    .ToArray();

                return new DirectoryEntryInfo(
                    de.Name,
                    context.ToString(),
                    subDirs,
                    files
                );
            }
        }
        public byte[] GetFileContents(string filePath)
        {
            var context = new GitPath(this, filePath);
            if (context.Repository == null)
                throw new ArgumentException(filePath + " does not represent a valid Git path.", "filePath");

            this.EnsureLocalRepository(context);
            this.UpdateLocalRepository(context, null);

            return this.Agent.ReadFileBytes(context.WorkspaceDiskPath);
        }
        public byte[] GetFileContents(string filePath)
        {
            var gitSourcePath = new GitPath(this, filePath);
            if (gitSourcePath.Repository == null)
                throw new ArgumentException(filePath + " does not represent a valid Git path.", "filePath");

            this.EnsureRepoIsPresent(gitSourcePath.Repository);
            this.GitClient.UpdateLocalRepo(gitSourcePath.Repository, gitSourcePath.Branch, null);

            return ((IFileOperationsExecuter)this.Agent).ReadAllFileBytes(gitSourcePath.PathOnDisk);
        }
        private DirectoryEntryInfo GetDirectoryEntryInfo(GitPath path)
        {
            if (path.Repository == null)
            {
                return new DirectoryEntryInfo(
                    string.Empty,
                    string.Empty,
                    Repositories.Select(repo => new DirectoryEntryInfo(repo.RepositoryName, repo.RepositoryName, null, null)).ToArray(),
                    null
                );
            }
            else if (path.PathSpecifiedBranch == null)
            {
                this.EnsureRepoIsPresent(path.Repository);

                return new DirectoryEntryInfo(
                    path.Repository.RepositoryName,
                    path.Repository.RepositoryName,
                    this.GitClient.EnumBranches(path.Repository)
                        .Select(branch => new DirectoryEntryInfo(branch, GitPath.BuildSourcePath(path.Repository.RepositoryName, branch, null), null, null))
                        .ToArray(),
                    null
                );
            }
            else
            {
                this.EnsureRepoIsPresent(path.Repository);
                this.GitClient.UpdateLocalRepo(path.Repository, path.PathSpecifiedBranch, null);

                var de = ((IFileOperationsExecuter)this.Agent).GetDirectoryEntry(new GetDirectoryEntryCommand()
                {
                    Path = path.PathOnDisk,
                    Recurse = false,
                    IncludeRootPath = false
                }).Entry;

                var subDirs = de.SubDirectories
                    .Where(entry => !entry.Name.StartsWith(".git"))
                    .Select(subdir => new DirectoryEntryInfo(subdir.Name, GitPath.BuildSourcePath(path.Repository.RepositoryName, path.PathSpecifiedBranch, subdir.Path.Replace('\\', '/')), null, null))
                    .ToArray();

                var files = de.Files
                    .Select(file => new FileEntryInfo(file.Name, GitPath.BuildSourcePath(path.Repository.RepositoryName, path.PathSpecifiedBranch, file.Path.Replace('\\', '/'))))
                    .ToArray();

                return new DirectoryEntryInfo(
                    de.Name,
                    path.ToString(),
                    subDirs,
                    files
                );
            }
        }
        public void GetLatest(string sourcePath, string targetPath)
        {
            if (targetPath == null)
                throw new ArgumentNullException("targetPath");

            var gitSourcePath = new GitPath(this, sourcePath);
            if (gitSourcePath.Repository == null)
                throw new ArgumentException(sourcePath + " does not represent a valid Git path.", "sourcePath");

            this.EnsureRepoIsPresent(gitSourcePath.Repository);
            this.GitClient.UpdateLocalRepo(gitSourcePath.Repository, gitSourcePath.Branch, null);
            this.CopyNonGitFiles(gitSourcePath.PathOnDisk, targetPath);
        }