Yujie Wu  committed ec581c8 Merge

flow: Merged <hotfix/0.9.6> 'fix_finish_commit_bug' to <hotfix/0.9.6> ('hotfix/0.9.6').

  • Participants
  • Parent commits 80c7f65, b27a6b2
  • Branches hotfix/0.9.6

Comments (0)

Files changed (1)

File src/

             if (value in [None, ""]) :
+            # If the command is `hg commit --message <commit-hint> --force-editor [other-options...]`, we will drop the
+            # `--message <commit-hint> --force-editor` part from the command string because `--force-editor` is not a command
+            # option (it avails only programmatically).
+            if (cmd == "commit" and (key in ["message", "force_editor",]) and "force_editor" in kwarg) :
+                continue
             new_key = ""
             for e in key :
                 new_key += "-" if (e == "_") else e
         Construct a C{Flow} instance that will execute the workflow.
         Construction will fail if the C{flow} extension has not been initialized for the repository.
         A warning message will be issued if the repository has uncommitted changes.
         @type  init: C{boolean}
         @param init: If true, a C{Flow} object will be constructed for initialization of hgflow. Such constructed object does
                      not supply all functionalities and is only meant to execute the `hg flow init` command.
-    def _commit_change( self, opt, erase_branch = False ) :
+    def _commit_change( self, opt, commit_hint, is_erasing = False ) :
         Commit the changes in the workspace.
         Note that this method can potentially mutate C{opt}. Specifically, it will delete the C{commit} and C{message} keys if
                     will be used as the commit message. It is OK for both of the options to be missing. But it would trigger
                     an error if C{message} is given without C{commit} set to true. There is no special treatment on other
                     keys, and they will be passed to the C{hg commit} command as is.
+        @rtype : C{bool}
+        @return: Return `True' if committing was successfully done, or `False' if it was not.
         if (opt.get( "commit" )) :
             del opt["commit"]
+            msg = opt.get( "message" )
+            if (msg is None) :
+                opt["force_editor"] = True
+                opt["message"] = "\n\nHG: flow: %s" % commit_hint
             self._commit( **opt )
-            try :
-                del opt["message"]
-            except KeyError :
-                pass
+            del opt["message"]
+            if (msg is None) :
+                del opt["force_editor"]
+            return True
         elif (opt.get( "message" )) :
-            if (erase_branch) :
+            if (is_erasing) :
                 del opt["message"]
             else :
                 raise AbortFlow( "Cannot use the specified commit message.", "Did you forget to specify the -c option?" )
+        return False
     def _action_finish( self, stream, *arg, **kwarg ) :
                 raise AbortFlow( "'--erase' cannot be applied to branches with multiple merge destinations." )
         # Commits changes (if any) in the current branch.
-        self._commit_change( kwarg, should_erase )
+        is_commit_done = self._commit_change( kwarg, "Finishing '%s' branch" % curr_workspace, should_erase )
+        # If the commit was done successfully, we don't check against uncommitted changes.
+        # This is particularly needed for dry run.
+        if (not is_commit_done and self._has_uncommitted_changes()) :
+            raise AbortFlow( "Cannot finish '%s' branch because it has uncommitted changes." % curr_workspace )
         # For destin streams without trunks, we need to create a branch in each of these destin streams.
         # Each newly created branch will be named after the pattern: <stream-prefix>/<current-branch-basename> and will be from
         # the current branch. The current branch will be closed. Note that there is no need to merge the current branch because
- -c --commit        Commit changes before close the branch.
+ -c --commit        Commit changes before closing the branch.
  -m --message TEXT  Record TEXT as commit message.
  -p --stamp TEXT    Append TEXT to all commit messages.
  -d --date DATE     Record the specified DATE as commit date.