Esempio n. 1
0
        public ActionResult Commits(Guid id, string encodedName, int?page = null)
        {
            page = page >= 1 ? page : 1;

            ViewBag.ID = id;
            ViewBag.ShowShortMessageOnly = true;
            var repo = RepositoryRepository.GetRepository(id);

            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    name = PathEncoder.Decode(encodedName);
                string referenceName;
                int    totalCount;
                var    commits = browser.GetCommits(name, page.Value, 10, out referenceName, out totalCount);
                PopulateBranchesData(browser, referenceName);
                ViewBag.TotalCount = totalCount;

                var linksreg = repo.LinksUseGlobal ? UserConfiguration.Current.LinksRegex : repo.LinksRegex;
                var linksurl = repo.LinksUseGlobal ? UserConfiguration.Current.LinksUrl : repo.LinksUrl;
                foreach (var commit in commits)
                {
                    var links = new List <string>();
                    if (!string.IsNullOrEmpty(linksreg))
                    {
                        try
                        {
                            var matches = Regex.Matches(commit.Message, linksreg);
                            if (matches.Count > 0)
                            {
                                foreach (Match match in matches)
                                {
                                    IEnumerable <Group> groups = match.Groups.Cast <Group>();
                                    var link = "";
                                    try
                                    {
                                        var m = groups.Select(x => x.ToString()).ToArray();
                                        link = string.Format(linksurl, m);
                                    }
                                    catch (FormatException e)
                                    {
                                        link = "An error occured while trying to format the link. Exception: " + e.Message;
                                    }
                                    links.Add(link);
                                }
                            }
                        }
                        catch (ArgumentException e)
                        {
                            links.Add("An error occured while trying to match the regualar expression. Error: " + e.Message);
                        }
                    }
                    commit.Links = links;
                }
                return(View(new RepositoryCommitsModel {
                    Commits = commits,
                    Name = repo.Name,
                    Logo = new RepositoryLogoDetailModel(repo.Logo)
                }));
            }
        }
Esempio n. 2
0
        public ActionResult Raw(Guid id, string encodedName, string encodedPath, bool display = false)
        {
            ViewBag.ID = id;

            var repo = RepositoryRepository.GetRepository(id);

            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    name = PathEncoder.Decode(encodedName);
                var    path = PathEncoder.Decode(encodedPath);
                string referenceName;
                var    model = browser.BrowseBlob(name, path, out referenceName);

                if (!display)
                {
                    return(File(model.Data, "application/octet-stream", model.Name));
                }
                if (model.IsText)
                {
                    return(Content(model.Text, "text/plain", model.Encoding));
                }
                if (model.IsImage)
                {
                    return(File(model.Data, MimeTypeMap.GetMimeType(Path.GetExtension(model.Name.ToLower())), model.Name));
                }
            }

            return(HttpNotFound());
        }
Esempio n. 3
0
 public ActionResult Edit(RepositoryDetailModel model)
 {
     if (ModelState.IsValid)
     {
         var currentUserIsInAdminList = model.PostedSelectedAdministrators != null && model.PostedSelectedAdministrators.Contains(User.Id());
         if (currentUserIsInAdminList || User.IsInRole(Definitions.Roles.Administrator))
         {
             var existingRepo = RepositoryRepository.GetRepository(model.Id);
             var repoModel    = ConvertRepositoryDetailModel(model);
             MoveRepo(existingRepo, repoModel);
             try
             {
                 RepositoryRepository.Update(repoModel);
             }
             catch (System.Data.Entity.Infrastructure.DbUpdateException)
             {
                 MoveRepo(repoModel, existingRepo);
             }
             ViewBag.UpdateSuccess = true;
         }
         else
         {
             ModelState.AddModelError("Administrators", Resources.Repository_Edit_CantRemoveYourself);
         }
     }
     PopulateCheckboxListData(ref model);
     return(View(model));
 }
Esempio n. 4
0
        public ActionResult Download(Guid id, string encodedName, string encodedPath)
        {
            var name = PathEncoder.Decode(encodedName);
            var path = PathEncoder.Decode(encodedPath);

            Response.BufferOutput = false;
            Response.Charset      = "";
            Response.ContentType  = "application/zip";

            var    repo        = RepositoryRepository.GetRepository(id);
            string headerValue = ContentDispositionUtil.GetHeaderValue((name ?? repo.Name) + ".zip");

            Response.AddHeader("Content-Disposition", headerValue);

            using (var outputZip = new ZipFile())
            {
                outputZip.UseZip64WhenSaving     = Zip64Option.Always;
                outputZip.AlternateEncodingUsage = ZipOption.AsNecessary;
                outputZip.AlternateEncoding      = Encoding.Unicode;

                using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
                {
                    AddTreeToZip(browser, name, path, outputZip);
                }

                outputZip.Save(Response.OutputStream);

                return(new EmptyResult());
            }
        }
        public ActionResult GitLfsBasicTransferUpload(string repositoryName, string oid)
        {
            bool authorized = RepositoryPermissionService.HasPermission(User.Id(), RepositoryRepository.GetRepository(repositoryName).Id, RepositoryAccessLevel.Pull);

            if (!authorized)
            {
                Response.StatusCode = 403;
                return(Content(
                           Newtonsoft.Json.JsonConvert.SerializeObject(new BatchApiErrorResponse()
                {
                    Message = "You do not have permission to PUSH (LFS upload)."
                })
                           , GitLfsConsts.GIT_LFS_CONTENT_TYPE));
            }

            // If the object already exists, the client does not send it.  But even if it does, we will still not replace it.
            if (!StorageProvider.Exists(repositoryName, oid))
            {
                using (Stream destStream = StorageProvider.GetWriteStream(LfsOperationNames.UPLOAD, repositoryName, oid))
                {
                    Request.InputStream.CopyTo(destStream);
                    destStream.Flush();
                    destStream.Close();
                }
            }

            Response.StatusCode = 200;
            return(null);
        }
Esempio n. 6
0
        public ActionResult Tags(Guid id, string encodedName, int page = 1)
        {
            page = page >= 1 ? page : 1;


            ViewBag.ShowShortMessageOnly = true;
            var repo = RepositoryRepository.GetRepository(id);

            ViewBag.ID     = id;
            ViewBag.Name   = repo.Name;
            ViewBag.GitUrl = GitUrl(repo.Name);
            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    name = PathEncoder.Decode(encodedName);
                string referenceName;
                int    totalCount;
                var    commits = browser.GetTags(name, page, 10, out referenceName, out totalCount);
                PopulateBranchesData(browser, referenceName);
                ViewBag.TotalCount = totalCount;
                return(View(new RepositoryCommitsModel
                {
                    Commits = commits,
                    Name = repo.Name,
                    Logo = new RepositoryLogoDetailModel(repo.Logo)
                }));
            }
        }
Esempio n. 7
0
        public ActionResult Edit(Guid id)
        {
            var model = ConvertRepositoryModel(RepositoryRepository.GetRepository(id));

            PopulateCheckboxListData(ref model);
            return(View(model));
        }
Esempio n. 8
0
 private void PopulateCheckboxListData(ref RepositoryDetailModel model)
 {
     model = model.Id != Guid.Empty ? ConvertRepositoryModel(RepositoryRepository.GetRepository(model.Id)) : model;
     model.AllAdministrators            = MembershipService.GetAllUsers().ToArray();
     model.AllUsers                     = MembershipService.GetAllUsers().ToArray();
     model.AllTeams                     = TeamRepository.GetAllTeams().ToArray();
     model.PostedSelectedAdministrators = new Guid[0];
     model.PostedSelectedUsers          = new Guid[0];
     model.PostedSelectedTeams          = new Guid[0];
 }
Esempio n. 9
0
 public ActionResult Edit(string id)
 {
     if (!String.IsNullOrEmpty(id))
     {
         var model = ConvertRepositoryModel(RepositoryRepository.GetRepository(id));
         PopulateEditData();
         return(View(model));
     }
     return(View());
 }
Esempio n. 10
0
        public ActionResult Commit(Guid id, string commit)
        {
            ViewBag.ID = id;
            ViewBag.ShowShortMessageOnly = false;
            var repo = RepositoryRepository.GetRepository(id);

            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var model = browser.GetCommitDetail(commit);
                model.Name = repo.Name;
                return(View(model));
            }
        }
Esempio n. 11
0
 public ActionResult Detail(string id)
 {
     ViewBag.ID = id;
     if (!String.IsNullOrEmpty(id))
     {
         var model = ConvertRepositoryModel(RepositoryRepository.GetRepository(id));
         if (model != null)
         {
             model.IsCurrentUserAdministrator = RepositoryPermissionService.IsRepositoryAdministrator(User.Identity.Name, id);
         }
         return(View(model));
     }
     return(View());
 }
Esempio n. 12
0
        public ActionResult Clone(Guid id)
        {
            if (!User.IsInRole(Definitions.Roles.Administrator) && !UserConfiguration.Current.AllowUserRepositoryCreation)
            {
                return(RedirectToAction("Unauthorized", "Home"));
            }

            var model = ConvertRepositoryModel(RepositoryRepository.GetRepository(id));

            model.Name = "";
            PopulateCheckboxListData(ref model);
            ViewBag.ID = id;
            return(View(model));
        }
Esempio n. 13
0
        public ActionResult Clone(Guid id)
        {
            if (!RepositoryPermissionService.HasCreatePermission(User.Id()))
            {
                return(RedirectToAction("Unauthorized", "Home"));
            }

            var model = ConvertRepositoryModel(RepositoryRepository.GetRepository(id), User);

            model.Name = "";
            PopulateCheckboxListData(ref model);
            ViewBag.ID = id;
            return(View(model));
        }
Esempio n. 14
0
        public ActionResult Tree(Guid id, string encodedName, string encodedPath)
        {
            bool includeDetails = Request.IsAjaxRequest();


            var name = PathEncoder.Decode(encodedName);
            var path = PathEncoder.Decode(encodedPath);

            var repo = RepositoryRepository.GetRepository(id);
            var repositoryDetailModel = ConvertRepositoryModel(repo, User);

            ViewBag.ID     = id;
            ViewBag.Name   = repo.Name;
            ViewBag.GitUrl = GitUrl(repo.Name);
            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                string referenceName;
                var    files = browser.BrowseTree(name, path, out referenceName, includeDetails).ToList();

                var    readme    = files.FirstOrDefault(x => x.Name.Equals("readme.md", StringComparison.OrdinalIgnoreCase));
                string readmeTxt = string.Empty;
                if (readme != null)
                {
                    string refereceName;
                    var    blob = browser.BrowseBlob(name, readme.Path, out refereceName);
                    readmeTxt = blob.Text;
                }
                var model = new RepositoryTreeModel
                {
                    Name   = repo.Name,
                    Branch = name ?? referenceName,
                    Path   = path,
                    Readme = readmeTxt,
                    Logo   = new RepositoryLogoDetailModel(repo.Logo),
                    Files  = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name)
                };

                if (includeDetails)
                {
                    return(Json(model, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    PopulateBranchesData(browser, referenceName);
                    PopulateAddressBarData(path);
                    return(View(model));
                }
            }
        }
Esempio n. 15
0
 public ActionResult Delete(RepositoryDetailModel model)
 {
     if (model != null)
     {
         var    repo = RepositoryRepository.GetRepository(model.Id);
         string path = Path.Combine(UserConfiguration.Current.Repositories, repo.Name);
         if (Directory.Exists(path))
         {
             DeleteFileSystemInfo(new DirectoryInfo(path));
         }
         RepositoryRepository.Delete(repo.Id);
         TempData["DeleteSuccess"] = true;
     }
     return(RedirectToAction("Index"));
 }
Esempio n. 16
0
        public ActionResult Blob(Guid id, string encodedName, string encodedPath)
        {
            ViewBag.ID = id;
            var repo = RepositoryRepository.GetRepository(id);

            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    name = PathEncoder.Decode(encodedName);
                var    path = PathEncoder.Decode(encodedPath);
                string referenceName;
                var    model = browser.BrowseBlob(name, path, out referenceName);
                PopulateBranchesData(browser, referenceName);
                PopulateAddressBarData(path);

                return(View(model));
            }
        }
Esempio n. 17
0
        public ActionResult History(Guid id, string encodedPath, string encodedName)
        {
            ViewBag.ID = id;
            ViewBag.ShowShortMessageOnly = true;
            var repo = RepositoryRepository.GetRepository(id);

            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    path = PathEncoder.Decode(encodedPath);
                var    name = PathEncoder.Decode(encodedName);
                string referenceName;
                var    commits = browser.GetHistory(path, name, out referenceName);
                return(View(new RepositoryCommitsModel {
                    Commits = commits, Name = repo.Name
                }));
            }
        }
Esempio n. 18
0
 private Guid GetRepoId(AuthorizationContext filterContext)
 {
     if (filterContext.Controller.ControllerContext.RouteData.Values.ContainsKey("id"))
     {
         Guid result;
         if (Guid.TryParse(filterContext.Controller.ControllerContext.RouteData.Values["id"].ToString(), out result))
         {
             return(result);
         }
         else
         {
             return(Guid.Empty);
         }
     }
     else
     {
         return(RepositoryRepository.GetRepository(filterContext.Controller.ControllerContext.RouteData.Values["repositoryName"].ToString()).Id);
     }
 }
Esempio n. 19
0
        public ActionResult Detail(Guid id)
        {
            ViewBag.ID = id;
            var model = ConvertRepositoryModel(RepositoryRepository.GetRepository(id));

            if (model != null)
            {
                model.IsCurrentUserAdministrator = User.IsInRole(Definitions.Roles.Administrator) || RepositoryPermissionService.IsRepositoryAdministrator(User.Id(), model.Id);
                SetGitUrls(model);
            }
            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, model.Name)))
            {
                string defaultReferenceName;
                browser.BrowseTree(null, null, out defaultReferenceName);
                RouteData.Values.Add("encodedName", defaultReferenceName);
            }

            return(View(model));
        }
Esempio n. 20
0
        public ActionResult Commit(Guid id, string commit)
        {
            ViewBag.ID = id;
            ViewBag.ShowShortMessageOnly = false;
            var repo = RepositoryRepository.GetRepository(id);

            ViewBag.ID     = id;
            ViewBag.Name   = repo.Name;
            ViewBag.GitUrl = GitUrl(repo.Name);
            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                string referenceName;
                var    model = browser.GetCommitDetail(commit, out referenceName);
                PopulateBranchesData(browser, referenceName);
                model.Name = repo.Name;
                model.Logo = new RepositoryLogoDetailModel(repo.Logo);
                return(View(model));
            }
        }
        public ActionResult GitLfsBasicTransferDownload(string repositoryName, string oid)
        {
            bool authorized = RepositoryPermissionService.HasPermission(User.Id(), RepositoryRepository.GetRepository(repositoryName).Id, RepositoryAccessLevel.Pull);

            if (!authorized)
            {
                Response.StatusCode = 403;
                return(Content(
                           Newtonsoft.Json.JsonConvert.SerializeObject(new BatchApiErrorResponse()
                {
                    Message = "You do not have permission to PULL (LFS download)."
                })
                           , GitLfsConsts.GIT_LFS_CONTENT_TYPE));
            }

            Stream readStream = StorageProvider.GetReadStream(LfsOperationNames.DOWNLOAD, repositoryName, oid);

            return(File(readStream, "application/octet-stream"));
        }
Esempio n. 22
0
 public ActionResult Detail(string id)
 {
     ViewBag.ID = id;
     if (!String.IsNullOrEmpty(id))
     {
         var model = ConvertRepositoryModel(RepositoryRepository.GetRepository(id));
         if (model != null)
         {
             model.IsCurrentUserAdministrator = RepositoryPermissionService.IsRepositoryAdministrator(User.Identity.Name, id);
         }
         using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id)))
         {
             string defaultReferenceName;
             browser.BrowseTree(null, null, out defaultReferenceName);
             RouteData.Values.Add("encodedName", defaultReferenceName);
         }
         return(View(model));
     }
     return(View());
 }
Esempio n. 23
0
        public ActionResult Graph(Guid id)
        {
            ViewBag.ID = id;

            var model = ConvertRepositoryModel(RepositoryRepository.GetRepository(id), User);

            if (model != null)
            {
                model.IsCurrentUserAdministrator = RepositoryPermissionService.HasPermission(User.Id(), model.Id, RepositoryAccessLevel.Administer);
                SetGitUrls(model);
            }
            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, model.Name)))
            {
                string defaultReferenceName;
                browser.BrowseTree(null, null, out defaultReferenceName);
                RouteData.Values.Add("encodedName", defaultReferenceName);
            }

            return(View(model));
        }
Esempio n. 24
0
        public ActionResult Blame(Guid id, string encodedName, string encodedPath)
        {
            ViewBag.ShowShortMessageOnly = true;
            var repo = RepositoryRepository.GetRepository(id);

            ViewBag.ID     = id;
            ViewBag.Name   = repo.Name;
            ViewBag.GitUrl = GitUrl(repo.Name);
            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                var    name = PathEncoder.Decode(encodedName);
                var    path = PathEncoder.Decode(encodedPath);
                string referenceName;
                var    model = browser.GetBlame(name, path, out referenceName);
                model.Logo = new RepositoryLogoDetailModel(repo.Logo);
                PopulateBranchesData(browser, referenceName);
                PopulateAddressBarData(path);

                return(View(model));
            }
        }
Esempio n. 25
0
 private void PopulateCheckboxListData(ref RepositoryDetailModel model)
 {
     model = model.Id != Guid.Empty ? ConvertRepositoryModel(RepositoryRepository.GetRepository(model.Id), User) : model;
     model.AllAdministrators = MembershipService.GetAllUsers().ToArray();
     model.AllUsers          = MembershipService.GetAllUsers().ToArray();
     model.AllTeams          = TeamRepository.GetAllTeams().ToArray();
     if (model.PostedSelectedUsers != null && model.PostedSelectedUsers.Any())
     {
         model.Users = model.PostedSelectedUsers.Select(x => MembershipService.GetUserModel(x)).ToArray();
     }
     if (model.PostedSelectedTeams != null && model.PostedSelectedTeams.Any())
     {
         model.Teams = model.PostedSelectedTeams.Select(x => TeamRepository.GetTeam(x)).ToArray();
     }
     if (model.PostedSelectedAdministrators != null && model.PostedSelectedAdministrators.Any())
     {
         model.Administrators = model.PostedSelectedAdministrators.Select(x => MembershipService.GetUserModel(x)).ToArray();
     }
     model.PostedSelectedAdministrators = new Guid[0];
     model.PostedSelectedUsers          = new Guid[0];
     model.PostedSelectedTeams          = new Guid[0];
 }
Esempio n. 26
0
        public GitLfsResult GetBatchApiResponse(string urlScheme, string urlAuthority, string requestApplicationPath, string repositoryName, string[] acceptTypes, BatchApiRequest requestObj, Guid userId)
        {
            // Validate the request.
            if (!acceptTypes
                .Select(at => at.Split(new[] { ';' }))
                .SelectMany(list => list)
                .Any(at => at.Equals("application/vnd.git-lfs+json")))
            {
                return(GitLfsResult.From(
                           Newtonsoft.Json.JsonConvert.SerializeObject(
                               new BatchApiErrorResponse()
                {
                    Message = "Invalid ContentType."
                }),
                           406,
                           GitLfsConsts.GIT_LFS_CONTENT_TYPE));
            }

            // Check permissions
            RepositoryAccessLevel accessLevelRequested;

            if (requestObj.Operation.Equals(LfsOperationNames.DOWNLOAD))
            {
                accessLevelRequested = RepositoryAccessLevel.Pull;
            }
            else if (requestObj.Operation.Equals(LfsOperationNames.UPLOAD))
            {
                accessLevelRequested = RepositoryAccessLevel.Push;
            }
            else
            {
                accessLevelRequested = RepositoryAccessLevel.Administer;
            }

            bool authorized = RepositoryPermissionService.HasPermission(userId, RepositoryRepository.GetRepository(repositoryName).Id, accessLevelRequested);

            if (!authorized)
            {
                return(GitLfsResult.From(
                           Newtonsoft.Json.JsonConvert.SerializeObject(
                               new BatchApiErrorResponse()
                {
                    Message = "You do not have the required permissions."
                }),
                           403,
                           GitLfsConsts.GIT_LFS_CONTENT_TYPE));
            }

            if (requestObj == null)
            {
                return(GitLfsResult.From(
                           Newtonsoft.Json.JsonConvert.SerializeObject(
                               new BatchApiErrorResponse()
                {
                    Message = "Cannot parse request body."
                }),
                           400,
                           GitLfsConsts.GIT_LFS_CONTENT_TYPE));
            }


            // Process the request.
            var    requestedTransferAdapters     = requestObj.Transfers ?? (new string[] { LfsTransferProviderNames.BASIC });
            string firstSupportedTransferAdapter = requestedTransferAdapters.FirstOrDefault(t => t.Equals(LfsTransferProviderNames.BASIC));

            if (firstSupportedTransferAdapter != null)
            {
                string transferAdapterToUse = firstSupportedTransferAdapter;
                var    requiredSpace        = DetermineRequiredDiskSpace(requestObj);
                if (StorageProvider.SufficientSpace(requiredSpace))
                {
                    BatchApiResponse responseObj = new BatchApiResponse()
                    {
                        Transfer = transferAdapterToUse,
                        Objects  = requestObj.Objects
                                   .Select(ro => new { ro, ActionFactory = new LfsActionFactory() })
                                   .Select(x => new BatchApiResponse.BatchApiObject()
                        {
                            Oid           = x.ro.Oid,
                            Size          = x.ro.Size,
                            Authenticated = true,
                            Actions       = x.ActionFactory.CreateBatchApiObjectActions(urlScheme, urlAuthority, requestApplicationPath, requestObj.Operation, x.ro, repositoryName, StorageProvider)
                        })
                                   .ToArray()
                    };


                    return(GitLfsResult.From(responseObj, 200, GitLfsConsts.GIT_LFS_CONTENT_TYPE));
                }
                else
                {
                    return(GitLfsResult.From(new BatchApiErrorResponse()
                    {
                        Message = "Insufficient storage space."
                    }, 507, GitLfsConsts.GIT_LFS_CONTENT_TYPE));
                }
            }
            else
            {
                // None of the requested transfer adapters are supported.
                return(GitLfsResult.From(new BatchApiErrorResponse()
                {
                    Message = $"None of the requested transfer adapters are supported."
                }, 400, GitLfsConsts.GIT_LFS_CONTENT_TYPE));
            }
        }
Esempio n. 27
0
        public ActionResult Detail(Guid id)
        {
            var mater = ConvertRepositoryModel(RepositoryRepository.GetRepository(id), User);

            if (mater != null)
            {
                mater.IsCurrentUserAdministrator = RepositoryPermissionService.HasPermission(User.Id(), mater.Id, RepositoryAccessLevel.Administer);
                SetGitUrls(mater);
            }
            ViewBag.ID     = id;
            ViewBag.Name   = mater.Name;
            ViewBag.GitUrl = mater.GitUrl;

            //using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, model.Name)))
            //{
            //    string defaultReferenceName;
            //    browser.BrowseTree(null, null, out defaultReferenceName);
            //    RouteData.Values.Add("encodedName", defaultReferenceName);
            //}
            bool includeDetails = Request.IsAjaxRequest();


            var name = PathEncoder.Decode(null);
            var path = PathEncoder.Decode(null);

            var repo = RepositoryRepository.GetRepository(id);
            var repositoryDetailModel = ConvertRepositoryModel(repo, User);


            using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name)))
            {
                string referenceName;
                var    files = browser.BrowseTree(name, path, out referenceName, includeDetails).ToList();
                PopulateBranchesData(browser, referenceName);
                var    readme    = files.FirstOrDefault(x => x.Name.Equals("readme.md", StringComparison.OrdinalIgnoreCase));
                string readmeTxt = string.Empty;
                if (readme != null)
                {
                    string refereceName;
                    var    blob = browser.BrowseBlob(name, readme.Path, out refereceName);
                    readmeTxt = blob.Text;
                }
                var model = new RepositoryTreeModel
                {
                    Name   = repo.Name,
                    Branch = name ?? referenceName,
                    Path   = path,
                    Readme = readmeTxt,
                    Logo   = new RepositoryLogoDetailModel(repo.Logo),
                    Files  = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name)
                };

                if (includeDetails)
                {
                    return(Json(model, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    PopulateBranchesData(browser, referenceName);
                    PopulateAddressBarData(path);
                    return(View(model));
                }
            }
        }
Esempio n. 28
0
        public ActionResult Clone(Guid id, RepositoryDetailModel model)
        {
            if (!User.IsInRole(Definitions.Roles.Administrator) && !UserConfiguration.Current.AllowUserRepositoryCreation)
            {
                return(RedirectToAction("Unauthorized", "Home"));
            }

            if (model != null && !String.IsNullOrEmpty(model.Name))
            {
                model.Name = Regex.Replace(model.Name, @"\s", "");
            }

            if (model != null && String.IsNullOrEmpty(model.Name))
            {
                ModelState.AddModelError("Name", Resources.Repository_Create_NameFailure);
            }
            else if (ModelState.IsValid)
            {
                var repo_model = ConvertRepositoryDetailModel(model);
                if (RepositoryRepository.Create(repo_model))
                {
                    string targetRepositoryPath = Path.Combine(UserConfiguration.Current.Repositories, model.Name);
                    if (!Directory.Exists(targetRepositoryPath))
                    {
                        var    source_repo          = RepositoryRepository.GetRepository(id);
                        string sourceRepositoryPath = Path.Combine(UserConfiguration.Current.Repositories, source_repo.Name);

                        LibGit2Sharp.CloneOptions options = new LibGit2Sharp.CloneOptions()
                        {
                            IsBare   = true,
                            Checkout = false
                        };

                        LibGit2Sharp.Repository.Clone(sourceRepositoryPath, targetRepositoryPath, options);

                        using (var repo = new LibGit2Sharp.Repository(targetRepositoryPath))
                        {
                            if (repo.Network.Remotes.Any(r => r.Name == "origin"))
                            {
                                repo.Network.Remotes.Remove("origin");
                            }
                        }

                        TempData["CloneSuccess"] = true;
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        RepositoryRepository.Delete(model.Id);
                        ModelState.AddModelError("", Resources.Repository_Create_DirectoryExists);
                    }
                }
                else
                {
                    ModelState.AddModelError("", Resources.Repository_Create_Failure);
                }
            }

            ViewBag.ID = id;
            PopulateCheckboxListData(ref model);
            return(View(model));
        }
Esempio n. 29
0
 public ActionResult Delete(Guid id)
 {
     return(View(ConvertRepositoryModel(RepositoryRepository.GetRepository(id))));
 }