Пример #1
0
        public ActionResult ZipArchive(
            string branch, string path)
        {
            var repository = new GitVersioningSystem(path, branch);
            var archive    = repository.GenerateZipArchive();

            return(File(archive.Data, "application/zip", archive.Name));
        }
Пример #2
0
        public ActionResult Log(
            string branch, string path, int skip = 0, int take = 50)
        {
            var repository = new GitVersioningSystem(path, branch);

            var model = new CommitHistoryViewModel {
                Branch         = branch,
                RepositoryPath = repository.RootPath,
                Commits        = repository.GetCommitMessages(skip, take)
            };

            return(View(model));
        }
Пример #3
0
        public ActionResult Index(
            string path)
        {
            var repository = new GitVersioningSystem(path);

            var model = new RepositoryViewModel {
                RepositoryPath = repository.RootPath,
                Branches       = repository.GetBranches(),
                ReadMe         = repository.FindAndReadFile(_isReadMe)
            };

            return(View(model));
        }
Пример #4
0
        public ActionResult RawBlob(
            string branch, string path)
        {
            var repository = new GitVersioningSystem(path, branch);

            var content = repository.GetBlobContent();

            if (content == null)
            {
                return(HttpNotFound());
            }

            return(File(content.RawContent, "application/octet-stream", content.FileName));
        }
Пример #5
0
        public ActionResult Commit(
            string branch, string hash, string path)
        {
            var repository = new GitVersioningSystem(path, branch);
            var details    = repository.GetCommitDetails(hash);

            var model = new CommitDetailsViewModel {
                Branch         = branch,
                RepositoryPath = repository.RootPath,
                Files          = details.FileDiffs,
                CommitMessage  = details.Message
            };

            return(View(model));
        }
Пример #6
0
        public ActionResult Blob(
            string branch, string path)
        {
            var repository = new GitVersioningSystem(path, branch);

            var content = repository.GetBlobContent();

            if (content == null)
            {
                return(HttpNotFound());
            }

            content.RawUrl = Url.Action("RawBlob", new { branch, path });

            return(View(content));
        }
Пример #7
0
        public ActionResult Tree(
            string branch, string path, bool commits = false)
        {
            var repository = new GitVersioningSystem(path, branch);

            string parentSubPath = null;

            if (!string.IsNullOrEmpty(repository.SubPath))
            {
                parentSubPath = repository.SubPath;

                var index = repository.SubPath.LastIndexOf('/');
                if (index == -1)
                {
                    parentSubPath = string.Empty;
                }
                else if (index > -1)
                {
                    parentSubPath = repository.SubPath.Substring(0, index);
                }
            }

            var model = new RepositoryTreeViewModel {
                Branch         = branch,
                RepositoryPath = repository.RootPath,
                ParentSubPath  = parentSubPath,
                Tree           = repository.GetRepositoryContent(commits)
            };

            var pjax = Request.Headers["X-PJAX"] != null;

            if (pjax || commits)
            {
                return(PartialView("_RepositoryTree", model));
            }

            return(View(model));
        }
Пример #8
0
        private void GetRepositories(
            ICollection <OrganizationRepository> directories,
            DirectoryInfo directory,
            string relativePath)
        {
            if (directory.Name.EndsWith(".git"))
            {
                // Repository
                var repository = new GitVersioningSystem(relativePath);

                directories.Add(
                    new OrganizationRepository
                {
                    Name        = repository.RootPath,
                    HasBranches = repository.GetBranches().Any()
                });
            }
            else
            {
                // Namespace
                foreach (var subDirectory in directory.EnumerateDirectories())
                {
                    try
                    {
                        subDirectory.EnumerateDirectories();
                    }
                    catch (UnauthorizedAccessException)
                    {
                        continue;
                    }

                    var path = string.Concat(relativePath, "/", subDirectory.Name);
                    GetRepositories(directories, subDirectory, path);
                }
            }
        }