diff --git a/Bonobo.Git.Server.Test/UnitTests/GitAuthorizeAttributeTest.cs b/Bonobo.Git.Server.Test/UnitTests/GitAuthorizeAttributeTest.cs
index e7081ef95..3a61af86e 100644
--- a/Bonobo.Git.Server.Test/UnitTests/GitAuthorizeAttributeTest.cs
+++ b/Bonobo.Git.Server.Test/UnitTests/GitAuthorizeAttributeTest.cs
@@ -10,10 +10,10 @@ public class GitAuthorizeAttributeTest
[TestMethod]
public void GetRepoPathTest()
{
- var repo = GitAuthorizeAttribute.GetRepoPath("/other/test.git/info/refs", "/other");
- Assert.AreEqual("test", repo);
- repo = GitAuthorizeAttribute.GetRepoPath("/test.git/info/refs", "/");
- Assert.AreEqual("test", repo);
+ var repo = GitAuthorizeAttribute.GetRepoPath("/other/test.git/info/refs", "/other", false);
+ Assert.AreEqual(@"\test.git", repo);
+ repo = GitAuthorizeAttribute.GetRepoPath("/test.git/info/refs", "/", false);
+ Assert.AreEqual("test.git", repo);
}
}
}
diff --git a/Bonobo.Git.Server/App_GlobalResources/Resources.Designer.cs b/Bonobo.Git.Server/App_GlobalResources/Resources.Designer.cs
index eafec560a..98c1278c7 100644
--- a/Bonobo.Git.Server/App_GlobalResources/Resources.Designer.cs
+++ b/Bonobo.Git.Server/App_GlobalResources/Resources.Designer.cs
@@ -19,7 +19,7 @@ namespace Bonobo.Git.Server.App_GlobalResources {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class Resources {
@@ -1331,6 +1331,24 @@ public static string Repository_Create_Informations {
}
}
+ ///
+ /// Looks up a localized string similar to Invalid root repo folder. Choose a different folder name..
+ ///
+ public static string Repository_Create_IsAControllerNameFailure {
+ get {
+ return ResourceManager.GetString("Repository_Create_IsAControllerNameFailure", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Must have an extension of .git.
+ ///
+ public static string Repository_Create_NameExtensionFailure {
+ get {
+ return ResourceManager.GetString("Repository_Create_NameExtensionFailure", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to "Name" shouldn't contain only whitespace characters..
///
diff --git a/Bonobo.Git.Server/App_GlobalResources/Resources.resx b/Bonobo.Git.Server/App_GlobalResources/Resources.resx
index 4fc18d6f0..d5c31f56b 100644
--- a/Bonobo.Git.Server/App_GlobalResources/Resources.resx
+++ b/Bonobo.Git.Server/App_GlobalResources/Resources.resx
@@ -957,4 +957,10 @@ The regular C# string formatting rules apply: To get {} in your link you need to
URL to a CSS file to use for the site. Site-relative (~) paths are supported.
+
+ Must have an extension of .git
+
+
+ Invalid root repo folder. Choose a different folder name.
+
\ No newline at end of file
diff --git a/Bonobo.Git.Server/App_Start/DoesControllerExistConstraint.cs b/Bonobo.Git.Server/App_Start/DoesControllerExistConstraint.cs
new file mode 100644
index 000000000..128bb6552
--- /dev/null
+++ b/Bonobo.Git.Server/App_Start/DoesControllerExistConstraint.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Web;
+using System.Web.Routing;
+
+namespace Bonobo.Git.Server.App_Start
+{
+ ///
+ /// Checks if controller and action is defined
+ ///
+ public class DoesControllerExistConstraint : IRouteConstraint
+ {
+ public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
+ {
+ if (routeDirection == RouteDirection.IncomingRequest)
+ {
+ var action = values["action"] as string;
+ var controller = values["controller"] as string;
+
+ return DoesControllerExist(controller, action);
+ }
+ else
+ return true;
+ }
+
+ public static bool DoesControllerExist(string controller, string action = null)
+ {
+ if (controller is null)
+ return false;
+
+ var controllerFullName = string.Format("Bonobo.Git.Server.Controllers.{0}Controller", controller);
+
+ var cont = Assembly.GetExecutingAssembly().GetType(controllerFullName);
+
+ try
+ {
+ return cont != null && (!string.IsNullOrEmpty(action) ? cont.GetMethod(action) != null : true);
+ }
+ catch(AmbiguousMatchException)
+ {
+ return true;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Bonobo.Git.Server/App_Start/RouteConfig.cs b/Bonobo.Git.Server/App_Start/RouteConfig.cs
index fafd1d6be..9febd6220 100644
--- a/Bonobo.Git.Server/App_Start/RouteConfig.cs
+++ b/Bonobo.Git.Server/App_Start/RouteConfig.cs
@@ -8,26 +8,6 @@ public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
- routes.MapRoute("SecureInfoRefs",
- "{repositoryName}.git/info/refs",
- new { controller = "Git", action = "SecureGetInfoRefs" },
- new { method = new HttpMethodConstraint("GET") });
-
- routes.MapRoute("SecureUploadPack",
- "{repositoryName}.git/git-upload-pack",
- new { controller = "Git", action = "SecureUploadPack" },
- new { method = new HttpMethodConstraint("POST") });
-
- routes.MapRoute("SecureReceivePack",
- "{repositoryName}.git/git-receive-pack",
- new { controller = "Git", action = "SecureReceivePack" },
- new { method = new HttpMethodConstraint("POST") });
-
- routes.MapRoute("GitBaseUrl",
- "{repositoryName}.git",
- new { controller = "Git", action = "GitUrl" },
- new { method = new HttpMethodConstraint("GET") });
-
routes.MapRoute("IndexRoute",
"{controller}/Index/",
new { action = "Index" });
@@ -90,11 +70,22 @@ public static void RegisterRoutes(RouteCollection routes)
routes.MapRoute("RepoCommits",
"Repository/Commits/{id}",
- new { controller = "Repository", action = "Commits", id = string.Empty});
+ new { controller = "Repository", action = "Commits", id = string.Empty });
routes.MapRoute("Default",
"{controller}/{action}/{id}",
- new { controller = "Home", action = "Index", id = String.Empty });
+ new { controller = "Home", action = "Index", id = String.Empty },
+ new { action = new DoesControllerExistConstraint() }); //Route constraints
+
+ routes.MapRoute("GitBaseUrl",
+ "{repositoryName}",
+ new { controller = "Git", action = "GitUrl" },
+ new { method = new HttpMethodConstraint("GET") });
+
+ routes.MapRoute(
+ "GitRepoRouting",
+ "{*url}",
+ new { controller = "Git", action = "Index" });
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
diff --git a/Bonobo.Git.Server/Attributes/FileNameAttribute.cs b/Bonobo.Git.Server/Attributes/FileNameAttribute.cs
index 731f4cdf1..eea8257fa 100644
--- a/Bonobo.Git.Server/Attributes/FileNameAttribute.cs
+++ b/Bonobo.Git.Server/Attributes/FileNameAttribute.cs
@@ -9,7 +9,7 @@ public override bool IsValid(object value)
{
if (value != null)
{
- return value.ToString().IndexOfAny(Path.GetInvalidFileNameChars()) == -1;
+ return value.ToString().IndexOfAny(Path.GetInvalidPathChars()) == -1;
}
return base.IsValid(null);
diff --git a/Bonobo.Git.Server/Attributes/GitAuthorizeAttribute.cs b/Bonobo.Git.Server/Attributes/GitAuthorizeAttribute.cs
index f0b547206..b44d10e65 100644
--- a/Bonobo.Git.Server/Attributes/GitAuthorizeAttribute.cs
+++ b/Bonobo.Git.Server/Attributes/GitAuthorizeAttribute.cs
@@ -9,6 +9,9 @@
using Microsoft.Practices.Unity;
using Bonobo.Git.Server.Helpers;
using Serilog;
+using System.Linq;
+using System.IO;
+using Bonobo.Git.Server.Configuration;
namespace Bonobo.Git.Server
{
@@ -26,10 +29,31 @@ public class GitAuthorizeAttribute : AuthorizeAttribute
[Dependency]
public IRepositoryRepository RepositoryRepository { get; set; }
- public static string GetRepoPath(string path, string applicationPath)
+ public static string GetRepoPath(string url, string applicationPath, bool checkDirectory=true)
{
- var repo = path.Replace(applicationPath, "").Replace("/","");
- return repo.Substring(0, repo.IndexOf(".git"));
+ var gitStartIndex = url.IndexOf(".git");
+ if (gitStartIndex >= 0)
+ {
+ var repositoryPath = url.Substring(0, gitStartIndex + 4);
+
+ repositoryPath = applicationPath.Length ==1 ? repositoryPath.TrimStart(applicationPath.ToCharArray()) : repositoryPath.Replace(applicationPath, "");
+
+ repositoryPath = repositoryPath.Replace('/', '\\').TrimEnd('\\');
+
+ if (checkDirectory)
+ {
+ string path = Path.Combine(UserConfiguration.Current.Repositories, repositoryPath);
+
+ if (Directory.Exists(path))
+ {
+ return repositoryPath;
+ }
+ }
+ else
+ return repositoryPath;
+ }
+
+ return null;
}
public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
@@ -42,6 +66,7 @@ public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterC
HttpContextBase httpContext = filterContext.HttpContext;
string incomingRepoName = GetRepoPath(httpContext.Request.Path, httpContext.Request.ApplicationPath);
+
string repoName = Repository.NormalizeRepositoryName(incomingRepoName, RepositoryRepository);
// Add header to prevent redirection to login page even if we fail auth later (see IAuthenticationProvider.Configure)
diff --git a/Bonobo.Git.Server/Bonobo.Git.Server.csproj b/Bonobo.Git.Server/Bonobo.Git.Server.csproj
index 32725905f..840f3783a 100644
--- a/Bonobo.Git.Server/Bonobo.Git.Server.csproj
+++ b/Bonobo.Git.Server/Bonobo.Git.Server.csproj
@@ -1,8 +1,8 @@
+
-
@@ -47,6 +47,8 @@
prompt
4
false
+ true
+ true
pdbonly
@@ -82,9 +84,9 @@
..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll
True
-
- ..\packages\LibGit2Sharp.0.23.1\lib\net40\LibGit2Sharp.dll
- True
+
+ ..\packages\LibGit2Sharp.0.26.2\lib\net46\LibGit2Sharp.dll
+ False
..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
@@ -272,6 +274,7 @@
+
@@ -703,7 +706,9 @@
-
+
+ Designer
+
@@ -769,10 +774,10 @@ xcopy/s /y /d "$(SolutionDir)packages\LibGit2Sharp.0.21.0.176\lib\net40\NativeBi
This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
+
\ No newline at end of file
diff --git a/Bonobo.Git.Server/Configuration/AuthenticationSettings.cs b/Bonobo.Git.Server/Configuration/AuthenticationSettings.cs
index e20347367..8a9d4c090 100644
--- a/Bonobo.Git.Server/Configuration/AuthenticationSettings.cs
+++ b/Bonobo.Git.Server/Configuration/AuthenticationSettings.cs
@@ -8,6 +8,7 @@ public static class AuthenticationSettings
public static string MembershipService { get; private set; }
public static string AuthenticationProvider { get; private set; }
public static bool ImportWindowsAuthUsersAsAdmin { get; private set; }
+ public static string EmailDomain { get; }
public static bool DemoModeActive { get; private set; }
static AuthenticationSettings()
@@ -15,6 +16,7 @@ static AuthenticationSettings()
MembershipService = ConfigurationManager.AppSettings["MembershipService"];
AuthenticationProvider = ConfigurationManager.AppSettings["AuthenticationProvider"];
ImportWindowsAuthUsersAsAdmin = Convert.ToBoolean(ConfigurationManager.AppSettings["ImportWindowsAuthUsersAsAdmin"]);
+ EmailDomain = ConfigurationManager.AppSettings["EmailDomain"];
DemoModeActive = Convert.ToBoolean(ConfigurationManager.AppSettings["demoModeActive"]);
}
}
diff --git a/Bonobo.Git.Server/Controllers/AccountController.cs b/Bonobo.Git.Server/Controllers/AccountController.cs
index 72b1d847d..b11dfbe49 100644
--- a/Bonobo.Git.Server/Controllers/AccountController.cs
+++ b/Bonobo.Git.Server/Controllers/AccountController.cs
@@ -187,10 +187,10 @@ public ActionResult Edit(UserEditModel model)
public ActionResult CreateADUser()
{
var efms = MembershipService as EFMembershipService;
-
+
if ((!Request.IsAuthenticated) || efms == null)
{
- Log.Warning("CreateADUser: can't run IsAuth: {IsAuth}, MemServ {MemServ}",
+ Log.Warning("CreateADUser: can't run IsAuth: {IsAuth}, MemServ {MemServ}",
Request.IsAuthenticated,
MembershipService.GetType());
return RedirectToAction("Unauthorized", "Home");
@@ -201,6 +201,13 @@ public ActionResult CreateADUser()
if (adUser != null)
{
var userId = adUser.Guid.GetValueOrDefault(Guid.NewGuid());
+
+ if (string.IsNullOrEmpty(adUser.EmailAddress))
+ {
+ var username = credentials.Split('\\')[1];
+ adUser.EmailAddress = $"{username}@{AuthenticationSettings.EmailDomain}";
+ }
+
if (MembershipService.CreateUser(credentials, Guid.NewGuid().ToString(), adUser.GivenName, adUser.Surname, adUser.EmailAddress, userId))
{
// 2 because we just added the user and there is the default admin user.
@@ -209,7 +216,7 @@ public ActionResult CreateADUser()
Log.Information("Making AD user {User} into an admin", credentials);
var id = MembershipService.GetUserModel(credentials).Id;
- RoleProvider.AddUserToRoles(id, new[] {Definitions.Roles.Administrator});
+ RoleProvider.AddUserToRoles(id, new[] { Definitions.Roles.Administrator });
// Add the administrator role to the Identity/cookie
var Identity = (ClaimsIdentity)User.Identity;
diff --git a/Bonobo.Git.Server/Controllers/GitController.cs b/Bonobo.Git.Server/Controllers/GitController.cs
index 91bd95566..f68814126 100644
--- a/Bonobo.Git.Server/Controllers/GitController.cs
+++ b/Bonobo.Git.Server/Controllers/GitController.cs
@@ -31,7 +31,43 @@ public class GitController : Controller
[Dependency]
public IGitService GitService { get; set; }
- public ActionResult SecureGetInfoRefs(String repositoryName, String service)
+ public ActionResult Index(string url)
+ {
+ if (url != null)
+ {
+ var gitStartIndex = url.IndexOf(".git");
+ if (gitStartIndex >= 0)
+ {
+ var repositoryPath = url.Substring(0, gitStartIndex + 4).Replace('/', '\\');
+
+ string path = Path.Combine(UserConfiguration.Current.Repositories, repositoryPath);
+
+ if (Directory.Exists(path))
+ {
+ return RedirectGitQuery(url, repositoryPath);
+ }
+ }
+ }
+
+ return RedirectToAction("Index", "Home");
+ }
+
+ private ActionResult RedirectGitQuery(string url, string repositoryPath)
+ {
+ var queryString = Request.QueryString;
+
+ if (url.EndsWith("/info/refs"))
+ return SecureGetInfoRefs(repositoryPath, queryString["service"]);
+ else if (url.EndsWith("/git-upload-pack"))
+ return SecureUploadPack(repositoryPath);
+ else if (url.EndsWith("/git-receive-pack"))
+ return SecureReceivePack(repositoryPath);
+ else
+ return new HttpNotFoundResult();
+ }
+
+ [HttpGet]
+ private ActionResult SecureGetInfoRefs(String repositoryName, String service)
{
bool isPush = String.Equals("git-receive-pack", service, StringComparison.OrdinalIgnoreCase);
@@ -72,7 +108,7 @@ public ActionResult SecureGetInfoRefs(String repositoryName, String service)
}
[HttpPost]
- public ActionResult SecureUploadPack(String repositoryName)
+ private ActionResult SecureUploadPack(String repositoryName)
{
if (!RepositoryIsValid(repositoryName))
{
@@ -90,7 +126,7 @@ public ActionResult SecureUploadPack(String repositoryName)
}
[HttpPost]
- public ActionResult SecureReceivePack(String repositoryName)
+ private ActionResult SecureReceivePack(String repositoryName)
{
if (!RepositoryIsValid(repositoryName))
{
diff --git a/Bonobo.Git.Server/Controllers/RepositoryController.cs b/Bonobo.Git.Server/Controllers/RepositoryController.cs
index a4d52ee3b..c690a154e 100644
--- a/Bonobo.Git.Server/Controllers/RepositoryController.cs
+++ b/Bonobo.Git.Server/Controllers/RepositoryController.cs
@@ -16,6 +16,8 @@
using Microsoft.Practices.Unity;
using MimeTypes;
using System.Security.Principal;
+using Bonobo.Git.Server.App_Start;
+using System.Net.NetworkInformation;
namespace Bonobo.Git.Server.Controllers
{
@@ -143,15 +145,27 @@ public ActionResult Create(RepositoryDetailModel model)
return RedirectToAction("Unauthorized", "Home");
}
- if (model != null && !String.IsNullOrEmpty(model.Name))
+ bool isAControllerPath = false;
+ if (model != null && !string.IsNullOrEmpty(model.Name))
{
model.Name = Regex.Replace(model.Name, @"\s", "");
+ model.Name = model.Name.Replace('/', '\\');
+ var rootDir = model.Name.Split('\\').FirstOrDefault();
+ isAControllerPath = DoesControllerExistConstraint.DoesControllerExist(rootDir);
}
- if (model != null && String.IsNullOrEmpty(model.Name))
+ if (model != null && string.IsNullOrEmpty(model.Name))
{
ModelState.AddModelError("Name", Resources.Repository_Create_NameFailure);
}
+ else if (model != null && !model.Name.Contains(".git"))
+ {
+ ModelState.AddModelError("Name", Resources.Repository_Create_NameExtensionFailure);
+ }
+ else if (model != null && isAControllerPath)
+ {
+ ModelState.AddModelError("Name", Resources.Repository_Create_IsAControllerNameFailure);
+ }
else if (ModelState.IsValid)
{
@@ -234,19 +248,35 @@ public ActionResult Detail(Guid id)
///
void SetGitUrls(RepositoryDetailModel model)
{
+ var host = Request.Url.Host;
+
+ if (host == "localhost" && Request.ServerVariables["remote_host"] != "::1")
+ {
+ var networkInfo = IPGlobalProperties.GetIPGlobalProperties();
+
+ if(!string.IsNullOrEmpty(networkInfo.DomainName))
+ host = $"{networkInfo.HostName}.{networkInfo.DomainName}";
+ else
+ host = $"{networkInfo.HostName}";
+ }
+
string serverAddress = System.Configuration.ConfigurationManager.AppSettings["GitServerPath"]
?? string.Format("{0}://{1}{2}{3}/",
Request.Url.Scheme,
- Request.Url.Host,
+ host,
(Request.Url.IsDefaultPort ? "" : (":" + Request.Url.Port)),
Request.ApplicationPath == "/" ? "" : Request.ApplicationPath
);
- model.GitUrl = String.Concat(serverAddress, model.Name, ".git");
+ var path = model.Name.Replace('\\', '/');
+
+ model.GitUrl = string.Concat(serverAddress, path);
if (User.Identity.IsAuthenticated)
{
+ var usermodel = MembershipService.GetUserModel(User.Username());
+
model.PersonalGitUrl =
- String.Concat(serverAddress.Replace("://", "://" + Uri.EscapeDataString(User.Username()) + "@"), model.Name, ".git");
+ string.Concat(serverAddress.Replace("://", "://" + Uri.EscapeDataString(usermodel.Username) + "@"), path);
}
}
@@ -549,12 +579,12 @@ public ActionResult Clone(Guid id, RepositoryDetailModel model)
return RedirectToAction("Unauthorized", "Home");
}
- if (model != null && !String.IsNullOrEmpty(model.Name))
+ if (model != null && !string.IsNullOrEmpty(model.Name))
{
model.Name = Regex.Replace(model.Name, @"\s", "");
}
- if (model != null && String.IsNullOrEmpty(model.Name))
+ if (model != null && string.IsNullOrEmpty(model.Name))
{
ModelState.AddModelError("Name", Resources.Repository_Create_NameFailure);
}
diff --git a/Bonobo.Git.Server/Controllers/SettingsController.cs b/Bonobo.Git.Server/Controllers/SettingsController.cs
index 54a9b9616..e33267130 100644
--- a/Bonobo.Git.Server/Controllers/SettingsController.cs
+++ b/Bonobo.Git.Server/Controllers/SettingsController.cs
@@ -10,6 +10,7 @@
using Bonobo.Git.Server.App_GlobalResources;
using Bonobo.Git.Server.Configuration;
using Bonobo.Git.Server.Models;
+using Serilog;
namespace Bonobo.Git.Server.Controllers
{
@@ -76,6 +77,7 @@ public ActionResult Index(GlobalSettingsModel model)
}
else
{
+ Log.Error($"Is Path Rooted: {Path.IsPathRooted(model.RepositoryPath)} Path: {model.RepositoryPath}");
ModelState.AddModelError("RepositoryPath", Resources.Settings_RepositoryPathNotExists);
}
}
diff --git a/Bonobo.Git.Server/Data/Update/ADBackend/UpdateADBackend.cs b/Bonobo.Git.Server/Data/Update/ADBackend/UpdateADBackend.cs
index ba8986aad..92313cb25 100644
--- a/Bonobo.Git.Server/Data/Update/ADBackend/UpdateADBackend.cs
+++ b/Bonobo.Git.Server/Data/Update/ADBackend/UpdateADBackend.cs
@@ -80,7 +80,7 @@ private static bool BackendSubDirectoryNeedsUpdating(string backendDirectory,
try
{
var x = JsonConvert.DeserializeObject(File.ReadAllText(jsonfile.FullName));
- if (x.Id == Guid.Empty)
+ if (x == null || x.Id == Guid.Empty)
{
// No GUID - we need to convert
return true;
diff --git a/Bonobo.Git.Server/Data/Update/RepositorySynchronizer.cs b/Bonobo.Git.Server/Data/Update/RepositorySynchronizer.cs
index 08fec60f4..df2c8879e 100644
--- a/Bonobo.Git.Server/Data/Update/RepositorySynchronizer.cs
+++ b/Bonobo.Git.Server/Data/Update/RepositorySynchronizer.cs
@@ -1,6 +1,8 @@
-using Bonobo.Git.Server.Configuration;
+using Bonobo.Git.Server.App_Start;
+using Bonobo.Git.Server.Configuration;
using Bonobo.Git.Server.Models;
using LibGit2Sharp;
+using Serilog;
using System;
using System.Collections.Generic;
using System.IO;
@@ -23,16 +25,23 @@ private void CheckForNewRepositories()
{
if (!Directory.Exists(UserConfiguration.Current.Repositories))
{
+ Log.Error($"Repo root doesn't exist: {UserConfiguration.Current.Repositories}");
// We don't want an exception if the repo dir no longer exists,
// as this would make it impossible to start the server
return;
}
- IEnumerable directories = Directory.EnumerateDirectories(UserConfiguration.Current.Repositories);
+ IEnumerable directories = Directory.EnumerateDirectories(UserConfiguration.Current.Repositories, "*.git", SearchOption.AllDirectories);
foreach (string directory in directories)
{
- string name = Path.GetFileName(directory);
+ var repoPath = directory.Remove(0, UserConfiguration.Current.Repositories.Length).TrimStart('\\');
+ var rootDir = repoPath.Split('\\').FirstOrDefault();
- RepositoryModel repository = _repositoryRepository.GetRepository(name);
+ Log.Debug($"Repo {repoPath}");
+
+ if (DoesControllerExistConstraint.DoesControllerExist(rootDir))
+ continue; //Do not load as a valid repo
+
+ RepositoryModel repository = _repositoryRepository.GetRepository(repoPath);
if (repository == null)
{
if (LibGit2Sharp.Repository.IsValid(directory))
@@ -40,7 +49,7 @@ private void CheckForNewRepositories()
repository = new RepositoryModel();
repository.Id = Guid.NewGuid();
repository.Description = "Discovered in file system.";
- repository.Name = name;
+ repository.Name = repoPath;
repository.AnonymousAccess = false;
repository.Users = new UserModel[0];
repository.Teams = new TeamModel[0];
diff --git a/Bonobo.Git.Server/Models/RepositoryModels.cs b/Bonobo.Git.Server/Models/RepositoryModels.cs
index ae815bedc..c814815c2 100644
--- a/Bonobo.Git.Server/Models/RepositoryModels.cs
+++ b/Bonobo.Git.Server/Models/RepositoryModels.cs
@@ -50,7 +50,7 @@ public bool NameIsValid
{
// Check for an exact match, not just a substring hit - based on RegularExpressionAttribute
Match match = Regex.Match(Name, NameValidityRegex);
- return match.Success && match.Index == 0 && match.Length == Name.Length;
+ return match.Success;
}
}
@@ -80,7 +80,7 @@ public void EnsureCollectionsAreValid()
}
}
- public const string NameValidityRegex = @"([\w\.-])*([\w])$";
+ public const string NameValidityRegex = @".*([\w\.-])*([\w])$";
}
public class RepositoryDetailModel
diff --git a/Bonobo.Git.Server/web.config b/Bonobo.Git.Server/web.config
index c41892d6a..e897b66b6 100644
--- a/Bonobo.Git.Server/web.config
+++ b/Bonobo.Git.Server/web.config
@@ -20,9 +20,14 @@
-->
+
+
+ -->
+
+
+
+