From 2da8c0160ca2078c1091a385cc0254e383505c88 Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Thu, 24 Jun 2010 22:37:55 -0700 Subject: Add a commit function This should work well whether you're on a real tty or not, but I didn't test it for the "not a tty" aspect. --- src/pyfedpkg/__init__.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py index e0c27c1..cc977fe 100644 --- a/src/pyfedpkg/__init__.py +++ b/src/pyfedpkg/__init__.py @@ -587,6 +587,41 @@ class PackageModule: clogfile.writelines(cloglines) return + def commit(self, message=None, file=None, files=[]): + """Commit changes to a module. + + Can take a message to use as the commit message + + a file to find the commit message within + + and a list of files to commit. + + Requires the caller be a real tty or a message passed. + + Logs the output and returns nothing. + + """ + + # First lets see if we got a message or we're on a real tty: + if not sys.stdin.isatty(): + if not message or not file: + raise FedpkgError('Must have a commit message or be on a real tty.') + + # construct the git command + # We do this via subprocess because the git module is terrible. + cmd = ['git', 'commit'] + if message: + cmd.extend(['-m', message]) + elif file: + cmd.extend(['-F', os.path.abspath(file)]) + if not files: + cmd.append('-a') + else: + cmd.extend(files) + # make it so + _run_command(cmd) + return + def compile(self, arch=None, short=False): """Run rpm -bc on a module -- cgit