From 0fc89bcdb4bbbded6c56e98b54426d34988b857c Mon Sep 17 00:00:00 2001 From: Ben Finney Date: Sun, 29 Jan 2017 13:17:04 +1100 Subject: Extract a function to clean the working tree. --- gbp/scripts/buildpackage.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'gbp/scripts/buildpackage.py') diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index 7638c855..e5812046 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -240,6 +240,26 @@ def prepare_output_dir(dir): return output_dir +def clean_working_tree(options, repo): + """ + Clean the working tree. + + :param options: Program run-time options, as an + `optparse.OptionContainer`. + :param repo: The Git repository, as a `DebianGitRepository`. + :raise GbpError: When the working tree has uncommitted + changes. + :return: None. + """ + Command(options.cleaner, shell=True)() + if not options.ignore_new: + (ret, out) = repo.is_clean() + if not ret: + gbp.log.err("You have uncommitted changes in your source tree:") + gbp.log.err(out) + raise GbpError("Use --git-ignore-new to ignore.") + + def pristine_tar_prepare_orig_tree(repo, cp, options): """Make sure the upstream tree exists In case of component tarballs we need to recreate a tree for the @@ -671,13 +691,7 @@ def main(argv): return 1 try: - Command(options.cleaner, shell=True)() - if not options.ignore_new: - (ret, out) = repo.is_clean() - if not ret: - gbp.log.err("You have uncommitted changes in your source tree:") - gbp.log.err(out) - raise GbpError("Use --git-ignore-new to ignore.") + clean_working_tree(options, repo) try: branch = repo.get_branch() -- cgit v1.2.3