def push(self, repo=None, src=None, dst=None, ff_only=True): """ Push changes to the remote repo @param repo: repository to push to @type repo: C{str} @param src: the source ref to push @type src: C{str} @param dst: the name of the destination ref to push to @type dst: C{str} @param ff_only: only push if it's a fast forward update @type ff_only: C{bool} """ args = GitArgs() args.add_cond(repo, repo) # Allow for src == '' to delete dst on the remote if src != None: refspec = src if dst: refspec += ':%s' % dst if not ff_only: refspec = '+%s' % refspec args.add(refspec) self._git_command("push", args.args)
def get_commits(self, since=None, until=None, paths=None, num=0, first_parent=False, options=None): """ Get commits from since to until touching paths @param since: commit to start from @type since: C{str} @param until: last commit to get @type until: C{str} @param paths: only list commits touching paths @type paths: C{list} of C{str} @param num: maximum number of commits to fetch @type num: C{int} @param options: list of additional options passed to git log @type options: C{list} of C{str}ings @param first_parent: only follow first parent when seeing a merge commit @type first_parent: C{bool} """ args = GitArgs('--pretty=format:%H') args.add_true(num, '-%d' % num) args.add_true(first_parent, '--first-parent') args.add_true(since and until, '%s..%s' % (since, until)) args.add_cond(options, options) args.add("--") if isinstance(paths, basestring): paths = [ paths ] args.add_cond(paths, paths) commits, ret = self._git_getoutput('log', args.args) if ret: where = " on %s" % paths if paths else "" raise GitRepositoryError("Error getting commits %s..%s%s" % (since, until, where)) return [ commit.strip() for commit in commits ]
def format_patches(self, start, end, output_dir, signature=True, thread=None): """ Output the commits between start and end as patches in output_dir """ options = GitArgs('-N', '-k', '-o', output_dir) options.add_cond(not signature, '--no-signature') options.add('%s...%s' % (start, end)) options.add_cond(thread, '--thread=%s' % thread, '--no-thread') output, ret = self._git_getoutput('format-patch', options.args) return [ line.strip() for line in output ]
def merge(self, commit, verbose=False, edit=False): """ Merge changes from the named commit into the current branch @param commit: the commit to merge from (usually a branch name or tag) @type commit: C{str} @param verbose: whether to print a summary after the merge @type verbose: C{bool} @param edit: wheter to invoke an editor to edit the merge message @type edit: C{bool} """ args = GitArgs() args.add_cond(verbose, '--summary', '--no-summary') args.add_cond(edit, '--edit', '--no-edit') args.add(commit) self._git_command("merge", args.args)
def fetch(self, repo=None, tags=False, depth=0): """ Download objects and refs from another repository. @param repo: repository to fetch from @type repo: C{str} @param tags: whether to fetch all tag objects @type tags: C{bool} @param depth: deepen the history of (shallow) repository to depth I{depth} @type depth: C{int} """ args = GitArgs('--quiet') args.add_true(tags, '--tags') args.add_cond(depth, '--depth=%s' % depth) args.add_cond(repo, repo) self._git_command("fetch", args.args)
def rev_parse(self, name, short=0): """ Find the SHA1 of a given name @param name: the name to look for @type name: C{str} @param short: try to abbreviate SHA1 to given length @type short: C{int} @return: the name's sha1 @rtype: C{str} """ args = GitArgs("--quiet", "--verify") args.add_cond(short, '--short=%d' % short) args.add(name) sha, ret = self._git_getoutput('rev-parse', args.args) if ret: raise GitRepositoryError("revision '%s' not found" % name) return sha[0].strip()