diff options
author | Guido Günther <agx@sigxcpu.org> | 2017-08-11 15:42:55 -0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2017-08-12 15:55:21 -0300 |
commit | 5bc0968a759d3a7f7527c502bfe55cbc8a7326f3 (patch) | |
tree | 6bae0bdc690397f7b18d80ddaea64c109bc03e91 /gbp/scripts/buildpackage.py | |
parent | 9830f439f352b9d79a0030ff0a173f9a7e66e4d7 (diff) |
buildpackage: move branch setting and check to separate method
to make things more expressive
Gbp-Dch: Ignore
Diffstat (limited to 'gbp/scripts/buildpackage.py')
-rwxr-xr-x | gbp/scripts/buildpackage.py | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index 1238a16b..617c6edb 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -327,6 +327,27 @@ def changes_file_name(source, build_dir, dpkg_args): changes_file_suffix(dpkg_args))) +def check_branch(repo, options): + """ + Check if we're on the right branch and bail out otherwise + + returns: the current branch or C{None} if in detached head mode + """ + branch = None + try: + branch = repo.get_branch() + except GitRepositoryError: + # Not being on any branch is o.k. with --git-ignore-branch + if not options.ignore_branch: + raise + + ignore = options.ignore_new or options.ignore_branch + if branch != options.debian_branch and not ignore: + gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch)) + raise GbpError("Use --git-ignore-branch to ignore or --git-debian-branch to set the branch name.") + return branch + + def build_parser(name, prefix=None): try: parser = GbpOptionParserDebian(command=os.path.basename(name), prefix=prefix) @@ -482,19 +503,7 @@ def main(argv): try: clean_working_tree(options, repo) - - try: - branch = repo.get_branch() - except GitRepositoryError: - # Not being on any branch is o.k. with --git-ignore-branch - if not options.ignore_branch: - raise - - if not options.ignore_new and not options.ignore_branch: - if branch != options.debian_branch: - gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch)) - raise GbpError("Use --git-ignore-branch to ignore or --git-debian-branch to set the branch name.") - + branch = check_branch(repo, options) head = repo.head tree = maybe_write_tree(repo, options) source = source_vfs(repo, options, tree) |