model.mailingLists = new ArrayList<String>(Arrays.asList(config.getStringList(\r
"gitblit", null, "mailingList")));\r
}\r
- model.defaultHead = JGitUtils.getSymbolicHeadTarget(r);\r
- model.availableHeads = JGitUtils.getAvailableHeadTargets(r);\r
+ model.HEAD = JGitUtils.getHEADRef(r);\r
+ model.availableRefs = JGitUtils.getAvailableHeadTargets(r);\r
r.close();\r
return model;\r
}\r
if (r != null) {\r
updateConfiguration(r, repository);\r
// only update symbolic head if it changes\r
- String currentHead = JGitUtils.getSymbolicHeadTarget(r);\r
- if (!StringUtils.isEmpty(repository.defaultHead) &&\r
- !repository.defaultHead.equals(currentHead)) {\r
+ String currentRef = JGitUtils.getHEADRef(r);\r
+ if (!StringUtils.isEmpty(repository.HEAD) && !repository.HEAD.equals(currentRef)) {\r
logger.info(MessageFormat.format("Relinking {0} HEAD from {1} to {2}", \r
- repository.name, currentHead, repository.defaultHead));\r
- JGitUtils.setSymbolicHeadTarget(r, repository.defaultHead);\r
-\r
- // clear the cache\r
- clearRepositoryCache(repository.name);\r
+ repository.name, currentRef, repository.HEAD));\r
+ if (JGitUtils.setHEADtoRef(r, repository.HEAD)) {\r
+ // clear the cache\r
+ clearRepositoryCache(repository.name);\r
+ }\r
}\r
\r
// close the repository object\r
\r
private JComboBox ownerField;\r
\r
- private JComboBox defaultHeadField;\r
+ private JComboBox headRefField;\r
\r
private JPalette<String> usersPalette;\r
\r
anRepository.origin == null ? "" : anRepository.origin, 40);\r
originField.setEditable(false);\r
\r
- if (ArrayUtils.isEmpty(anRepository.availableHeads)) {\r
- defaultHeadField = new JComboBox();\r
- defaultHeadField.setEnabled(false); \r
+ if (ArrayUtils.isEmpty(anRepository.availableRefs)) {\r
+ headRefField = new JComboBox();\r
+ headRefField.setEnabled(false); \r
} else {\r
- defaultHeadField = new JComboBox(\r
- anRepository.availableHeads.toArray());\r
- defaultHeadField.setSelectedItem(anRepository.defaultHead);\r
+ headRefField = new JComboBox(\r
+ anRepository.availableRefs.toArray());\r
+ headRefField.setSelectedItem(anRepository.HEAD);\r
}\r
\r
ownerField = new JComboBox();\r
descriptionField));\r
fieldsPanel\r
.add(newFieldPanel(Translation.get("gb.origin"), originField));\r
- fieldsPanel.add(newFieldPanel(Translation.get("gb.defaultHead"),\r
- defaultHeadField));\r
+ fieldsPanel.add(newFieldPanel(Translation.get("gb.head"), headRefField));\r
fieldsPanel.add(newFieldPanel(Translation.get("gb.owner"), ownerField));\r
\r
fieldsPanel.add(newFieldPanel(Translation.get("gb.enableTickets"),\r
repository.description = descriptionField.getText();\r
repository.owner = ownerField.getSelectedItem() == null ? null\r
: ownerField.getSelectedItem().toString();\r
- repository.defaultHead = defaultHeadField.getSelectedItem() == null ? null\r
- : defaultHeadField.getSelectedItem().toString();\r
+ repository.HEAD = headRefField.getSelectedItem() == null ? null\r
+ : headRefField.getSelectedItem().toString();\r
repository.useTickets = useTickets.isSelected();\r
repository.useDocs = useDocs.isSelected();\r
repository.showRemoteBranches = showRemoteBranches.isSelected();\r
public List<String> preReceiveScripts;\r
public List<String> postReceiveScripts;\r
public List<String> mailingLists;\r
- public String defaultHead;\r
- public List<String> availableHeads;\r
+ public String HEAD;\r
+ public List<String> availableRefs;\r
\r
private String displayName;\r
\r
* no match is found, the SHA1 is returned.\r
*\r
* @param repository\r
- * @return the ref name or the SHA1 for detached HEADs\r
+ * @return the ref name or the SHA1 for a detached HEAD\r
*/\r
- public static String getSymbolicHeadTarget(Repository repository) {\r
+ public static String getHEADRef(Repository repository) {\r
String target = null;\r
try {\r
target = repository.getFullBranch();\r
}\r
\r
/**\r
- * Sets the HEAD symbolic ref name for a repository. The HEAD will\r
- * be detached if the name does not reference a branch.\r
+ * Sets the symbolic ref HEAD to the specified target ref. The\r
+ * HEAD will be detached if the target ref is not a branch.\r
*\r
* @param repository\r
- * @param name\r
+ * @param targetRef\r
+ * @return true if successful\r
*/\r
- public static void setSymbolicHeadTarget(Repository repository, String name) {\r
+ public static boolean setHEADtoRef(Repository repository, String targetRef) {\r
try {\r
- boolean detach = !name.startsWith(Constants.R_HEADS); // detach if not a branch\r
+ // detach HEAD if target ref is not a branch\r
+ boolean detach = !targetRef.startsWith(Constants.R_HEADS);\r
RefUpdate.Result result;\r
RefUpdate head = repository.updateRef(Constants.HEAD, detach);\r
if (detach) { // Tag\r
- RevCommit commit = getCommit(repository, name);\r
+ RevCommit commit = getCommit(repository, targetRef);\r
head.setNewObjectId(commit.getId());\r
result = head.forceUpdate();\r
} else {\r
- result = head.link(name);\r
+ result = head.link(targetRef);\r
}\r
switch (result) {\r
case NEW:\r
case FORCED:\r
case NO_CHANGE:\r
case FAST_FORWARD:\r
- break;\r
+ return true; \r
default:\r
- LOGGER.error(MessageFormat.format("{0} symbolic HEAD update to {1} returned result {2}",\r
- repository.getDirectory().getAbsolutePath(), name, result));\r
+ LOGGER.error(MessageFormat.format("{0} HEAD update to {1} returned result {2}",\r
+ repository.getDirectory().getAbsolutePath(), targetRef, result));\r
}\r
} catch (Throwable t) {\r
- error(t, repository, "{0} failed to set symbolic HEAD to {1}", name);\r
+ error(t, repository, "{0} failed to set HEAD to {1}", targetRef);\r
}\r
+ return false;\r
}\r
\r
/**\r
- * Get the full branch and tag ref names for any potential symbolic head targets.\r
+ * Get the full branch and tag ref names for any potential HEAD targets.\r
*\r
* @param repository\r
* @return a list of ref names\r
*/\r
public static List<String> getAvailableHeadTargets(Repository repository) {\r
List<String> targets = new ArrayList<String>();\r
- List<RefModel> branchModels = JGitUtils.getLocalBranches(repository, true, -1);\r
- if (branchModels.size() > 0) {\r
- for (RefModel branchModel : branchModels) {\r
- targets.add(branchModel.getName());\r
- }\r
+ for (RefModel branchModel : JGitUtils.getLocalBranches(repository, true, -1)) {\r
+ targets.add(branchModel.getName());\r
}\r
- List<RefModel> tagModels = JGitUtils.getTags(repository, true, -1);\r
- if (tagModels.size() > 0) {\r
- for (RefModel tagModel : tagModels) {\r
- targets.add(tagModel.getName());\r
- }\r
+\r
+ for (RefModel tagModel : JGitUtils.getTags(repository, true, -1)) {\r
+ targets.add(tagModel.getName());\r
}\r
return targets;\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.headRefDescription = change the ref that HEAD links to. 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" tabindex="4" /> <span class="help-inline"><wicket:message key="gb.defaultHeadDescription"></wicket:message></span></td></tr>\r
+ <tr><th><wicket:message key="gb.head"></wicket:message></th><td class="edit"><select wicket:id="HEAD" tabindex="4" /> <span class="help-inline"><wicket:message key="gb.headRefDescription"></wicket:message></span></td></tr>\r
<tr><th><wicket:message key="gb.owner"></wicket:message></th><td class="edit"><select wicket:id="owner" tabindex="5" /> <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="6" /> <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="7" /> <span class="help-inline"><wicket:message key="gb.useDocsDescription"></wicket:message></span></td></tr>\r
form.add(new TextField<String>("origin").setEnabled(false/* isCreate */));\r
\r
// allow relinking HEAD to a branch or tag other than master on edit repository\r
- List<String> availableHeads = new ArrayList<String>();\r
- if (!ArrayUtils.isEmpty(repositoryModel.availableHeads)) {\r
- availableHeads.addAll(repositoryModel.availableHeads);\r
+ List<String> availableRefs = new ArrayList<String>();\r
+ if (!ArrayUtils.isEmpty(repositoryModel.availableRefs)) {\r
+ availableRefs.addAll(repositoryModel.availableRefs);\r
}\r
- form.add(new DropDownChoice<String>("defaultHead", availableHeads).setEnabled(!isCreate));\r
+ form.add(new DropDownChoice<String>("HEAD", availableRefs).setEnabled(!isCreate));\r
\r
// federation strategies - remove ORIGIN choice if this repository has\r
// no origin.\r
assertEquals("183474d554e6f68478a02d9d7888b67a9338cdff", list.get(0).notesRef\r
.getReferencedObjectId().getName());\r
}\r
+ \r
+ @Test\r
+ public void testRelinkHEAD() throws Exception {\r
+ Repository repository = GitBlitSuite.getJGitRepository();\r
+ // confirm HEAD is master\r
+ String currentRef = JGitUtils.getHEADRef(repository);\r
+ assertEquals("refs/heads/master", currentRef);\r
+ List<String> availableHeads = JGitUtils.getAvailableHeadTargets(repository);\r
+ assertTrue(availableHeads.size() > 0);\r
+ \r
+ // set HEAD to stable-1.2\r
+ JGitUtils.setHEADtoRef(repository, "refs/heads/stable-1.2");\r
+ currentRef = JGitUtils.getHEADRef(repository);\r
+ assertEquals("refs/heads/stable-1.2", currentRef);\r
+\r
+ // restore HEAD to master\r
+ JGitUtils.setHEADtoRef(repository, "refs/heads/master");\r
+ currentRef = JGitUtils.getHEADRef(repository);\r
+ assertEquals("refs/heads/master", currentRef);\r
+ \r
+ repository.close();\r
+ }\r
\r
@Test\r
public void testCreateOrphanedBranch() throws Exception {\r