Commit Merge in Mercurial added and Cancel renamed to Abort Merge Commit_Merge_addition

Fri, 23 Aug 2019 02:02:42 +0300

author
Christos Sevastiadis <csevast@auth.gr>
date
Fri, 23 Aug 2019 02:02:42 +0300
branch
Commit_Merge_addition
changeset 7152
a99df2004bb7
parent 7150
cfe71cde2eec
child 7153
ca02892fde13
child 7160
14c139167b6e

Commit Merge in Mercurial added and Cancel renamed to Abort Merge

eric6/Plugins/VcsPlugins/vcsMercurial/HgCommitDialog.py file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsMercurial/ProjectHelper.py file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsMercurial/hg.py file | annotate | diff | comparison | revisions
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/HgCommitDialog.py	Thu Aug 22 15:47:14 2019 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/HgCommitDialog.py	Fri Aug 23 02:02:42 2019 +0300
@@ -25,13 +25,14 @@
     accepted = pyqtSignal()
     rejected = pyqtSignal()
     
-    def __init__(self, vcs, msg, mq, parent=None):
+    def __init__(self, vcs, msg, mq, merge, parent=None):
         """
         Constructor
         
         @param vcs reference to the vcs object
         @param msg initial message (string)
         @param mq flag indicating a queue commit (boolean)
+        @param merge flag indicating a merge commit (boolean)
         @param parent parent widget (QWidget)
         """
         super(HgCommitDialog, self).__init__(parent, Qt.WindowFlags(Qt.Window))
@@ -41,7 +42,7 @@
         
         self.logEdit.setPlainText(msg)
         
-        if mq:
+        if mq or merge:
             self.amendCheckBox.setVisible(False)
             self.subrepoCheckBox.setVisible(False)
         else:
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/ProjectHelper.py	Thu Aug 22 15:47:14 2019 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/ProjectHelper.py	Fri Aug 23 02:02:42 2019 +0300
@@ -419,20 +419,34 @@
         self.vcsMergeAct.triggered.connect(self._vcsMerge)
         self.actions.append(self.vcsMergeAct)
         
-        self.hgCancelMergeAct = E5Action(
-            self.tr('Cancel uncommitted merge'),
-            self.tr('Cancel uncommitted merge'),
+        self.hgCommitMergeAct = E5Action(
+            self.tr('Commit Merge'),
+            self.tr('Commit Merge'),
+            0, 0, self, 'mercurial_commit_merge')
+        self.hgCommitMergeAct.setStatusTip(self.tr(
+            'Commit a merge.'
+            ))
+        self.hgCommitMergeAct.setWhatsThis(self.tr(
+            """<b>Commit a merge</b>"""
+            """<p>This commits a merge working directory</p>"""
+            ))
+        self.hgCommitMergeAct.triggered.connect(self.__hgCommitMerge)
+        self.actions.append(self.hgCommitMergeAct)
+        
+        self.hgAbortMergeAct = E5Action(
+            self.tr('Abort Merge'),
+            self.tr('Abort Merge'),
             0, 0, self, 'mercurial_cancel_merge')
-        self.hgCancelMergeAct.setStatusTip(self.tr(
-            'Cancel an uncommitted merge and lose all changes'
+        self.hgAbortMergeAct.setStatusTip(self.tr(
+            'Abort an uncommitted merge and lose all changes'
         ))
-        self.hgCancelMergeAct.setWhatsThis(self.tr(
-            """<b>Cancel uncommitted merge</b>"""
-            """<p>This cancels an uncommitted merge causing all changes"""
+        self.hgAbortMergeAct.setWhatsThis(self.tr(
+            """<b>Abort uncommitted merge</b>"""
+            """<p>This aborts an uncommitted merge causing all changes"""
             """ to be lost.</p>"""
         ))
-        self.hgCancelMergeAct.triggered.connect(self.__hgCancelMerge)
-        self.actions.append(self.hgCancelMergeAct)
+        self.hgAbortMergeAct.triggered.connect(self.__hgAbortMerge)
+        self.actions.append(self.hgAbortMergeAct)
         
         self.hgReMergeAct = E5Action(
             self.tr('Re-Merge'),
@@ -1298,6 +1312,8 @@
         self.hgBookmarkOutgoingAct.setEnabled(self.vcs.canPush())
         if self.vcs.version >= (3, 8):
             self.hgBookmarkPushCurrentAct.setEnabled(self.vcs.canPull())
+        self.hgCommitMergeAct.setEnabled(
+            self.vcs.canCommitMerge(self.project.ppath))
     
     def initMenu(self, menu):
         """
@@ -1434,7 +1450,8 @@
         mergeMenu.addAction(self.vcsResolveAct)
         mergeMenu.addAction(self.hgUnresolveAct)
         mergeMenu.addAction(self.hgReMergeAct)
-        mergeMenu.addAction(self.hgCancelMergeAct)
+        mergeMenu.addAction(self.hgCommitMergeAct)
+        mergeMenu.addAction(self.hgAbortMergeAct)
         
         act = menu.addAction(
             UI.PixmapCache.getIcon(
@@ -1533,6 +1550,7 @@
         toolbarManager.addAction(self.vcsRevertAct, title)
         toolbarManager.addAction(self.vcsMergeAct, title)
         toolbarManager.addAction(self.hgReMergeAct, title)
+        toolbarManager.addAction(self.hgCommitMergeAct, title)
         toolbarManager.addAction(self.vcsTagAct, title)
         toolbarManager.addAction(self.hgBranchAct, title)
         toolbarManager.addAction(self.vcsSwitchAct, title)
@@ -1705,12 +1723,18 @@
         unresolved.
         """
         self.vcs.hgResolved(self.project.ppath, unresolve=True)
-    
-    def __hgCancelMerge(self):
+
+    def __hgCommitMerge(self):
+        """
+        Private slot used to commit a merge.
         """
-        Private slot used to cancel an uncommitted merge.
+        self.vcs.vcsCommit(self.project.ppath, 'Merge', merge=True)
+    
+    def __hgAbortMerge(self):
         """
-        self.vcs.hgCancelMerge(self.project.ppath)
+        Private slot used to abort an uncommitted merge.
+        """
+        self.vcs.hgAbortMerge(self.project.ppath)
     
     def __hgShowConflicts(self):
         """
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/hg.py	Thu Aug 22 15:47:14 2019 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/hg.py	Fri Aug 23 02:02:42 2019 +0300
@@ -394,7 +394,7 @@
         return status
     
     def vcsCommit(self, name, message, noDialog=False, closeBranch=False,
-                  mq=False):
+                  mq=False, merge=False):
         """
         Public method used to make the change of a file/directory permanent
         in the Mercurial repository.
@@ -405,10 +405,11 @@
         @param noDialog flag indicating quiet operations
         @keyparam closeBranch flag indicating a close branch commit (boolean)
         @keyparam mq flag indicating a queue commit (boolean)
+        @keyparam merge flag indicating a merge commit (boolean)
         """
         msg = message
         
-        if mq:
+        if mq or merge:
             # ensure dialog is shown for a queue commit
             noDialog = False
         
@@ -416,7 +417,8 @@
             # call CommitDialog and get message from there
             if self.__commitDialog is None:
                 from .HgCommitDialog import HgCommitDialog
-                self.__commitDialog = HgCommitDialog(self, msg, mq, self.__ui)
+                self.__commitDialog = HgCommitDialog(self, msg, mq, merge, 
+                                                     self.__ui)
                 self.__commitDialog.accepted.connect(self.__vcsCommit_Step2)
             self.__commitDialog.show()
             self.__commitDialog.raise_()
@@ -427,6 +429,7 @@
         self.__commitData["noDialog"] = noDialog
         self.__commitData["closeBranch"] = closeBranch
         self.__commitData["mq"] = mq
+        self.__commitData["merge"] = merge
         
         if noDialog:
             self.__vcsCommit_Step2()
@@ -440,6 +443,7 @@
         noDialog = self.__commitData["noDialog"]
         closeBranch = self.__commitData["closeBranch"]
         mq = self.__commitData["mq"]
+        merge = self.__commitData["merge"]
         
         if not noDialog:
             # check, if there are unsaved changes, that should be committed
@@ -509,6 +513,8 @@
         args.append("-v")
         if mq:
             args.append("--mq")
+        elif merge:
+            ...
         else:
             if closeBranch:
                 args.append("--close-branch")
@@ -2134,12 +2140,12 @@
             dia.exec_()
         self.checkVCSStatus()
     
-    def hgCancelMerge(self, name):
+    def hgAbortMerge(self, name):
         """
-        Public method to cancel an uncommitted merge.
+        Public method to abort an uncommitted merge.
         
         @param name file/directory name (string)
-        @return flag indicating, that the cancellation contained an add
+        @return flag indicating, that the abortion contained an add
             or delete (boolean)
         """
         dname, fname = self.splitPath(name)
@@ -2159,7 +2165,7 @@
             args.append("--clean")
         
         dia = HgDialog(
-            self.tr('Canceling uncommitted merge'),
+            self.tr('Aborting uncommitted merge'),
             self)
         res = dia.startProcess(args, repodir, False)
         if res:
@@ -3350,6 +3356,44 @@
                         not line.strip().endswith("="):
                     self.__defaultPushConfigured = True
     
+    def canCommitMerge(self, name):
+        """
+        Public method to check if the working directory is uncommitted merge.
+ 
+        @param name file/directory name (string)
+ 
+        @return flag indicating commit merge capability (boolean)
+        """
+        dname, fname = self.splitPath(name)
+        
+        # find the root of the repo
+        repodir = dname
+        while not os.path.isdir(os.path.join(repodir, self.adminDir)):
+            repodir = os.path.dirname(repodir)
+            if os.path.splitdrive(repodir)[1] == os.sep:
+                return
+        
+        args = self.initCommand("identify")
+        
+        output = ""
+        if self.__client is None:
+            process = QProcess()
+            process.setWorkingDirectory(repodir)
+            process.start('hg', args)
+            procStarted = process.waitForStarted(5000)
+            if procStarted:
+                finished = process.waitForFinished(30000)
+                if finished and process.exitCode() == 0:
+                    output = str(process.readAllStandardOutput(),
+                                 self.getEncoding(), 'replace')
+        else:
+            output, error = self.__client.runcommand(args)
+        
+        if output.count('+') == 2:
+            return True
+        else:
+            return False
+
     def canPull(self):
         """
         Public method to check, if pull is possible.

eric ide

mercurial