From 16eae678baa4631a72f58ab6f5c3688ca234e4a9 Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Tue, 5 Jan 2010 15:10:58 -0800 Subject: Add a clean function --- src/fedpkg/__init__.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src') diff --git a/src/fedpkg/__init__.py b/src/fedpkg/__init__.py index 99b3e5e..77bd658 100644 --- a/src/fedpkg/__init__.py +++ b/src/fedpkg/__init__.py @@ -91,6 +91,37 @@ def _get_build_arches_from_srpm(srpm, arches): raise FedpkgError('No compatible build arches found in %s' % srpm) return archlist +def clean(dry=False, useignore=True): + """Clean a module checkout of untracked files. + + Can optionally perform a dry-run + + Can optionally not use the ignore rules + + Returns output + + """ + + # setup the command, this could probably be done with some python api... + cmd = ['git', 'clean', '-f', '-d'] + if dry: + cmd.append('--dry-run') + if not useignore: + cmd.append('-x') + # Run it! + try: + proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + output = proc.communicate() + except OSError, e: + raise FedpkgError(e) + # See if we exited cleanly + if proc.returncode: + raise FedpkgError('%s returned %s: %s' % + (subprocess.list2cmdline(cmd), + proc.returncode, output[0])) + return output[0] + def clone(module, user, branch=None): """Clone a repo, optionally check out a specific branch. -- cgit