From f1b8822f715ea00da6b7d39a8ea63864aeda2d39 Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 8 Mar 2014 15:39:36 -0500 Subject: [PATCH] Allow configuring the default integration branch for a repository --- .../gitblit/client/EditRepositoryDialog.java | 19 +++++++++++- .../gitblit/manager/RepositoryManager.java | 7 +++++ .../com/gitblit/models/RepositoryModel.java | 1 + .../gitblit/wicket/GitBlitWebApp.properties | 1 + .../wicket/pages/EditRepositoryPage.html | 30 ++++++++++--------- .../wicket/pages/EditRepositoryPage.java | 12 +++++++- .../gitblit/wicket/pages/EditTicketPage.java | 6 ++-- .../gitblit/wicket/pages/NewTicketPage.java | 2 +- .../com/gitblit/wicket/pages/TicketPage.java | 2 +- 9 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/gitblit/client/EditRepositoryDialog.java b/src/main/java/com/gitblit/client/EditRepositoryDialog.java index c3690f37..ef665d10 100644 --- a/src/main/java/com/gitblit/client/EditRepositoryDialog.java +++ b/src/main/java/com/gitblit/client/EditRepositoryDialog.java @@ -58,6 +58,8 @@ import javax.swing.KeyStroke; import javax.swing.ListCellRenderer; import javax.swing.ScrollPaneConstants; +import org.eclipse.jgit.lib.Repository; + import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.Constants.AuthorizationControl; import com.gitblit.Constants.FederationStrategy; @@ -92,7 +94,9 @@ public class EditRepositoryDialog extends JDialog { private JCheckBox acceptNewTickets; - private JCheckBox requireApproval; + private JCheckBox requireApproval; + + private JComboBox mergeToField; private JCheckBox useIncrementalPushTags; @@ -217,6 +221,16 @@ public class EditRepositoryDialog extends JDialog { anRepository.acceptNewPatchsets); requireApproval = new JCheckBox(Translation.get("gb.requireApprovalDescription"), anRepository.requireApproval); + + if (ArrayUtils.isEmpty(anRepository.availableRefs)) { + mergeToField = new JComboBox(); + mergeToField.setEnabled(false); + } else { + mergeToField = new JComboBox( + anRepository.availableRefs.toArray()); + mergeToField.setSelectedItem(anRepository.mergeTo); + } + useIncrementalPushTags = new JCheckBox(Translation.get("gb.useIncrementalPushTagsDescription"), anRepository.useIncrementalPushTags); showRemoteBranches = new JCheckBox( @@ -316,6 +330,7 @@ public class EditRepositoryDialog extends JDialog { acceptNewPatchsets)); fieldsPanel.add(newFieldPanel(Translation.get("gb.requireApproval"), requireApproval)); + fieldsPanel.add(newFieldPanel(Translation.get("gb.mergeTo"), mergeToField)); fieldsPanel .add(newFieldPanel(Translation.get("gb.enableIncrementalPushTags"), useIncrementalPushTags)); fieldsPanel.add(newFieldPanel(Translation.get("gb.showRemoteBranches"), @@ -573,6 +588,8 @@ public class EditRepositoryDialog extends JDialog { repository.acceptNewPatchsets = acceptNewPatchsets.isSelected(); repository.acceptNewTickets = acceptNewTickets.isSelected(); repository.requireApproval = requireApproval.isSelected(); + repository.mergeTo = mergeToField.getSelectedItem() == null ? null + : Repository.shortenRefName(mergeToField.getSelectedItem().toString()); repository.useIncrementalPushTags = useIncrementalPushTags.isSelected(); repository.showRemoteBranches = showRemoteBranches.isSelected(); repository.skipSizeCalculation = skipSizeCalculation.isSelected(); diff --git a/src/main/java/com/gitblit/manager/RepositoryManager.java b/src/main/java/com/gitblit/manager/RepositoryManager.java index 1e917984..839671c2 100644 --- a/src/main/java/com/gitblit/manager/RepositoryManager.java +++ b/src/main/java/com/gitblit/manager/RepositoryManager.java @@ -804,6 +804,7 @@ public class RepositoryManager implements IRepositoryManager { model.acceptNewPatchsets = getConfig(config, "acceptNewPatchsets", true); model.acceptNewTickets = getConfig(config, "acceptNewTickets", true); model.requireApproval = getConfig(config, "requireApproval", settings.getBoolean(Keys.tickets.requireApproval, false)); + model.mergeTo = getConfig(config, "mergeTo", null); model.useIncrementalPushTags = getConfig(config, "useIncrementalPushTags", false); model.incrementalPushTagPrefix = getConfig(config, "incrementalPushTagPrefix", null); model.allowForks = getConfig(config, "allowForks", true); @@ -854,6 +855,9 @@ public class RepositoryManager implements IRepositoryManager { } } model.HEAD = JGitUtils.getHEADRef(r); + if (StringUtils.isEmpty(model.mergeTo)) { + model.mergeTo = model.HEAD; + } model.availableRefs = JGitUtils.getAvailableHeadTargets(r); model.sparkleshareId = JGitUtils.getSparkleshareId(r); model.hasCommits = JGitUtils.hasCommits(r); @@ -1418,6 +1422,9 @@ public class RepositoryManager implements IRepositoryManager { // override default config.setBoolean(Constants.CONFIG_GITBLIT, null, "requireApproval", repository.requireApproval); } + if (!StringUtils.isEmpty(repository.mergeTo)) { + config.setString(Constants.CONFIG_GITBLIT, null, "mergeTo", repository.mergeTo); + } config.setBoolean(Constants.CONFIG_GITBLIT, null, "useIncrementalPushTags", repository.useIncrementalPushTags); if (StringUtils.isEmpty(repository.incrementalPushTagPrefix) || repository.incrementalPushTagPrefix.equals(settings.getString(Keys.git.defaultIncrementalPushTagPrefix, "r"))) { diff --git a/src/main/java/com/gitblit/models/RepositoryModel.java b/src/main/java/com/gitblit/models/RepositoryModel.java index 5bd2ec03..f84e96b9 100644 --- a/src/main/java/com/gitblit/models/RepositoryModel.java +++ b/src/main/java/com/gitblit/models/RepositoryModel.java @@ -88,6 +88,7 @@ public class RepositoryModel implements Serializable, Comparable - - - - - -  
- + + + + + + @@ -54,15 +56,15 @@
- + - + - - - + + + @@ -75,7 +77,7 @@





- +
diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java index 3a5f122f..f860eeb3 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -49,6 +49,7 @@ import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; import org.apache.wicket.model.util.CollectionModel; import org.apache.wicket.model.util.ListModel; +import org.eclipse.jgit.lib.Repository; import com.gitblit.Constants; import com.gitblit.Constants.AccessRestrictionType; @@ -443,8 +444,16 @@ public class EditRepositoryPage extends RootSubPage { // allow relinking HEAD to a branch or tag other than master on edit repository List availableRefs = new ArrayList(); + List availableBranches = new ArrayList(); if (!ArrayUtils.isEmpty(repositoryModel.availableRefs)) { - availableRefs.addAll(repositoryModel.availableRefs); + for (String ref : repositoryModel.availableRefs) { + if (!ref.startsWith(Constants.R_TICKET)) { + availableRefs.add(ref); + if (ref.startsWith(Constants.R_HEADS)) { + availableBranches.add(Repository.shortenRefName(ref)); + } + } + } } form.add(new DropDownChoice("HEAD", availableRefs).setEnabled(availableRefs.size() > 0)); @@ -469,6 +478,7 @@ public class EditRepositoryPage extends RootSubPage { form.add(new CheckBox("acceptNewPatchsets")); form.add(new CheckBox("acceptNewTickets")); form.add(new CheckBox("requireApproval")); + form.add(new DropDownChoice("mergeTo", availableBranches).setEnabled(availableBranches.size() > 0)); form.add(new CheckBox("useIncrementalPushTags")); form.add(new CheckBox("showRemoteBranches")); form.add(new CheckBox("skipSizeCalculation")); diff --git a/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java b/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java index b5004861..00cd47d9 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java @@ -108,7 +108,7 @@ public class EditTicketPage extends RepositoryPage { topicModel = Model.of(ticket.topic == null ? "" : ticket.topic); responsibleModel = Model.of(); milestoneModel = Model.of(); - mergeToModel = Model.of(ticket.mergeTo == null ? "" : ticket.mergeTo); + mergeToModel = Model.of(ticket.mergeTo == null ? getRepositoryModel().mergeTo : ticket.mergeTo); statusModel = Model.of(ticket.status); setStatelessHint(false); @@ -309,8 +309,8 @@ public class EditTicketPage extends RepositoryPage { branches.add(Repository.shortenRefName(branch)); } } - branches.remove(Repository.shortenRefName(getRepositoryModel().HEAD)); - branches.add(0, Repository.shortenRefName(getRepositoryModel().HEAD)); + branches.remove(Repository.shortenRefName(getRepositoryModel().mergeTo)); + branches.add(0, Repository.shortenRefName(getRepositoryModel().mergeTo)); Fragment mergeto = new Fragment("mergeto", "mergeToFragment", this); mergeto.add(new DropDownChoice("mergeto", mergeToModel, branches)); diff --git a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java index 25fe48f4..fda2e9f3 100644 --- a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java @@ -87,7 +87,7 @@ public class NewTicketPage extends RepositoryPage { typeModel = Model.of(TicketModel.Type.defaultType); titleModel = Model.of(); topicModel = Model.of(); - mergeToModel = Model.of(Repository.shortenRefName(getRepositoryModel().HEAD)); + mergeToModel = Model.of(Repository.shortenRefName(getRepositoryModel().mergeTo)); responsibleModel = Model.of(); milestoneModel = Model.of(); diff --git a/src/main/java/com/gitblit/wicket/pages/TicketPage.java b/src/main/java/com/gitblit/wicket/pages/TicketPage.java index 434882f4..1a1686d3 100644 --- a/src/main/java/com/gitblit/wicket/pages/TicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TicketPage.java @@ -988,7 +988,7 @@ public class TicketPage extends TicketBasePage { md = md.replace("${ticketId}", "" + ticketId); md = md.replace("${patchset}", "" + 1); md = md.replace("${reviewBranch}", Repository.shortenRefName(PatchsetCommand.getTicketBranch(ticketId))); - String integrationBranch = Repository.shortenRefName(getRepositoryModel().HEAD); + String integrationBranch = Repository.shortenRefName(getRepositoryModel().mergeTo); if (!StringUtils.isEmpty(ticket.mergeTo)) { integrationBranch = ticket.mergeTo; } -- 2.39.5