This allows control over the default branch after clone, which is equivalent to running:
git symbolic-ref HEAD refs/heads/mybranch
import com.gitblit.models.FederationProposal;\r
import com.gitblit.models.FederationSet;\r
import com.gitblit.models.Metric;\r
+import com.gitblit.models.RefModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.ServerSettings;\r
import com.gitblit.models.ServerStatus;\r
model.mailingLists = new ArrayList<String>(Arrays.asList(config.getStringList(\r
"gitblit", null, "mailingList")));\r
}\r
+ model.defaultHead = JGitUtils.getDefaultHead(r);\r
+ model.availableHeads = new ArrayList<RefModel>();\r
+ model.availableHeads.addAll(JGitUtils.getLocalBranches(r, true, -1));\r
+ model.availableHeads.addAll(JGitUtils.getTags(r, true, -1));\r
r.close();\r
return model;\r
}\r
// update settings\r
if (r != null) {\r
updateConfiguration(r, repository);\r
+ if (repository.defaultHead != null) {\r
+ JGitUtils.setDefaultHead(r, repository.defaultHead.reference);\r
+ }\r
r.close();\r
}\r
}\r
public List<String> preReceiveScripts;\r
public List<String> postReceiveScripts;\r
public List<String> mailingLists;\r
+ public RefModel defaultHead;\r
+ public List<RefModel> availableHeads;\r
\r
private String displayName;\r
\r
return object;\r
}\r
\r
+ /**\r
+ * Returns the default HEAD for a repository. Normally returns the ref HEAD points to, but if HEAD points to nothing\r
+ * it returns null.\r
+ *\r
+ * @param repository\r
+ * @return the refmodel for HEAD or null\r
+ */\r
+ public static RefModel getDefaultHead(Repository repository) {\r
+ RefModel ref = null;\r
+ try {\r
+ Ref head = repository.getRef(Constants.HEAD);\r
+ if (head != null) {\r
+ Ref target = head.getTarget();\r
+ RevWalk rw = new RevWalk(repository);\r
+ ObjectId targetId = target.getObjectId();\r
+ if (targetId != null) {\r
+ RevObject object = rw.parseAny(targetId);\r
+ ref = new RefModel(target.getName(), target, object);\r
+ }\r
+ rw.dispose();\r
+ }\r
+ } catch (Throwable t) {\r
+ LOGGER.error("Failed to get default head!", t);\r
+ }\r
+ return ref;\r
+ }\r
+\r
+ /**\r
+ * Sets the default HEAD symbolic ref for a repository.\r
+ *\r
+ * @param repository\r
+ * @param ref\r
+ */\r
+ public static void setDefaultHead(Repository repository, Ref ref) {\r
+ try {\r
+ RefUpdate head = repository.updateRef(Constants.HEAD);\r
+ RefUpdate.Result result = head.link(ref.getName());\r
+ LOGGER.debug(MessageFormat.format("Set repository {0} default head to {1} ({2})",\r
+ repository.getDirectory().getAbsolutePath(), ref.getName(), result));\r
+ } catch (IOException e) {\r
+ LOGGER.error("Failed to set default head!", e);\r
+ }\r
+ }\r
+\r
/**\r
* Returns all refs grouped by their associated object id.\r
* \r
gb.sendProposal propose\r
gb.status = status\r
gb.origin = origin\r
+gb.defaultHead = default head\r
+gb.defaultHeadDescription = current branch after clone. e.g. refs/heads/master\r
gb.federationStrategy = federation strategy\r
gb.federationRegistration = federation registration\r
gb.federationResults = federation pull results\r
<tr><th><wicket:message key="gb.name"></wicket:message></th><td class="edit"><input class="span6" type="text" wicket:id="name" id="name" size="40" tabindex="1" /> <span class="help-inline"><wicket:message key="gb.nameDescription"></wicket:message></span></td></tr>\r
<tr><th><wicket:message key="gb.description"></wicket:message></th><td class="edit"><input class="span6" type="text" wicket:id="description" size="40" tabindex="2" /></td></tr>\r
<tr><th><wicket:message key="gb.origin"></wicket:message></th><td class="edit"><input class="span7" type="text" wicket:id="origin" size="80" tabindex="3" /></td></tr>\r
+ <tr><th><wicket:message key="gb.defaultHead"></wicket:message></th><td class="edit"><select wicket:id="defaultHead" /> <span class="help-inline"><wicket:message key="gb.defaultHeadDescription"></wicket:message></span></td></tr>\r
<tr><th><wicket:message key="gb.owner"></wicket:message></th><td class="edit"><select wicket:id="owner" tabindex="4" /> <span class="help-inline"><wicket:message key="gb.ownerDescription"></wicket:message></span></td></tr>\r
<tr><th><wicket:message key="gb.enableTickets"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="useTickets" tabindex="5" /> <span class="help-inline"><wicket:message key="gb.useTicketsDescription"></wicket:message></span></td></tr>\r
<tr><th><wicket:message key="gb.enableDocs"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="useDocs" tabindex="6" /> <span class="help-inline"><wicket:message key="gb.useDocsDescription"></wicket:message></span></td></tr>\r
import com.gitblit.GitBlit;\r
import com.gitblit.GitBlitException;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.RefModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.ArrayUtils;\r
form.add(new CheckBox("isFrozen"));\r
// TODO enable origin definition\r
form.add(new TextField<String>("origin").setEnabled(false/* isCreate */));\r
+ // enable alteration of the default branch after clone\r
+ form.add(new DropDownChoice<RefModel>("defaultHead", repositoryModel.availableHeads,\r
+ new RefModelRenderer()).setEnabled(GitBlitWebSession.get().canAdmin()));\r
\r
// federation strategies - remove ORIGIN choice if this repository has\r
// no origin.\r
}\r
}\r
\r
+ private class RefModelRenderer implements IChoiceRenderer<RefModel> {\r
+\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ @Override\r
+ public String getDisplayValue(RefModel type) {\r
+ return type.displayName;\r
+ }\r
+\r
+ @Override\r
+ public String getIdValue(RefModel type, int index) {\r
+ return type.getName();\r
+ }\r
+ }\r
+\r
private class AccessRestrictionRenderer implements IChoiceRenderer<AccessRestrictionType> {\r
\r
private static final long serialVersionUID = 1L;\r