Commits

Anonymous committed 79af9c2

optimize code

  • Participants
  • Parent commits a7c4bca
  • Branches develop

Comments (0)

Files changed (1)

File src/hgflow/hgflow.py

 
         return True
 
+    def hgflow_func_feature_finish(self, target_branch, name, tag_name):
+        '''finish this feature.
+        1, Check develop branch version and current feature
+        1, Close this branch
+        2, Merge it into develop
+        3, Commit develop branch
+        '''
+
+        if not self._findBranch(target_branch, name):
+            return 
+        commands.update(self.ui, self.repo, target_branch)
+        commands.commit(self.ui, self.repo, close_branch=True, message='hg flow, close feature %s' % (name,))
+
+        commands.update(self.ui, self.repo, self.developBranch)
+        commands.merge(self.ui, self.repo, target_branch)
+        #commands.commit(self.ui, self.repo, message='hg flow, merge feature `%s` to develop branch `%s`' % (target_branch, self.developBranch))
+        commands.commit(self.ui, self.repo, message='hg flow, merge release `%s` to develop branch `%s`' % (name, self.developBranch))
+        #self.outputln(_('WARNING: No automatic commit after merge from feature `%s`, you should resolve the confict (if any) then commit manually.' % (name,)))
 
     def hgflow_func_feature(self, args, opts):
         def _feature_func(action, name, target_branch, tag_name):
                 self._startBranch(target_branch, self.developBranch)
             
             elif 'finish' == action:
-                '''finish this feature.
-                1, Check develop branch version and current feature
-                1, Close this branch
-                2, Merge it into develop
-                3, Commit develop branch
-                '''
+                self.hgflow_func_feature_finish(target_branch, name, tag_name)
 
-                if not self._findBranch(target_branch, name):
-                    return 
-
-                commands.update(self.ui, self.repo, target_branch)
-                commands.commit(self.ui, self.repo, close_branch=True, message='hg flow, close feature %s' % (name,))
-
-                commands.update(self.ui, self.repo, self.developBranch)
-                commands.merge(self.ui, self.repo, target_branch)
-                #commands.commit(self.ui, self.repo, message='hg flow, merge feature `%s` to develop branch `%s`' % (target_branch, self.developBranch))
-                commands.commit(self.ui, self.repo, message='hg flow, merge release `%s` to develop branch `%s`' % (name, self.developBranch))
-                #self.outputln(_('WARNING: No automatic commit after merge from feature `%s`, you should resolve the confict (if any) then commit manually.' % (name,)))
 
             elif 'change' == action:
                 commands.update(self.ui, self.repo, target_branch)
 
         func(action, name, target_branch, tag_name)
 
+    def hgflow_func_release_finish(self, target_branch, name, tag_name):
+        '''finish this releas
+        1, Check publish branch version and current version
+        2, Close this branch
+        3, Merge it into publish branch
+        4, Tag publish branch with release branch name
+        5, Merge it into develop branch. Always not successed, should manully do that
+        '''
+
+        if not self._findBranch(target_branch, name):
+            return
+        if tag_name:
+            if not self._findTag(tag_name):
+                self.outputln(_('Tag `%s` not found.' % (tag_name,)))
+                return
+            else:
+                self._mergeIntoPublishBranch(target_branch, name, tag_name)
+        else:
+             self._mergeIntoPublishBranch(target_branch, name)
+
+
     def hgflow_func_release(self, args, opts):
         def _release_func(action, name, target_branch, tag_name):
             if 'start' == action:
                 '''
                 self._startBranch(target_branch, self.developBranch)
             elif 'finish' == action:
-                '''finish this release
-                1, Check publish branch version and current version
-                2, Close this branch
-                3, Merge it into publish branch
-                4, Tag publish branch with release branch name
-                5, Merge it into develop branch. Always not successed, should manully do that
-                '''
-
-                if not self._findBranch(target_branch, name):
-                    return
-
-                #merge tag to publish branch
-                if tag_name:
-                    if not self._findTag(tag_name):
-                        self.outputln(_('Tag `%s` not found.' % (tag_name,)))
-                        return
-                    else:
-                        self._mergeIntoPublishBranch(target_branch, name, tag_name)
-                else:
-                    self._mergeIntoPublishBranch(target_branch, name)
-
+                self.hgflow_func_release_finish(target_branch, name, tag_name)
             else:
                 self.outputln(_('Please give a valid action.'))
 
         self._hgflow_func_base(args, opts, self.releasePrefix, _release_func)
 
+    def hgflow_func_hotfix_finish(self, target_branch, name, tag_name):
+        '''finish the hotfix
+        1, Check publish branch version and current version
+        2, Close this branch
+        3, Merge it into publich branch
+        4, Tag publish branch with hotfix branch name
+        5, Merge it into develop branch. Always not successed, otherwise should manually do that
+        '''
+
+        if not self._findBranch(target_branch, name):
+            return
+
+        if tag_name:
+            if not self._findTag(tag_name):
+                self.outputln(_('Tag `%s` not found.' % (tag_name,)))
+                return
+            else:
+                self._mergeIntoPublishBranch(target_branch, name, tag_name)
+        else:
+            self._mergeIntoPublishBranch(target_branch, name)
+
+
+
     def hgflow_func_hotfix(self, args, opts):
         def _hotfix_func(action, name, target_branch, tag_name):
             if 'start' == action:
                 '''
                 self._startBranch(target_branch, self.publishBranch)
             elif 'finish' == action:
-                '''finish the hotfix
-                1, Check publish branch version and current version
-                2, Close this branch
-                3, Merge it into publich branch
-                4, Tag publish branch with hotfix branch name
-                5, Merge it into develop branch. Always not successed, otherwise should manually do that
-                '''
-
-                if not self._findBranch(target_branch, name):
-                    return
-
-                if tag_name:
-                    if not self._findTag(tag_name):
-                        self.outputln(_('Tag `%s` not found.' % (tag_name,)))
-                        return
-                    else:
-                        self._mergeIntoPublishBranch(target_branch, name, tag_name)
-                else:
-                    self._mergeIntoPublishBranch(target_branch, name)
-
+                self.hgflow_func_hotfix_finish(target_branch, name, tag_name)
             else:
                 self.outputln(_('Please give a valid action.'))
 
                 self.outputln('target_branch %s is not exists' % target_branch)
         else:
             if opts['finish']:
-                commands.update(self.ui, self.repo, target_branch)
-                commands.commit(self.ui, self.repo, close_branch=True, message='hg flow, close feature %s' % (name,))
-
-                commands.update(self.ui, self.repo, self.developBranch)
-                commands.merge(self.ui, self.repo, target_branch)
-                #commands.commit(self.ui, self.repo, message='hg flow, merge feature `%s` to develop branch `%s`' % (target_branch, self.developBranch))
-                commands.commit(self.ui, self.repo, message='hg flow, merge release `%s` to develop branch `%s`' % (name, self.developBranch))
-                #self.outputln(_('WARNING: No automatic commit after merge from feature `%s`, you should resolve the confict (if any) then commit manually.' % (name,)))
+                self.hgflow_func_feature_finish(target_branch, name, tag_name)
             elif opts['close']:
                 return
             elif opts['switch']:
                 self.outputln('target_branch %s is not exists' % target_branch)
         else:
             if opts['finish']:
-                if tag_name:
-                    if not self._findTag(tag_name):
-                        self.outputln(_('Tag `%s` not found.' % (tag_name,)))
-                        return
-                    else:
-                        self._mergeIntoPublishBranch(target_branch, name, tag_name)
-                else:
-                    self._mergeIntoPublishBranch(target_branch, name)
+                self.hgflow_func_release_finish(target_branch, name, tag_name)
             elif opts['close']:
                 return
             elif opts['switch']:
                 self.outputln('target_branch %s is not exists' % target_branch)
         else:
             if opts['finish']:
-                if tag_name:
-                    if not self._findTag(tag_name):
-                        self.outputln(_('Tag `%s` not found.' % (tag_name,)))
-                        return
-                    else:
-                        self._mergeIntoPublishBranch(target_branch, name, tag_name)
-                else:
-                    self._mergeIntoPublishBranch(target_branch, name)
+                self.hgflow_func_hotfix_finish(target_branch, name, tag_name)
             elif opts['close']:
                 return
             elif opts['switch']: