コード例 #1
0
        public ActionResult Create(CreateRepoRequest request)
        {
            string repoPath = null;

            if (ModelState.IsValid)
            {
                var invalid = Path.GetInvalidFileNameChars();

                if (request.RepoName.Any(c => invalid.Contains(c)))
                {
                    ModelState.AddModelError("RepoName", "Repository name must be a valid folder name.");
                }
                else
                {
                    var resourceInfo = this.FileManager.GetResourceInfo(request.RepoName);

                    if (resourceInfo.FileSystemInfo == null)
                    {
                        ModelState.AddModelError("RepoName", "You do not have permission to create this repository.");
                    }

                    if (resourceInfo.Type != ResourceType.NotFound)
                    {
                        ModelState.AddModelError("RepoName", "There is already an object at that location.");
                    }

                    repoPath = resourceInfo.FullPath;
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(request));
            }

            try
            {
                GitUtilities.CreateRepo(repoPath);
            }
            catch (GitErrorException ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(request));
            }

            io::File.WriteAllText(Path.Combine(repoPath, "description"), request.Description);

            GitUtilities.ExecutePostCreateHook(repoPath);

            return(RedirectToAction("ViewRepo", "Browse", new { repo = request.RepoName }));
        }