From 37994ee10f8feed935e2770969ebc970a50d8d04 Mon Sep 17 00:00:00 2001 From: Constantine Plotnikov Date: Tue, 28 Oct 2008 16:11:48 +0300 Subject: [PATCH] git4idea: minor refactoring, fixed formatting, removed unused methods that has been replaced by OS process handler. --- plugins/git4idea/src/git4idea/GitRemote.java | 39 +++++++-------- .../src/git4idea/actions/GitCurrentBranch.java | 10 ++-- .../git4idea/src/git4idea/actions/GitMerge.java | 16 ++----- plugins/git4idea/src/git4idea/actions/GitPull.java | 24 ++++------ .../git4idea/src/git4idea/commands/GitHandler.java | 6 ++- .../src/git4idea/commands/GitHandlerUtil.java | 2 +- .../src/git4idea/config/GitConfigUtil.java | 22 ++++----- .../src/git4idea/i18n/GitBundle.properties | 1 + .../src/git4idea/merge/GitMergeDialog.java | 2 +- .../git4idea/src/git4idea/merge/GitMergeUtil.java | 55 ++++++++++++++++++---- .../git4idea/src/git4idea/merge/GitPullDialog.java | 52 ++++++++++---------- plugins/git4idea/src/git4idea/ui/GitUIUtil.java | 15 +++--- 12 files changed, 136 insertions(+), 108 deletions(-) diff --git a/plugins/git4idea/src/git4idea/GitRemote.java b/plugins/git4idea/src/git4idea/GitRemote.java index dea530eb45..43c980def2 100644 --- a/plugins/git4idea/src/git4idea/GitRemote.java +++ b/plugins/git4idea/src/git4idea/GitRemote.java @@ -19,8 +19,8 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; import git4idea.commands.GitSimpleHandler; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; @@ -54,7 +54,7 @@ public final class GitRemote { * A constructor * * @param name the name - * @param url the url + * @param url the url */ public GitRemote(@NotNull final String name, final String url) { myName = name; @@ -88,7 +88,7 @@ public final class GitRemote { */ @Override public boolean equals(final Object obj) { - return (obj instanceof GitRemote) && myName.equals(((GitRemote)obj).myName); + return (obj instanceof GitRemote) && myName.equals(((GitRemote)obj).myName); } /** @@ -103,7 +103,7 @@ public final class GitRemote { * List all remotes for the git root (git remote -v) * * @param project the context project - * @param root the git root + * @param root the git root * @return a list of registered remotes */ public static List list(Project project, VirtualFile root) throws VcsException { @@ -112,13 +112,13 @@ public final class GitRemote { handler.setNoSSH(true); handler.setSilent(true); handler.addParameters("-v"); - for(String line : handler.run().split("\n")) { + for (String line : handler.run().split("\n")) { int i = line.indexOf('\t'); - if(i == -1) { + if (i == -1) { continue; } String name = line.substring(0, i); - String url = line.substring(i+1); + String url = line.substring(i + 1); remotes.add(new GitRemote(name, url)); } return remotes; @@ -133,30 +133,30 @@ public final class GitRemote { GitSimpleHandler handler = new GitSimpleHandler(project, root, "remote"); handler.setNoSSH(true); handler.setSilent(true); - handler.addParameters("show","-n", myName); + handler.addParameters("show", "-n", myName); String[] lines = handler.run().split("\n"); - TreeMap mapping = new TreeMap(); + TreeMap mapping = new TreeMap(); TreeSet branches = new TreeSet(); int i = 0; - if(!lines[i].startsWith("*") || !lines[i].endsWith(myName)) { - throw new IllegalStateException("Unexpected format for 'git remote show' line "+i+":"+lines[i]); + if (!lines[i].startsWith("*") || !lines[i].endsWith(myName)) { + throw new IllegalStateException("Unexpected format for 'git remote show' line " + i + ":" + lines[i]); } - if(i >= lines.length) { - throw new IllegalStateException("Premature end from 'git remote show' at line "+i); + if (i >= lines.length) { + throw new IllegalStateException("Premature end from 'git remote show' at line " + i); } i++; - if(!lines[i].startsWith(SHOW_URL_PREFIX) || !lines[i].endsWith(myUrl)) { - throw new IllegalStateException("Unexpected format for 'git remote show' line "+i+":"+lines[i]); + if (!lines[i].startsWith(SHOW_URL_PREFIX) || !lines[i].endsWith(myUrl)) { + throw new IllegalStateException("Unexpected format for 'git remote show' line " + i + ":" + lines[i]); } i++; - while( i < lines.length && lines[i].startsWith(SHOW_MAPPING_PREFIX) ) { + while (i < lines.length && lines[i].startsWith(SHOW_MAPPING_PREFIX)) { String local = lines[i].substring(SHOW_MAPPING_PREFIX.length()); i++; String remote = lines[i].trim(); i++; - mapping.put(local,remote); + mapping.put(local, remote); } - if(i < lines.length && lines[i].equals(SHOW_BRANCHES_LINE)) { + if (i < lines.length && lines[i].equals(SHOW_BRANCHES_LINE)) { i++; branches.addAll(Arrays.asList(lines[i].substring(4).split(" "))); } @@ -179,7 +179,7 @@ public final class GitRemote { /** * A constructor from fields * - * @param branchMapping a map from local branches to remote branches + * @param branchMapping a map from local branches to remote branches * @param trackedRemotes a set of tracked remotes */ public Info(final Map branchMapping, final Set trackedRemotes) { @@ -196,6 +196,7 @@ public final class GitRemote { /** * Get remote branch for the local branch + * * @param localBranchName a local branch name * @return a remote branch name or null if the mapping is not found */ diff --git a/plugins/git4idea/src/git4idea/actions/GitCurrentBranch.java b/plugins/git4idea/src/git4idea/actions/GitCurrentBranch.java index a103e4ad3c..eb29b7fb82 100644 --- a/plugins/git4idea/src/git4idea/actions/GitCurrentBranch.java +++ b/plugins/git4idea/src/git4idea/actions/GitCurrentBranch.java @@ -20,9 +20,9 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; +import git4idea.GitBranch; import git4idea.GitUtil; import git4idea.GitVcs; -import git4idea.commands.GitCommand; import git4idea.i18n.GitBundle; import org.jetbrains.annotations.NotNull; @@ -35,10 +35,10 @@ public class GitCurrentBranch extends BasicAction { @Override protected void perform(@NotNull Project project, GitVcs vcs, @NotNull List exceptions, @NotNull VirtualFile[] files) throws VcsException { - - GitCommand cmd = new GitCommand(project, vcs.getSettings(), GitUtil.getVcsRoot(project, files[0])); - Messages.showInfoMessage(project, GitBundle.message("current.branch.message", cmd.currentBranch()), - GitBundle.getString("current.branch.title")); + final VirtualFile root = GitUtil.getVcsRoot(project, files[0]); + final GitBranch gitBranch = GitBranch.current(project, root); + final String branchName = gitBranch != null ? gitBranch.getName() : GitBranch.NO_BRANCH_NAME; + Messages.showInfoMessage(project, GitBundle.message("current.branch.message", branchName), GitBundle.getString("current.branch.title")); } @Override diff --git a/plugins/git4idea/src/git4idea/actions/GitMerge.java b/plugins/git4idea/src/git4idea/actions/GitMerge.java index 3c31223e15..f9fb6ed18d 100644 --- a/plugins/git4idea/src/git4idea/actions/GitMerge.java +++ b/plugins/git4idea/src/git4idea/actions/GitMerge.java @@ -17,11 +17,8 @@ package git4idea.actions; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx; import com.intellij.openapi.vcs.update.ActionInfo; -import com.intellij.openapi.vcs.update.UpdatedFiles; import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitRevisionNumber; import git4idea.GitVcs; @@ -29,7 +26,7 @@ import git4idea.commands.GitHandlerUtil; import git4idea.commands.GitLineHandler; import git4idea.i18n.GitBundle; import git4idea.merge.GitMergeDialog; -import git4idea.merge.MergeChangeCollector; +import git4idea.merge.GitMergeUtil; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -67,7 +64,7 @@ public class GitMerge extends GitRepositoryAction { affectedRoots.add(root); GitRevisionNumber currentRev = GitRevisionNumber.resolve(project, root, "HEAD"); try { - GitHandlerUtil.doSynchronouslyWithExceptions(h); + GitHandlerUtil.doSynchronously(h, GitBundle.message("merging.title", dialog.getSelectedRoot().getPath()), h.printableCommandLine()); } finally { exceptions.addAll(h.errors()); @@ -75,14 +72,7 @@ public class GitMerge extends GitRepositoryAction { if (exceptions.size() != 0) { return; } - final UpdatedFiles files = UpdatedFiles.create(); - MergeChangeCollector collector = new MergeChangeCollector(project, root, currentRev, files); - collector.collect(exceptions); - if (exceptions.size() != 0) { - return; - } - ProjectLevelVcsManagerEx manager = (ProjectLevelVcsManagerEx)ProjectLevelVcsManager.getInstance(project); GitVcs vcs = GitVcs.getInstance(project); - manager.showUpdateProjectInfo(files, getActionName(vcs), ActionInfo.INTEGRATE); + GitMergeUtil.showUpdates(project, exceptions, root, currentRev, getActionName(vcs), ActionInfo.INTEGRATE); } } diff --git a/plugins/git4idea/src/git4idea/actions/GitPull.java b/plugins/git4idea/src/git4idea/actions/GitPull.java index 70e171542d..c43b5371bb 100644 --- a/plugins/git4idea/src/git4idea/actions/GitPull.java +++ b/plugins/git4idea/src/git4idea/actions/GitPull.java @@ -17,19 +17,16 @@ package git4idea.actions; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx; import com.intellij.openapi.vcs.update.ActionInfo; -import com.intellij.openapi.vcs.update.UpdatedFiles; import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitRevisionNumber; import git4idea.GitVcs; import git4idea.commands.GitHandlerUtil; import git4idea.commands.GitLineHandler; import git4idea.i18n.GitBundle; +import git4idea.merge.GitMergeUtil; import git4idea.merge.GitPullDialog; -import git4idea.merge.MergeChangeCollector; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -52,8 +49,11 @@ public class GitPull extends GitRepositoryAction { /** * {@inheritDoc} */ - protected void perform(@NotNull final Project project, @NotNull final List gitRoots, @NotNull final VirtualFile defaultRoot, - final Set affectedRoots, final List exceptions) throws VcsException { + protected void perform(@NotNull final Project project, + @NotNull final List gitRoots, + @NotNull final VirtualFile defaultRoot, + final Set affectedRoots, + final List exceptions) throws VcsException { GitPullDialog dialog = new GitPullDialog(project, gitRoots, defaultRoot); dialog.show(); if (!dialog.isOK()) { @@ -64,7 +64,7 @@ public class GitPull extends GitRepositoryAction { affectedRoots.add(root); GitRevisionNumber currentRev = GitRevisionNumber.resolve(project, root, "HEAD"); try { - GitHandlerUtil.doSynchronously(h, GitBundle.message("pulling.title", dialog.getRemote()), h.printCommandLine()); + GitHandlerUtil.doSynchronously(h, GitBundle.message("pulling.title", dialog.getRemote()), h.printableCommandLine()); } finally { exceptions.addAll(h.errors()); @@ -72,14 +72,8 @@ public class GitPull extends GitRepositoryAction { if (exceptions.size() != 0) { return; } - final UpdatedFiles files = UpdatedFiles.create(); - MergeChangeCollector collector = new MergeChangeCollector(project, root, currentRev, files); - collector.collect(exceptions); - if (exceptions.size() != 0) { - return; - } - ProjectLevelVcsManagerEx manager = (ProjectLevelVcsManagerEx)ProjectLevelVcsManager.getInstance(project); GitVcs vcs = GitVcs.getInstance(project); - manager.showUpdateProjectInfo(files, getActionName(vcs), ActionInfo.UPDATE); + GitMergeUtil.showUpdates(project, exceptions, root, currentRev, getActionName(vcs), ActionInfo.UPDATE); } + } diff --git a/plugins/git4idea/src/git4idea/commands/GitHandler.java b/plugins/git4idea/src/git4idea/commands/GitHandler.java index 63eb9b8f04..7ae54b46d6 100644 --- a/plugins/git4idea/src/git4idea/commands/GitHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitHandler.java @@ -141,6 +141,7 @@ public abstract class GitHandler { /** * Add error code to ignored list + * * @param code the code to ignore */ public void ignoreErrorCode(int code) { @@ -149,6 +150,7 @@ public abstract class GitHandler { /** * Check if error code should be ignored + * * @param code a code to check * @return true if error code is ignorable */ @@ -319,7 +321,7 @@ public abstract class GitHandler { try { // setup environment if (!myProject.isDefault() && !mySilent) { - GitVcs.getInstance(myProject).showMessages(printCommandLine()); + GitVcs.getInstance(myProject).showMessages(printableCommandLine()); } if (log.isDebugEnabled()) { log.debug("running git: " + myCommandLine.getCommandLineString() + " in " + myWorkingDirectory); @@ -373,7 +375,7 @@ public abstract class GitHandler { /** * @return a command line with full path to executable replace to "git" */ - public String printCommandLine() { + public String printableCommandLine() { final GeneralCommandLine line = myCommandLine.clone(); line.setExePath("git"); return line.getCommandLineString(); diff --git a/plugins/git4idea/src/git4idea/commands/GitHandlerUtil.java b/plugins/git4idea/src/git4idea/commands/GitHandlerUtil.java index cde8fadc38..7f67d1a074 100644 --- a/plugins/git4idea/src/git4idea/commands/GitHandlerUtil.java +++ b/plugins/git4idea/src/git4idea/commands/GitHandlerUtil.java @@ -134,7 +134,7 @@ public class GitHandlerUtil { private static void runInCurrentThread(final GitHandler handler, final ProgressIndicator indicator, final boolean setIndeterminateFlag) { handler.start(); if (indicator != null) { - indicator.setText(GitBundle.message("git.running", handler.printCommandLine())); + indicator.setText(GitBundle.message("git.running", handler.printableCommandLine())); if (setIndeterminateFlag) { indicator.setIndeterminate(true); } diff --git a/plugins/git4idea/src/git4idea/config/GitConfigUtil.java b/plugins/git4idea/src/git4idea/config/GitConfigUtil.java index d31d2772f7..0d873ae95d 100644 --- a/plugins/git4idea/src/git4idea/config/GitConfigUtil.java +++ b/plugins/git4idea/src/git4idea/config/GitConfigUtil.java @@ -19,8 +19,8 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; import git4idea.commands.GitSimpleHandler; -import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -38,23 +38,23 @@ public class GitConfigUtil { * Get configuration values for the repository. Note that the method executes a git command. * * @param project the context project - * @param root the git root + * @param root the git root * @param keyMask the keys to be queried - * @param result the map to put results to + * @param result the map to put results to * @throws VcsException an exception */ - public static void getValues(Project project, VirtualFile root, String keyMask, Map result) throws VcsException { + public static void getValues(Project project, VirtualFile root, String keyMask, Map result) throws VcsException { GitSimpleHandler h = new GitSimpleHandler(project, root, "config"); h.setNoSSH(true); h.setSilent(true); - h.addParameters("--null","--get-regexp", keyMask); + h.addParameters("--null", "--get-regexp", keyMask); String output = h.run(); int start = 0; int pos; - while((pos = output.indexOf('\n', start))!= -1) { + while ((pos = output.indexOf('\n', start)) != -1) { String key = output.substring(start, pos); start = pos + 1; - if((pos = output.indexOf('\u0000', start)) == -1) { + if ((pos = output.indexOf('\u0000', start)) == -1) { break; } String value = output.substring(start, pos); @@ -67,8 +67,8 @@ public class GitConfigUtil { * Get configuration value for the repository. Note that the method executes a git command. * * @param project the context project - * @param root the git root - * @param key the keys to be queried + * @param root the git root + * @param key the keys to be queried * @return the value associtated with the key or null if the value is not found * @throws VcsException an exception */ @@ -78,10 +78,10 @@ public class GitConfigUtil { h.setNoSSH(true); h.setSilent(true); h.ignoreErrorCode(1); - h.addParameters("--null","--get", key); + h.addParameters("--null", "--get", key); String output = h.run(); int pos = output.indexOf('\u0000'); - if(h.getExitCode() != 0 || pos == -1 ) { + if (h.getExitCode() != 0 || pos == -1) { return null; } return output.substring(0, pos); diff --git a/plugins/git4idea/src/git4idea/i18n/GitBundle.properties b/plugins/git4idea/src/git4idea/i18n/GitBundle.properties index cadf89939d..f07170fe93 100644 --- a/plugins/git4idea/src/git4idea/i18n/GitBundle.properties +++ b/plugins/git4idea/src/git4idea/i18n/GitBundle.properties @@ -101,6 +101,7 @@ merge.strategy.tooltip=The merge strategy to use (\"-s\" option) merge.strategy=&Strategy: merge.tool.action.name=MergeTool merging.branch=Merging branch {0} +merging.title=Merging changes to {0} paths.affected.title=Paths affected in commit {0} pull.action.name=Pull pull.force.reference.update=Force reference &update diff --git a/plugins/git4idea/src/git4idea/merge/GitMergeDialog.java b/plugins/git4idea/src/git4idea/merge/GitMergeDialog.java index 939a322e86..5eb7dd1611 100644 --- a/plugins/git4idea/src/git4idea/merge/GitMergeDialog.java +++ b/plugins/git4idea/src/git4idea/merge/GitMergeDialog.java @@ -132,7 +132,7 @@ public class GitMergeDialog extends DialogWrapper { setOKActionEnabled(myBranchChooser.getMarkedElements().size() != 0); } }; - listener.elementMarkChanged(null,true); + listener.elementMarkChanged(null, true); } diff --git a/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java b/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java index 7812fa9ff0..f628d5a2ab 100644 --- a/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java +++ b/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java @@ -16,6 +16,14 @@ package git4idea.merge; import com.intellij.ide.util.ElementsChooser; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vcs.ProjectLevelVcsManager; +import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx; +import com.intellij.openapi.vcs.update.ActionInfo; +import com.intellij.openapi.vcs.update.UpdatedFiles; +import com.intellij.openapi.vfs.VirtualFile; +import git4idea.GitRevisionNumber; import git4idea.i18n.GitBundle; import org.jetbrains.annotations.NonNls; @@ -65,15 +73,16 @@ public class GitMergeUtil { * Initialize no commit checkbox (for both merge and pull dialog) * * @param addLogInformationCheckBox a log information checkbox - * @param commitMessage a commit message text field or null - * @param noCommitCheckBox a no commit checkbox to configure + * @param commitMessage a commit message text field or null + * @param noCommitCheckBox a no commit checkbox to configure */ - public static void setupNoCommitCheckbox(final JCheckBox addLogInformationCheckBox, final JTextField commitMessage, - final JCheckBox noCommitCheckBox) { + public static void setupNoCommitCheckbox(final JCheckBox addLogInformationCheckBox, + final JTextField commitMessage, + final JCheckBox noCommitCheckBox) { noCommitCheckBox.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { final boolean selected = noCommitCheckBox.isSelected(); - if(commitMessage != null) { + if (commitMessage != null) { commitMessage.setEnabled(!selected); } if (selected) { @@ -86,13 +95,14 @@ public class GitMergeUtil { /** * Setup strategies dropdown. The set of strategies changes according to amount of selected elements in branchChooser. - * - * @param branchChooser a branch chooser + * + * @param branchChooser a branch chooser * @param noCommitCheckBox no commit checkbox - * @param strategy a strategy selector + * @param strategy a strategy selector */ public static void setupStrategies(final ElementsChooser branchChooser, - final JCheckBox noCommitCheckBox, final JComboBox strategy) { + final JCheckBox noCommitCheckBox, + final JComboBox strategy) { final ElementsChooser.ElementsMarkListener listener = new ElementsChooser.ElementsMarkListener() { private void updateStrategies(final List elements) { strategy.removeAllItems(); @@ -101,6 +111,7 @@ public class GitMergeUtil { } strategy.setSelectedItem(DEFAULT_STRATEGY); } + public void elementMarkChanged(final String element, final boolean isMarked) { final List elements = branchChooser.getMarkedElements(); if (elements.size() == 0) { @@ -124,4 +135,30 @@ public class GitMergeUtil { listener.elementMarkChanged(null, true); branchChooser.addElementsMarkListener(listener); } + + /** + * Show updates caused by git operation + * + * @param project the context project + * @param exceptions the exception list + * @param root the git root + * @param currentRev the revision before update + * @param actionName the action name + * @param actionInfo the information about the action + */ + public static void showUpdates(final Project project, + final List exceptions, + final VirtualFile root, + final GitRevisionNumber currentRev, + final String actionName, + final ActionInfo actionInfo) { + final UpdatedFiles files = UpdatedFiles.create(); + MergeChangeCollector collector = new MergeChangeCollector(project, root, currentRev, files); + collector.collect(exceptions); + if (exceptions.size() != 0) { + return; + } + ProjectLevelVcsManagerEx manager = (ProjectLevelVcsManagerEx)ProjectLevelVcsManager.getInstance(project); + manager.showUpdateProjectInfo(files, actionName, actionInfo); + } } diff --git a/plugins/git4idea/src/git4idea/merge/GitPullDialog.java b/plugins/git4idea/src/git4idea/merge/GitPullDialog.java index 4f63c61b4d..6e978d5582 100644 --- a/plugins/git4idea/src/git4idea/merge/GitPullDialog.java +++ b/plugins/git4idea/src/git4idea/merge/GitPullDialog.java @@ -117,7 +117,7 @@ public class GitPullDialog extends DialogWrapper { } }; myBranchChooser.addElementsMarkListener(listener); - listener.elementMarkChanged(null,true); + listener.elementMarkChanged(null, true); GitMergeUtil.setupNoCommitCheckbox(myAddLogInformationCheckBox, null, myNoCommitCheckBox); GitMergeUtil.setupStrategies(myBranchChooser, myNoCommitCheckBox, myStrategy); init(); @@ -139,7 +139,7 @@ public class GitPullDialog extends DialogWrapper { * Validate dialog and enable buttons */ private void validateDialog() { - if(getRemote().trim().length() == 0) { + if (getRemote().trim().length() == 0) { setOKActionEnabled(false); return; } @@ -159,24 +159,24 @@ public class GitPullDialog extends DialogWrapper { }; textField.getDocument().addDocumentListener(listener); listener.changedUpdate(null); - myGetBranchesButton.addActionListener(new ActionListener(){ + myGetBranchesButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { GitSimpleHandler h = new GitSimpleHandler(myProject, gitRoot(), "ls-remote"); h.addParameters("--heads", myRemote.getSelectedItem().toString()); - String output = GitHandlerUtil.doSynchronously(h, GitBundle.getString("pull.getting.remote.branches"), h.printCommandLine()); - if(output == null) { + String output = GitHandlerUtil.doSynchronously(h, GitBundle.getString("pull.getting.remote.branches"), h.printableCommandLine()); + if (output == null) { return; } myBranchChooser.removeAllElements(); - for(String line : output.split("\n")) { - if(line.length() == 0) { + for (String line : output.split("\n")) { + if (line.length() == 0) { continue; } int pos = line.lastIndexOf('/'); - if(pos == -1) { + if (pos == -1) { pos = line.lastIndexOf('\t'); } - myBranchChooser.addElement(line.substring(pos+1), false); + myBranchChooser.addElement(line.substring(pos + 1), false); } } }); @@ -188,21 +188,22 @@ public class GitPullDialog extends DialogWrapper { public GitLineHandler pullHandler() { GitLineHandler h = new GitLineHandler(myProject, gitRoot(), "pull"); h.addParameters("--no-stat"); - if(myNoCommitCheckBox.isSelected()) { + if (myNoCommitCheckBox.isSelected()) { h.addParameters("--no-commit"); - } else { - if(myAddLogInformationCheckBox.isSelected()) { + } + else { + if (myAddLogInformationCheckBox.isSelected()) { h.addParameters("--log"); } } - if(mySquashCommitCheckBox.isSelected()) { + if (mySquashCommitCheckBox.isSelected()) { h.addParameters("--squash"); } - if(myNoFastForwardCheckBox.isSelected()) { + if (myNoFastForwardCheckBox.isSelected()) { h.addParameters("--no-ff"); } String strategy = (String)myStrategy.getSelectedItem(); - if(!GitMergeUtil.DEFAULT_STRATEGY.equals(strategy)) { + if (!GitMergeUtil.DEFAULT_STRATEGY.equals(strategy)) { h.addParameters("--strategy", strategy); } h.addParameters("-v"); @@ -221,25 +222,26 @@ public class GitPullDialog extends DialogWrapper { myBranchChooser.removeAllElements(); GitRemote r = null; final int count = myRemote.getItemCount(); - for(int i = 0; i< count; i++) { + for (int i = 0; i < count; i++) { GitRemote candidate = (GitRemote)myRemote.getItemAt(i); - if(candidate.name().equals(item)) { + if (candidate.name().equals(item)) { r = candidate; break; } } - if(r == null) { + if (r == null) { return; } GitRemote.Info ri = r.localInfo(myProject, gitRoot()); String toSelect = ri.getRemoteForLocal(currentBranch()); - for(String trackedBranch : ri.trackedBranches()) { + for (String trackedBranch : ri.trackedBranches()) { myBranchChooser.addElement(trackedBranch, trackedBranch.equals(toSelect)); } } catch (VcsException e) { GitVcs.getInstance(myProject).showErrors(Collections.singletonList(e), GitBundle.getString("pull.retriving.remotes")); - } finally { + } + finally { validateDialog(); } } @@ -261,19 +263,19 @@ public class GitPullDialog extends DialogWrapper { List remotes = GitRemote.list(myProject, gitRoot()); String branch = currentBranch(); String remote = null; - if(branch!= null) { - remote = GitConfigUtil.getValue(myProject, gitRoot(), "branch."+branch+".remote"); + if (branch != null) { + remote = GitConfigUtil.getValue(myProject, gitRoot(), "branch." + branch + ".remote"); } myRemote.setRenderer(GitUIUtil.getGitRemoteListCellRenderer(remote)); GitRemote toSelect = null; myRemote.removeAllItems(); - for(GitRemote r : remotes) { + for (GitRemote r : remotes) { myRemote.addItem(r); - if(r.name().equals(remote)) { + if (r.name().equals(remote)) { toSelect = r; } } - if(toSelect != null) { + if (toSelect != null) { myRemote.setSelectedItem(toSelect); } } diff --git a/plugins/git4idea/src/git4idea/ui/GitUIUtil.java b/plugins/git4idea/src/git4idea/ui/GitUIUtil.java index 57e9a518f1..3da3a67470 100644 --- a/plugins/git4idea/src/git4idea/ui/GitUIUtil.java +++ b/plugins/git4idea/src/git4idea/ui/GitUIUtil.java @@ -68,14 +68,15 @@ public class GitUIUtil { final GitRemote remote = (GitRemote)value; String startName; String endName; - if(defaultRemote != null && defaultRemote.equals(remote.name())) { - startName=""; - endName=""; - } else { - startName=""; - endName=""; + if (defaultRemote != null && defaultRemote.equals(remote.name())) { + startName = ""; + endName = ""; } - String text = ""+startName+remote.name()+endName+" ("+remote.url()+")"; + else { + startName = ""; + endName = ""; + } + String text = "" + startName + remote.name() + endName + " (" + remote.url() + ")"; return super.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus); } }; -- 2.11.4.GIT