From f2c4fa73e484e7abf70a2969def6fd79c3821284 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 18 Jun 2013 21:52:09 -0400
Subject: [PATCH] Ignore orphaned .git folder in repositories folder (issue-256)
---
src/main/java/com/gitblit/GitBlit.java | 72 +++++++++++++++++++++++++++++++++--
1 files changed, 67 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index c5616d9..ecd4662 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -239,6 +239,26 @@
}
/**
+ * Determine if this Gitblit instance is actively serving git repositories
+ * or if it is merely a repository viewer.
+ *
+ * @return true if Gitblit is serving repositories
+ */
+ public static boolean isServingRepositories() {
+ return getBoolean(Keys.git.enableGitServlet, true) || (getInteger(Keys.git.daemonPort, 0) > 0);
+ }
+
+ /**
+ * Determine if this Gitblit instance is actively serving git repositories
+ * or if it is merely a repository viewer.
+ *
+ * @return true if Gitblit is serving repositories
+ */
+ public static boolean isSendingMail() {
+ return self().mailExecutor.isReady();
+ }
+
+ /**
* Returns the preferred timezone for the Gitblit instance.
*
* @return a timezone
@@ -291,6 +311,19 @@
*/
public static int getInteger(String key, int defaultValue) {
return self().settings.getInteger(key, defaultValue);
+ }
+
+ /**
+ * Returns the integer list for the specified key. If the key does not
+ * exist or the value for the key can not be interpreted as an integer, an
+ * empty list is returned.
+ *
+ * @see IStoredSettings.getIntegers(String key)
+ * @param key
+ * @return key value or defaultValue
+ */
+ public static List<Integer> getIntegers(String key) {
+ return self().settings.getIntegers(key);
}
/**
@@ -648,7 +681,15 @@
* @return true if the user service supports credential changes
*/
public boolean supportsCredentialChanges(UserModel user) {
- return (user != null && user.isLocalAccount()) || userService.supportsCredentialChanges();
+ if (user == null) {
+ return false;
+ } else if (!Constants.EXTERNAL_ACCOUNT.equals(user.password)) {
+ // credentials likely maintained by Gitblit
+ return userService.supportsCredentialChanges();
+ } else {
+ // credentials are externally maintained
+ return false;
+ }
}
/**
@@ -794,11 +835,22 @@
Principal principal = httpRequest.getUserPrincipal();
if (principal != null) {
String username = principal.getName();
- if (StringUtils.isEmpty(username)) {
+ if (!StringUtils.isEmpty(username)) {
UserModel user = getUserModel(username);
if (user != null) {
+ // existing user
flagWicketSession(AuthenticationType.CONTAINER);
logger.debug(MessageFormat.format("{0} authenticated by servlet container principal from {1}",
+ user.username, httpRequest.getRemoteAddr()));
+ return user;
+ } else if (settings.getBoolean(Keys.realm.container.autoCreateAccounts, true)) {
+ // auto-create user from an authenticated container principal
+ user = new UserModel(username.toLowerCase());
+ user.displayName = username;
+ user.password = Constants.EXTERNAL_ACCOUNT;
+ userService.updateUserModel(user);
+ flagWicketSession(AuthenticationType.CONTAINER);
+ logger.debug(MessageFormat.format("{0} authenticated and created by servlet container principal from {1}",
user.username, httpRequest.getRemoteAddr()));
return user;
} else {
@@ -877,7 +929,10 @@
if (userService == null) {
return;
}
- if (userService.supportsCookies()) {
+ GitBlitWebSession session = GitBlitWebSession.get();
+ boolean standardLogin = session.authenticationType.isStandard();
+
+ if (userService.supportsCookies() && standardLogin) {
Cookie userCookie;
if (user == null) {
// clear cookie for logout
@@ -1906,6 +1961,8 @@
Constants.CONFIG_GITBLIT, null, "mailingList")));
model.indexedBranches = new ArrayList<String>(Arrays.asList(config.getStringList(
Constants.CONFIG_GITBLIT, null, "indexBranch")));
+ model.metricAuthorExclusions = new ArrayList<String>(Arrays.asList(config.getStringList(
+ Constants.CONFIG_GITBLIT, null, "metricAuthorExclusions")));
// Custom defined properties
model.customFields = new LinkedHashMap<String, String>();
@@ -2432,6 +2489,7 @@
updateList(config, "postReceiveScript", repository.postReceiveScripts);
updateList(config, "mailingList", repository.mailingLists);
updateList(config, "indexBranch", repository.indexedBranches);
+ updateList(config, "metricAuthorExclusions", repository.metricAuthorExclusions);
// User Defined Properties
if (repository.customFields != null) {
@@ -2973,7 +3031,9 @@
if (repository != null) {
for (String teamname : userService.getTeamnamesForRepositoryRole(repository.name)) {
TeamModel team = userService.getTeamModel(teamname);
- scripts.addAll(team.preReceiveScripts);
+ if (!ArrayUtils.isEmpty(team.preReceiveScripts)) {
+ scripts.addAll(team.preReceiveScripts);
+ }
}
}
return new ArrayList<String>(scripts);
@@ -3023,7 +3083,9 @@
if (repository != null) {
for (String teamname : userService.getTeamnamesForRepositoryRole(repository.name)) {
TeamModel team = userService.getTeamModel(teamname);
- scripts.addAll(team.postReceiveScripts);
+ if (!ArrayUtils.isEmpty(team.postReceiveScripts)) {
+ scripts.addAll(team.postReceiveScripts);
+ }
}
}
return new ArrayList<String>(scripts);
--
Gitblit v1.9.1