Esempio n. 1
0
    def cmd_push(self, flags, remote, branch):
        cur_remote, cur_branch = self.get_cur_remote_branch()
        remote, branch = remote or cur_remote, branch or cur_branch
        #self._assert_remote_branch(remote, branch)
        available_branch = self.get_available_remote_branches(remote)
        if 'force' in flags:
            args = self._get_args_list(flags) + [remote, branch]
            self.git.push(args)
            output = Color.green('Push --force completed')
        elif branch not in available_branch:
            output = Color.green(
                self.git.push(remote, branch) or 'Push completed (New Branch)')
        elif not self._is_ahead_commit(remote, branch):
            output = Color.yellow('Nothing to commit')
        else:
            if self._is_behind_commit(remote, branch):
                if 'rebase' not in flags:
                    raise ValueError(
                        'Merge is not allowed. You need to use --rebase to push'
                    )
                self.cmd_rebase(remote, branch)
            output = Color.green(
                self.git.push(remote, branch) or 'Push completed')

        return output
Esempio n. 2
0
    def cmd_commit(self, flags, message):
        if not message: output = Color.red('Commit message cannot be empty')
        elif not self._has_local_changes():
            output = Color.yellow('There is not local changes')
        else:
            flags['-m'] = message
            args = self._get_args_list(flags)
            output = Color.green(self.git.commit(args))

        return output
Esempio n. 3
0
 def cmd_checkout(self, flags, branch_name, from_branch=None):
     available_branches = self.get_available_local_branches()
     if not branch_name: raise ValueError('Branch name missing')
     if '-b' in flags:
         if branch_name in available_branches:
             raise ValueError(
                 'Failing creating branch "%s". Already exists' %
                 branch_name)
         if from_branch: self.git.checkout(['-b', flags['-b'], from_branch])
         else: self.git.checkout(['-b', flags['-b']])
         output = Color.green(('New branch %s created' % flags['-b']) +
                              (' from %s' %
                               from_branch if from_branch else ''))
     else:
         if from_branch: raise ValueError('Invalid syntax')
         if branch_name not in available_branches:
             raise ValueError('Branch "%s" does not exists.' % branch_name)
         self.git.checkout(branch_name)
         output = Color.green('Checkout %s branch' % branch_name)
     return output
Esempio n. 4
0
    def cmd_reset(self, flags, remote, branch):
        self._assert_remote_branch(remote, branch)
        try:
            if 'stash' in flags and self._has_local_changes():
                stashed = self.git.stash(u=True)
            if 'soft' in flags:
                args = ['--soft'] + ([branch] if remote is None else
                                     [remote + '/' + branch])
                self.git.reset(args)
                output = Color.green(
                    'Reset soft was executed on %s' %
                    (branch if remote is None else remote + '/' + branch))
            elif 'hard' in flags:
                args = ['--hard'] + ([branch] if remote is None else
                                     [remote + '/' + branch])
                output = Color.green(self.git.reset(args))
            else:
                raise ValueError('Invalid mode')
        finally:
            if 'stashed' in locals() and stashed: self.git.stash('pop')

        return output
Esempio n. 5
0
    def cmd_clean(self, remote, branch):
        self._assert_remote_branch(remote, branch)
        cur_remote, cur_branch = self.get_cur_remote_branch()
        if cur_branch == branch:
            raise ValueError('Cannot remove branch in use "%s"' % branch)

        self.git.branch(['-D', branch])
        output = Color.green('Branch "%s" was removed' % branch)

        if not remote: return output

        available_remotes = self.get_available_remotes()
        if remote not in available_remotes:
            raise ValueError('Remote "%s" was not found' % remote)
        available_remote_branches = self.get_available_remote_branches(remote)
        if branch in available_remote_branches:
            self.git.push([remote, ':' + branch])
            output += "\n" + Color.green('Remove branch "%s/%s" removed' %
                                         (remote, branch))
        else:
            output += "\n" + Color.yellow('Remote branch "%s/%s" not found' %
                                          (remote, branch))
        return output