# HG changeset patch # User jrice@netbeans.org # Date 1202841488 0 # Node ID be8a3d03a906525eb9309b59f082e71075c93e59 # Parent ac5302568e6bdccef8e21032aa32af71b896b21b #125835: Push to default set automatically after Clone, hg clone only sets default not default-push if there is no hgrc file diff -r ac5302568e6b -r be8a3d03a906 mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java --- a/mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java Mon Feb 11 11:26:01 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/config/HgConfigFiles.java Tue Feb 12 18:38:08 2008 +0000 @@ -86,8 +86,8 @@ public class HgConfigFiles { private static final String WINDOWS_USER_APPDATA = getAPPDATA(); private static final String WINDOWS_CONFIG_DIR = WINDOWS_USER_APPDATA + "\\Mercurial"; // NOI18N private static final String WINDOWS_GLOBAL_CONFIG_DIR = getGlobalAPPDATA() + "\\Mercurial"; // NOI18N - private static final String HG_RC_FILE = "hgrc"; // NOI18N - private static final String HG_REPO_DIR = ".hg"; // NOI18N + public static final String HG_RC_FILE = "hgrc"; // NOI18N + public static final String HG_REPO_DIR = ".hg"; // NOI18N /** * Creates a new instance diff -r ac5302568e6b -r be8a3d03a906 mercurial/src/org/netbeans/modules/mercurial/ui/clone/CloneAction.java --- a/mercurial/src/org/netbeans/modules/mercurial/ui/clone/CloneAction.java Mon Feb 11 11:26:01 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/clone/CloneAction.java Tue Feb 12 18:38:08 2008 +0000 @@ -44,8 +44,11 @@ import org.netbeans.modules.versioning.s import org.netbeans.modules.versioning.spi.VCSContext; import javax.swing.*; import java.awt.event.ActionEvent; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; import java.io.FileWriter; +import java.io.PrintWriter; import java.util.List; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; @@ -53,12 +56,12 @@ import org.netbeans.modules.mercurial.Hg import org.netbeans.modules.mercurial.HgProgressSupport; import org.netbeans.modules.mercurial.Mercurial; import org.netbeans.modules.mercurial.HgModuleConfig; +import org.netbeans.modules.mercurial.config.HgConfigFiles; import org.netbeans.modules.mercurial.util.HgCommand; import org.netbeans.modules.mercurial.util.HgUtils; -import org.netbeans.modules.mercurial.util.HgRepositoryContextCache; import org.netbeans.modules.mercurial.util.HgProjectUtils; -import org.netbeans.modules.mercurial.ui.clone.Clone; import org.netbeans.modules.mercurial.ui.actions.ContextAction; +import org.netbeans.modules.mercurial.ui.properties.HgProperties; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.DialogDisplayer; @@ -211,27 +214,19 @@ public class CloneAction extends Context NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex); DialogDisplayer.getDefault().notifyLater(e); }finally { + // #125835 - Push to default was not being set automatically by hg after Clone + // but was after you opened the Mercurial -> Properties, inconsistent + HgConfigFiles hg = new HgConfigFiles(cloneFolder); + String defaultPull = hg.getDefaultPull(false); + String defaultPush = hg.getDefaultPush(false); + hg.setProperty(HgProperties.HGPROPNAME_DEFAULT_PULL, defaultPull); + hg.setProperty(HgProperties.HGPROPNAME_DEFAULT_PUSH, defaultPush); + //#121581: Work around for ini4j bug on Windows not handling single '\' correctly // hg clone creates the default hgrc, we just overwrite it's contents with // default path contianing '\\' - if(isLocalClone && Utilities.isWindows()){ - File f = new File(cloneFolder.getAbsolutePath() + File.separator + ".hg", "hgrc"); - if(f.isFile() && f.canWrite()){ - FileWriter fw = null; - try { - fw = new FileWriter(f); - fw.write("[paths]\n"); - fw.write("default = " + source.replace("\\", "\\\\") + "\n"); - } catch (IOException ex) { - // Ignore - } finally { - try { - fw.close(); - } catch (IOException ex) { - // Ignore - } - } - } + if(isLocalClone && Utilities.isWindows()){ + fixLocalPullPushPathsOnWindows(cloneFolder.getAbsolutePath(), defaultPull, defaultPush); } if(!isLocalClone){ HgUtils.outputMercurialTabInRed(NbBundle.getMessage(CloneAction.class, "MSG_CLONE_DONE")); // NOI18N @@ -246,4 +241,67 @@ public class CloneAction extends Context public boolean isEnabled() { return HgUtils.getRootFile(context) != null; } + + private static final String HG_PATHS_SECTION_ENCLOSED = "[" + HgConfigFiles.HG_PATHS_SECTION + "]";// NOI18N + private static void fixLocalPullPushPathsOnWindows(String root, String defaultPull, String defaultPush) { + File hgrcFile = null; + File tempFile = null; + BufferedReader br = null; + PrintWriter pw = null; + + try { + hgrcFile = new File(root + File.separator + HgConfigFiles.HG_REPO_DIR, HgConfigFiles.HG_RC_FILE); + if (!hgrcFile.isFile() || !hgrcFile.canWrite()) return; + + String defaultPullWinStr = HgConfigFiles.HG_DEFAULT_PULL_VALUE + " = " + defaultPull.replace("\\", "\\\\") + "\n"; // NOI18N + String defaultPushWinStr = HgConfigFiles.HG_DEFAULT_PUSH_VALUE + " = " + defaultPush.replace("\\", "\\\\") + "\n"; // NOI18N + + tempFile = new File(hgrcFile.getAbsolutePath() + ".tmp"); // NOI18N + if (!tempFile.isFile() || !tempFile.canWrite()) return; + + br = new BufferedReader(new FileReader(hgrcFile)); + pw = new PrintWriter(new FileWriter(tempFile)); + + String line = null; + + boolean bInPaths = false; + boolean bPullDone = false; + boolean bPushDone = false; + while ((line = br.readLine()) != null) { + if (line.startsWith(HG_PATHS_SECTION_ENCLOSED)) { + bInPaths = true; + }else if (line.startsWith("[")) { // NOI18N + bInPaths = false; + } + + if (bInPaths && !bPullDone && line.startsWith(HgConfigFiles.HG_DEFAULT_PULL_VALUE) && + !line.startsWith(HgConfigFiles.HG_DEFAULT_PUSH_VALUE)) { + pw.println(defaultPullWinStr); + bPullDone = true; + } else if (bInPaths && !bPullDone && line.startsWith(HgConfigFiles.HG_DEFAULT_PULL)) { + pw.println(defaultPullWinStr); + bPullDone = true; + } else if (bInPaths && !bPushDone && line.startsWith(HgConfigFiles.HG_DEFAULT_PUSH_VALUE)) { + pw.println(defaultPushWinStr); + bPushDone = true; + } else { + pw.println(line); + pw.flush(); + } + } + } catch (IOException ex) { + // Ignore + } finally { + try { + if(pw != null) pw.close(); + if(br != null) br.close(); + if(tempFile != null && tempFile.isFile() && tempFile.canWrite() && hgrcFile != null){ + hgrcFile.delete(); + tempFile.renameTo(hgrcFile); + } + } catch (IOException ex) { + // Ignore + } + } + } } diff -r ac5302568e6b -r be8a3d03a906 mercurial/src/org/netbeans/modules/mercurial/ui/properties/HgProperties.java --- a/mercurial/src/org/netbeans/modules/mercurial/ui/properties/HgProperties.java Mon Feb 11 11:26:01 2008 +0000 +++ b/mercurial/src/org/netbeans/modules/mercurial/ui/properties/HgProperties.java Tue Feb 12 18:38:08 2008 +0000 @@ -85,9 +85,9 @@ import org.openide.NotifyDescriptor; */ public class HgProperties implements ListSelectionListener { - private static final String HGPROPNAME_USERNAME = "username"; // NOI18N - private static final String HGPROPNAME_DEFAULT_PULL = "default-pull"; // NOI18N - private static final String HGPROPNAME_DEFAULT_PUSH = "default-push"; // NOI18N + public static final String HGPROPNAME_USERNAME = "username"; // NOI18N + public static final String HGPROPNAME_DEFAULT_PULL = "default-pull"; // NOI18N + public static final String HGPROPNAME_DEFAULT_PUSH = "default-push"; // NOI18N private PropertiesPanel panel; private File root;