def createTarGZArchive(self, folder_name): tar_name = folder_name + '.tar' tar_command = [ 'pax', '-wf', tar_name, folder_name] execute(tar_command) gzip_command = ['gzip', '-f', tar_name] execute(gzip_command)
def account(self): '''Return the name and email of the current git user.''' exit_code, output = execute([self.git, 'config', 'user.name']) name = output.strip() exit_code, output = execute([self.git, 'config', 'user.email']) email = output.strip() return '%s <%s>' % (name, email)
def publish(self, remote='origin'): """ Publish new branch to remote repo. """ exit_code, output = execute([ self.git, 'push', '--set-upstream', remote, self.branch_name]) return output.strip()
def clone(self, repo_uri, project_name): '''Clone the repository if it does not already exists.''' command = [self.git, 'clone', repo_uri, project_name] exit_code, output = execute(command) if exit_code != 0: print 'Failed to clone "%s".' % repo_uri sys.exit(1)
def last_commit(self): '''Return the comment of the last commit.''' command = [ self.git, 'log', "--pretty=format:'%h - %s'", '--date=short', '-1', ] exit_code, output = execute(command) return output.strip()
def pull(self, repo_uri='origin', branch='master'): '''Run git pull on the branch.''' command = [self.git, 'pull', repo_uri, branch] exit_code, output = execute(command) if exit_code != 0: print 'Failed to update repo "%s".' % repo_uri sys.exit(1)
def execute(self, *args, **kwargs): """ Shortcut to execute function. This is here to avoid importing the execute function and also help with testing. """ return execute(*args, **kwargs)
def branch_name(self): """ Return the name of the current git branch. $ git symbolic-ref HEAD refs/heads/production """ exit_code, output = execute([self.git, 'symbolic-ref', 'HEAD']) return output.strip().split('/')[-1]
def diffFileNames(self, ref='master'): """ Return a list of (action, filename) that have changed in comparison with `ref`. """ result = [] command = ['git', 'diff', '--name-status', '%s' % (ref)] exit_code, output = execute(command) if exit_code != 0: print 'Failed to diff files.' sys.exit(1) for line in output.splitlines(): action, name = line.split('\t') action = action.lower() result.append((action, name)) return result
def revision(self): '''Return the revision of the current git branch.''' command = [self.git, 'show', '-s', '--pretty=format:%t'] exit_code, output = execute(command) return output.strip()
def status(self): """ Publish new branch to remote repo. """ exit_code, output = execute([self.git, 'status', '-s']) return output.strip()
def push(self, remote='origin'): '''Push current changes.''' exit_code, output = execute([self.git, 'push', remote]) return output.strip()
def copyFile(self, source, destination, branch='master'): command = ['git', 'show', '%s:%s' % (branch, self.fs.join(source))] with open(self.fs.join(destination), 'w') as output_file: execute(command, output=output_file)