Exemple #1
0
        protected ActionResult InfoRefs(string project, string service)
        {
            Response.Charset = "";
            Response.ContentType = String.Format(CultureInfo.InvariantCulture, "application/x-{0}-advertisement", service);
            SetNoCache();
            Response.Write(FormatMessage(String.Format(CultureInfo.InvariantCulture, "# service={0}\n", service)));
            Response.Write(FlushMessage());

            try
            {
                using (var git = new GitService(GitService.GetDirectoryInfo(project).FullName))
                {
                    var svc = service.Substring(4);
                    git.InfoRefs(svc, GetInputStream(), Response.OutputStream);
                }
                return new EmptyResult();
            }
            catch (RepositoryNotFoundException e)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, string.Empty, e);
            }
            catch (Exception e)
            {
                throw new HttpException((int)HttpStatusCode.InternalServerError, string.Empty, e);
            }
        }
 public ActionResult Detail(string name)
 {
     var model = RepositoryService.GetRepositoryModel(name, true);
     if (model == null)
         throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);
     using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName))
     {
         model.DefaultBranch = git.GetHeadBranch();
     }
     return View(model);
 }
 public ActionResult Contributors(string name, string path)
 {
     using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName))
     {
         var model = git.GetContributors(path);
         if (model == null)
             throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);
         return View(model);
     }
 }
 public JsonResult Branches(string name, string path)
 {
     using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName))
     {
         git.DeleteBranch(path);
         return Json("success");
     }
 }
 public ActionResult Branches(string name)
 {
     using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName))
     {
         var model = git.GetBranches();
         if (model == null)
             throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);
         model.RepositoryName = name;
         model.CanDelete = Token != null && Token.IsSystemAdministrator
             || RepositoryService.CanWriteRepository(name, Token == null ? null : Token.Username);
         return View(model);
     }
 }
 public ActionResult Tags(string name)
 {
     using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName))
     {
         var model = git.GetTags();
         if (model == null)
             throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);
         model.RepositoryName = name;
         return View(model);
     }
 }
        public ActionResult Archive(string name, string path, string eol = null)
        {
            using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName))
            {
                string newline = null;
                switch (eol)
                {
                    case "LF":
                        newline = "\n";
                        break;
                    case "CR":
                        newline = "\r";
                        break;
                    case "CRLF":
                        newline = "\r\n";
                        break;
                    default:
                        eol = null;
                        break;
                }

                string referenceName;
                var cacheFile = git.GetArchiveFilename(path, newline, out referenceName);
                if (cacheFile == null)
                    throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);

                var filename = name + "-" + referenceName;
                if (eol != null)
                    filename += "-" + eol;
                return File(cacheFile, "application/zip", filename + ".zip");
            }
        }
        public ActionResult Commits(string name, string path, int? page)
        {
            using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName))
            {
                var model = git.GetCommits(path, page ?? 1, UserConfiguration.Current.NumberOfCommitsPerPage);
                if (model == null)
                    throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);

                ViewBag.Pager = Pager.Items(model.ItemCount)
                    .PerPage(UserConfiguration.Current.NumberOfCommitsPerPage)
                    .Move(model.CurrentPage)
                    .Segment(5)
                    .Center();

                model.RepositoryName = name;
                return View(model);
            }
        }
 public ActionResult Compare(string name, string path)
 {
     using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName))
     {
         var start = "";
         var end = "";
         if (!string.IsNullOrEmpty(path))
         {
             var index = path.IndexOf("...");
             if (index == -1)
             {
                 start = path;
                 end = "";
             }
             else
             {
                 start = path.Substring(0, index);
                 end = path.Substring(index + 3);
             }
         }
         var model = git.GetCompare(start.Replace(';', '/'), end.Replace(';', '/'));
         if (model == null)
             throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);
         model.RepositoryName = name;
         return View(model);
     }
 }
        public ActionResult Raw(string name, string path)
        {
            using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName))
            {
                var model = git.GetBlob(path);
                if (model == null)
                    throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);

                return model.BlobType == BlobType.Binary
                    ? new RawResult(model.RawData, FileHelper.BinaryMimeType, model.Name)
                    : new RawResult(model.RawData);
            }
        }
        public ActionResult Tree(string name, string path)
        {
            using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName))
            {
                var model = git.GetTree(path);
                if (model == null)
                    throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);
                if (model.Entries == null && model.ReferenceName != "HEAD")
                    return RedirectToAction("Tree", new { path = model.ReferenceName });

                model.GitUrl = GetGitUrl(name);
                model.RepositoryName = name;
                if (model.IsRoot)
                {
                    var m = RepositoryService.GetRepositoryModel(name);
                    model.Description = m.Description;
                }
                return View(model);
            }
        }
        public ActionResult Edit(string name, RepositoryModel model)
        {
            if (string.IsNullOrEmpty(name))
                throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);

            if (ModelState.IsValid)
            {
                if (!RepositoryService.Update(model))
                    throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);
                using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName))
                {
                    git.SetHeadBranch(model.DefaultBranch);
                }
                return RedirectToAction("Detail", new { name });
            }

            return View(model);
        }