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
def run(self): """ :param str git_cmd: :rtype list(str) """ if len(self.packages) == 0: print(Color.red('There is not packages selected')) exit(-1) global pool_packages print(Color.yellow('Following command "git %s" is about to run on:\n' % self.git_cmd)) for package in self.packages: print("\t" + package.get_name()) # raw_input(Color.green('\n\nPress Enter to continue...')) for package in self.packages: pool_packages.add(package.get_name()) if self.pool: self.pool.apply_async(execute_package, [package, self.git_cmd, self.git_args], callback=lambda output, package=package: competed_package(package, output)) else: output = execute_package(package, self.git_cmd, self.git_args) competed_package(package, output) if not self.pool: return try: while len(pool_packages): print "Waiting packages: %s" % str(pool_packages) time.sleep(1) except KeyboardInterrupt: terminate = True; print "Interrupt!!!" else: terminate = False; if terminate: self.pool.terminate() print "Waiting threads to complete"; self.pool.close() print "Waiting threads to wrap-up"; self.pool.join()
def cmd_diff(self, flags, remote, branch): cur_remote, cur_branch = self.get_cur_remote_branch() branch = branch or cur_branch self._assert_remote_branch(remote, branch) list_args = self._get_args_list(flags) if remote: list_args += ['%s/%s' % (remote, branch)] else: list_args += [branch] output = self.git.diff(*list_args) if not output: output = Color.yellow("There is not changes") return output
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
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