diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-01-12 15:21:51 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2012-01-23 23:13:31 +0100 |
commit | f7ca58752638cd160051f174d43536f68beae5f9 (patch) | |
tree | c93fdb0b7a31554134be2304c1e116841d34ead2 /gbp | |
parent | b7d70164b9fa04e389d5ad03767eef04aad0f40a (diff) |
GitRepository: allow git.commit_dir to create new branches
commit_dir creates new orphan branch if the given branch is not found
and create_missing_branch is allowed.
Diffstat (limited to 'gbp')
-rw-r--r-- | gbp/git/repository.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 024a377..7a510f0 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -899,7 +899,7 @@ class GitRepository(object): self._commit(msg=msg, args=files, author_info=author_info) def commit_dir(self, unpack_dir, msg, branch, other_parents=None, - author={}, committer={}): + author={}, committer={}, create_missing_branch=False): """ Replace the current tip of branch I{branch} with the contents from I{unpack_dir} @@ -915,6 +915,9 @@ class GitRepository(object): @type author: C{dict} with keys I{name}, I{email}, I{date} @param committer: committer information to use for commit @type committer: C{dict} with keys I{name}, I{email}, I{date} + @param create_missing_branch: create I{branch} as detached branch if it + doesn't already exist. + @type create_missing_branch: C{bool} """ git_index_file = os.path.join(self.path, self._git_dir, 'gbp_index') @@ -927,7 +930,14 @@ class GitRepository(object): tree = self.write_tree(git_index_file) if branch: - cur = self.rev_parse(branch) + try: + cur = self.rev_parse(branch) + except GitRepositoryError: + if create_missing_branch == True: + log.debug("Will create missing branch '%s'..." % branch) + cur = None + else: + raise else: # emtpy repo cur = None branch = 'master' |