]> source.dussan.org Git - gitblit.git/commitdiff
Revised delete branch feature (issue 121)
authorJames Moger <james.moger@gitblit.com>
Thu, 20 Sep 2012 12:59:22 +0000 (08:59 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 20 Sep 2012 12:59:22 +0000 (08:59 -0400)
docs/04_releases.mkd
src/com/gitblit/models/RefModel.java
src/com/gitblit/wicket/pages/BranchesPage.java
src/com/gitblit/wicket/pages/RepositoryPage.java
src/com/gitblit/wicket/pages/SummaryPage.java
src/com/gitblit/wicket/panels/BranchesPanel.html
src/com/gitblit/wicket/panels/BranchesPanel.java

index 9ec8f5a55e2dea9010c9076ee9c22f0176acb17b..271e18a7e4df95aae49aabaeed595f64d93638b7 100644 (file)
@@ -16,6 +16,7 @@ If you are updating from an earlier release AND you have indexed branches with t
 \r
 #### additions\r
 \r
+- delete branch feature (issue 121, Github/ajermakovics)\r
 - added line links to blob view at the expense of zebra striping (issue 130)\r
 - added RedmineUserService (github/mallowlabs)\r
 \r
index 806700ba345aa0e6d79116bf6f18875980fc46dc..8489c8171202de5ad7d1a129a94cd8aef459ed19 100644 (file)
@@ -61,6 +61,9 @@ public class RefModel implements Serializable, Comparable<RefModel> {
        }\r
 \r
        public String getName() {\r
+               if (reference == null) {\r
+                       return displayName;\r
+               }\r
                return reference.getName();\r
        }\r
 \r
index b38a80a2dcca03e2981a0e8d0c9d29174f6a4d7b..8684fb3d7ea55a8319a97d5c463c678f880c3eff 100644 (file)
@@ -24,7 +24,7 @@ public class BranchesPage extends RepositoryPage {
        public BranchesPage(PageParameters params) {\r
                super(params);\r
 \r
-               add(new BranchesPanel("branchesPanel", getRepositoryModel(), getRepository(), -1, isShowAdmin()));\r
+               add(new BranchesPanel("branchesPanel", getRepositoryModel(), getRepository(), -1, isShowAdmin() || isOwner()));\r
        }\r
 \r
        @Override\r
index 69719464f34b99c2b3d7dcaeebccddea323331d1..eb8536c332eb57026b6a941048d8d9eefec13859 100644 (file)
@@ -76,7 +76,8 @@ public abstract class RepositoryPage extends BasePage {
        \r
        private final Map<String, PageRegistration> registeredPages;\r
        private boolean showAdmin;\r
-\r
+       private boolean isOwner;\r
+       \r
        public RepositoryPage(PageParameters params) {\r
                super(params);\r
                repositoryName = WicketUtils.getRepositoryName(params);\r
@@ -149,17 +150,17 @@ public abstract class RepositoryPage extends BasePage {
                }\r
 \r
                // Conditionally add edit link\r
-               this.showAdmin = false;\r
+               showAdmin = false;\r
                if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {\r
                        boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);\r
                        showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();\r
                } else {\r
                        showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);\r
                }\r
-               if (showAdmin\r
-                               || GitBlitWebSession.get().isLoggedIn()\r
+               isOwner = GitBlitWebSession.get().isLoggedIn()\r
                                && (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get()\r
-                                               .getUsername()))) {\r
+                                               .getUsername()));\r
+               if (showAdmin || isOwner) {\r
                        pages.put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class, params));\r
                }\r
                return pages;\r
@@ -413,9 +414,12 @@ public abstract class RepositoryPage extends BasePage {
                return WicketUtils.newObjectParameter(repositoryName, commitId);\r
        }\r
 \r
-       public boolean isShowAdmin()\r
-       {\r
-               return this.showAdmin;\r
+       public boolean isShowAdmin() {\r
+               return showAdmin;\r
+       }\r
+       \r
+       public boolean isOwner() {\r
+               return isOwner;\r
        }\r
        \r
        private class SearchForm extends SessionlessForm<Void> implements Serializable {\r
index 0b5317869a0ad0a2c9959f77356e05d21eddbd5c..39c7269dcca0f20a99a41b3fd99074e2484a51c7 100644 (file)
@@ -132,7 +132,7 @@ public class SummaryPage extends RepositoryPage {
 \r
                add(new LogPanel("commitsPanel", repositoryName, getRepositoryModel().HEAD, r, numberCommits, 0));\r
                add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());\r
-               add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, isShowAdmin()).hideIfEmpty());\r
+               add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false).hideIfEmpty());\r
 \r
                if (getRepositoryModel().showReadme) {\r
                        String htmlText = null;\r
index d2d88d38480ec1ec79989a4fb4ab0ae9d2d1c8e2..58c86a457aa78586ba8d251fe8ea2a04868d45c2 100644 (file)
 \r
        <!-- branch page links -->\r
        <wicket:fragment wicket:id="branchPageLinks">\r
+               <span class="link">\r
+                       <a wicket:id="log"><wicket:message key="gb.log"></wicket:message></a> | <a wicket:id="tree"><wicket:message key="gb.tree"></wicket:message></a> | <a wicket:id="metrics"><wicket:message key="gb.metrics"></wicket:message></a> | <a wicket:id="syndication"><wicket:message key="gb.feed"></wicket:message></a>\r
+               </span>\r
+       </wicket:fragment>\r
+\r
+       <!-- branch page admin links -->\r
+       <wicket:fragment wicket:id="branchPageAdminLinks">\r
                <span class="link">\r
                        <a wicket:id="log"><wicket:message key="gb.log"></wicket:message></a> | <a wicket:id="tree"><wicket:message key="gb.tree"></wicket:message></a> | <a wicket:id="metrics"><wicket:message key="gb.metrics"></wicket:message></a> | <a wicket:id="syndication"><wicket:message key="gb.feed"></wicket:message></a> | <a wicket:id="deleteBranch"><wicket:message key="gb.delete"></wicket:message></a>\r
                </span>\r
index 25126531f25683031cdeb5134a786e487797c06a..3ca02cb62d76044d0bafaec906e4ad50da88eb05 100644 (file)
@@ -32,6 +32,7 @@ import org.apache.wicket.model.StringResourceModel;
 import org.eclipse.jgit.lib.Repository;\r
 \r
 import com.gitblit.Constants;\r
+import com.gitblit.GitBlit;\r
 import com.gitblit.SyndicationServlet;\r
 import com.gitblit.models.RefModel;\r
 import com.gitblit.models.RepositoryModel;\r
@@ -51,7 +52,7 @@ public class BranchesPanel extends BasePanel {
 \r
        private final boolean hasBranches;\r
 \r
-       public BranchesPanel(String wicketId, final RepositoryModel model, final Repository r,\r
+       public BranchesPanel(String wicketId, final RepositoryModel model, Repository r,\r
                        final int maxCount, final boolean showAdmin) {\r
                super(wicketId);\r
 \r
@@ -76,7 +77,10 @@ public class BranchesPanel extends BasePanel {
                        // branches page\r
                        add(new Label("branches", new StringResourceModel("gb.branches", this, null)));\r
                }\r
-\r
+               \r
+               // only allow delete if we have multiple branches\r
+               final boolean showDelete = showAdmin && branches.size() > 1;\r
+               \r
                ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);\r
                DataView<RefModel> branchesView = new DataView<RefModel>("branch", branchesDp) {\r
                        private static final long serialVersionUID = 1L;\r
@@ -110,7 +114,7 @@ public class BranchesPanel extends BasePanel {
                                item.add(shortlog);\r
                                \r
                                if (maxCount <= 0) {\r
-                                       Fragment fragment = new Fragment("branchLinks", "branchPageLinks", this);\r
+                                       Fragment fragment = new Fragment("branchLinks", showDelete? "branchPageAdminLinks" : "branchPageLinks", this);\r
                                        fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils\r
                                                        .newObjectParameter(model.name, entry.getName())));\r
                                        fragment.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils\r
@@ -120,9 +124,9 @@ public class BranchesPanel extends BasePanel {
                                        fragment.add(new ExternalLink("syndication", SyndicationServlet.asLink(\r
                                                        getRequest().getRelativePathPrefixToContextRoot(), model.name,\r
                                                        entry.getName(), 0)));\r
-                                       \r
-                                       fragment.add(createDeleteBranchLink(r, entry, showAdmin));\r
-                                       \r
+                                       if (showDelete) {\r
+                                               fragment.add(createDeleteBranchLink(model, entry));\r
+                                       }\r
                                        item.add(fragment);\r
                                } else {\r
                                        Fragment fragment = new Fragment("branchLinks", "branchPanelLinks", this);\r
@@ -154,15 +158,20 @@ public class BranchesPanel extends BasePanel {
                return this;\r
        }\r
 \r
-       private Link<Void> createDeleteBranchLink(final Repository r, final RefModel entry, final boolean showAdmin)\r
+       private Link<Void> createDeleteBranchLink(final RepositoryModel repositoryModel, final RefModel entry)\r
        {\r
                Link<Void> deleteLink = new Link<Void>("deleteBranch") {\r
                        private static final long serialVersionUID = 1L;\r
 \r
                        @Override\r
                        public void onClick() {\r
-                               if( showAdmin && JGitUtils.deleteBranchRef(r, entry.getName()) ) {\r
+                               Repository r = GitBlit.self().getRepository(repositoryModel.name);\r
+                               boolean success = JGitUtils.deleteBranchRef(r, entry.getName());\r
+                               r.close();\r
+                               if (success) {\r
                                        info(MessageFormat.format("Branch \"{0}\" deleted", entry.displayName));\r
+                                       // redirect to the owning page\r
+                                       setResponsePage(getPage().getClass(), WicketUtils.newRepositoryParameter(repositoryModel.name));\r
                                }\r
                                else {\r
                                        error(MessageFormat.format("Failed to delete branch \"{0}\"", entry.displayName));\r
@@ -172,9 +181,6 @@ public class BranchesPanel extends BasePanel {
                \r
                deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(\r
                                "Delete branch \"{0}\"?", entry.displayName )));\r
-               \r
-               deleteLink.setVisible(showAdmin);\r
-               \r
                return deleteLink;\r
        }\r
 }\r