James Moger
2014-03-08 da97a6a8921da24e8d222ba3eea57f9d0f2f8f44
src/main/java/com/gitblit/wicket/pages/TicketPage.java
@@ -327,7 +327,7 @@
       * UPDATE FORM (DISCUSSION TAB)
       */
      if (user.canEdit(ticket, repository) && app().tickets().isAcceptingTicketUpdates(repository)) {
         if (ticket.isOpen()) {
         if (user.canAdmin(ticket, repository) && ticket.isOpen()) {
            /*
             * OPEN TICKET
             */
@@ -731,15 +731,36 @@
       *  PATCHSET TAB
       */
      if (currentPatchset == null) {
         // no patchset yet, show propose fragment
         String repoUrl = getRepositoryUrl(user, repository);
         Fragment changeIdFrag = new Fragment("patchset", "proposeFragment", this);
         changeIdFrag.add(new Label("proposeInstructions", MarkdownUtils.transformMarkdown(getString("gb.proposeInstructions"))).setEscapeModelStrings(false));
         changeIdFrag.add(new Label("ptWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Barnum")));
         changeIdFrag.add(new Label("ptWorkflowSteps", getProposeWorkflow("propose_pt.md", repoUrl, ticket.number)).setEscapeModelStrings(false));
         changeIdFrag.add(new Label("gitWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Git")));
         changeIdFrag.add(new Label("gitWorkflowSteps", getProposeWorkflow("propose_git.md", repoUrl, ticket.number)).setEscapeModelStrings(false));
         add(changeIdFrag);
         // no patchset available
         if (ticket.isOpen() && app().tickets().isAcceptingNewPatchsets(repository)) {
            // ticket & repo will accept a proposal patchset
            // show the instructions for proposing a patchset
            String repoUrl = getRepositoryUrl(user, repository);
            Fragment changeIdFrag = new Fragment("patchset", "proposeFragment", this);
            changeIdFrag.add(new Label("proposeInstructions", MarkdownUtils.transformMarkdown(getString("gb.proposeInstructions"))).setEscapeModelStrings(false));
            changeIdFrag.add(new Label("ptWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Barnum")));
            changeIdFrag.add(new Label("ptWorkflowSteps", getProposeWorkflow("propose_pt.md", repoUrl, ticket.number)).setEscapeModelStrings(false));
            changeIdFrag.add(new Label("gitWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Git")));
            changeIdFrag.add(new Label("gitWorkflowSteps", getProposeWorkflow("propose_git.md", repoUrl, ticket.number)).setEscapeModelStrings(false));
            add(changeIdFrag);
         } else {
            // explain why you can't propose a patchset
            Fragment fragment = new Fragment("patchset", "canNotProposeFragment", this);
            String reason = "";
            if (ticket.isClosed()) {
               reason = getString("gb.ticketIsClosed");
            } else if (repository.isMirror) {
               reason = getString("gb.repositoryIsMirror");
            } else if (repository.isFrozen) {
               reason = getString("gb.repositoryIsFrozen");
            } else if (!repository.acceptNewPatchsets) {
               reason = getString("gb.repositoryDoesNotAcceptPatchsets");
            } else {
               reason = getString("gb.serverDoesNotAcceptPatchsets");
            }
            fragment.add(new Label("reason", reason));
            add(fragment);
         }
      } else {
         // show current patchset
         Fragment patchsetFrag = new Fragment("patchset", "patchsetFragment", this);
@@ -967,7 +988,11 @@
      md = md.replace("${ticketId}", "" + ticketId);
      md = md.replace("${patchset}", "" + 1);
      md = md.replace("${reviewBranch}", Repository.shortenRefName(PatchsetCommand.getTicketBranch(ticketId)));
      md = md.replace("${integrationBranch}", Repository.shortenRefName(getRepositoryModel().HEAD));
      String integrationBranch = Repository.shortenRefName(getRepositoryModel().HEAD);
      if (!StringUtils.isEmpty(ticket.mergeTo)) {
         integrationBranch = ticket.mergeTo;
      }
      md = md.replace("${integrationBranch}", integrationBranch);
      return MarkdownUtils.transformMarkdown(md);
   }
@@ -1254,16 +1279,13 @@
   }
   protected void addGitReviewInstructions(UserModel user, RepositoryModel repository, MarkupContainer panel) {
      String repoUrl = getRepositoryUrl(user, repository);
      panel.add(new Label("gitStep1", MessageFormat.format(getString("gb.stepN"), 1)));
      panel.add(new Label("gitStep2", MessageFormat.format(getString("gb.stepN"), 2)));
      String ticketBranch  = Repository.shortenRefName(PatchsetCommand.getTicketBranch(ticket.number));
      String reviewBranch = PatchsetCommand.getReviewBranch(ticket.number);
      String step1 = MessageFormat.format("git fetch {0} {1}", repoUrl, ticketBranch);
      String step2 = MessageFormat.format("git checkout -B {0} FETCH_HEAD", reviewBranch);
      String step1 = "git fetch";
      String step2 = MessageFormat.format("git checkout {0} && git pull --ff-only\nOR\ngit checkout {0} && git reset --hard origin/{0}", ticketBranch);
      panel.add(new Label("gitPreStep1", step1));
      panel.add(new Label("gitPreStep2", step2));
@@ -1417,7 +1439,6 @@
   protected Component getMergeInstructions(UserModel user, RepositoryModel repository, String markupId, String infoKey) {
      Fragment cmd = new Fragment(markupId, "commandlineMergeFragment", this);
      cmd.add(new Label("instructions", MessageFormat.format(getString(infoKey), ticket.mergeTo)));
      String repoUrl = getRepositoryUrl(user, repository);
      // git instructions
      cmd.add(new Label("mergeStep1", MessageFormat.format(getString("gb.stepN"), 1)));
@@ -1427,9 +1448,9 @@
      String ticketBranch = Repository.shortenRefName(PatchsetCommand.getTicketBranch(ticket.number));
      String reviewBranch = PatchsetCommand.getReviewBranch(ticket.number);
      String step1 = MessageFormat.format("git checkout -B {0} {1}", reviewBranch, ticket.mergeTo);
      String step2 = MessageFormat.format("git pull {0} {1}", repoUrl, ticketBranch);
      String step3 = MessageFormat.format("git checkout {0}\ngit merge {1}\ngit push origin {0}", ticket.mergeTo, reviewBranch);
      String step1 = MessageFormat.format("git checkout -b {0} {1}", reviewBranch, ticket.mergeTo);
      String step2 = MessageFormat.format("git pull origin {0}", ticketBranch);
      String step3 = MessageFormat.format("git checkout {0}\ngit merge {1}\ngit push origin {0}\ngit branch -d {1}", ticket.mergeTo, reviewBranch);
      cmd.add(new Label("mergePreStep1", step1));
      cmd.add(new Label("mergePreStep2", step2));