From c016b58883aac19abc5e269e53ab69d9fe2c711d Mon Sep 17 00:00:00 2001 From: clime Date: Apr 04 2018 22:00:35 +0000 Subject: adjust git commit --- diff --git a/rpkg.bash b/rpkg.bash index ec32f5e..4cc39a6 100644 --- a/rpkg.bash +++ b/rpkg.bash @@ -116,7 +116,7 @@ _rpkg() after="package" ;; commit|ci) - options="--push --clog --raw --tag" + options="--push --tag" options_string="--message" options_file="--file" after="file" diff --git a/rpkglib/cli.py b/rpkglib/cli.py index ebd0f8f..db11bb6 100644 --- a/rpkglib/cli.py +++ b/rpkglib/cli.py @@ -211,6 +211,46 @@ class rpkgClient(cliClient): self.cmd.dump_spec_only = True self.cmd.load_spec() + def commit(self): + if self.args.with_changelog and not self.args.message: + raise rpkgError('--with-changelog must be used with -m together.') + + if self.args.message and self.args.with_changelog: + # Compose commit message with a summary and content into a file. + self.cmd.clog(True) + clog_file = os.path.abspath(os.path.join(self.args.path, 'clog')) + commit_msg_file = os.path.abspath(os.path.join(self.args.path, 'commit-message')) + with open(commit_msg_file, 'w') as commit_msg: + commit_msg.write(self.args.message) + commit_msg.write('\n\n') + with open(clog_file, 'r') as clog: + commit_msg.write(clog.read()) + self.args.file = commit_msg_file + os.remove(clog_file) + # This assignment is a magic because commit message is in the file + # commit-message already. + self.args.message = None + + try: + self.cmd.commit(self.args.message, self.args.file, self.args.files, self.args.signoff) + if self.args.tag: + self.cmd.dump_spec_only = True + self.cmd.version_bump = True + self.cmd.add_tag() + except Exception: + if self.args.tag: + self.log.error('Could not commit, will not tag!') + if self.args.push: + self.log.error('Could not commit, will not push!') + raise + finally: + if self.args.with_changelog and os.path.isfile(self.args.file): + os.remove(self.args.file) + del self.args.file + + if self.args.push: + self.push() + def copr_build(self): srpm_path = self.srpm() @@ -388,3 +428,46 @@ man page. tag_parser.add_argument( 'tag', nargs='?', default=None, help='Name of the tag') tag_parser.set_defaults(command=self.tag) + + def register_commit(self): + """Register the commit target and ci alias""" + commit_parser = self.subparsers.add_parser( + 'commit', help='Commit changes', + description='This invokes a git commit. All tracked files with ' + 'changes will be committed unless a specific file ' + 'list is provided. $EDITOR will be used to generate a' + ' changelog message unless one is given to the ' + 'command. A tag or push can be done at the same time.') + commit_parser.add_argument( + '-m', '--message', default=None, + help='Use the given as the commit message summary') + commit_parser.add_argument( + '--with-changelog', + action='store_true', + default=None, + help='Get the last changelog from SPEC as commit message content. ' + 'This option must be used with -m together.') + commit_parser.add_argument( + '-t', '--tag', default=False, action='store_true', + help='Create a tag for this commit') + commit_parser.add_argument( + '-F', '--file', default=None, + help='Take the commit message from the given file') + # allow one to commit /and/ push at the same time. + commit_parser.add_argument( + '-p', '--push', default=False, action='store_true', + help='Commit and push as one action') + # Allow a list of files to be committed instead of everything + commit_parser.add_argument( + 'files', nargs='*', default=[], + help='Optional list of specific files to commit') + commit_parser.add_argument( + '-s', '--signoff', default=False, action='store_true', + help='Include a signed-off-by') + commit_parser.set_defaults(command=self.commit) + + # Add a ci alias + ci_parser = self.subparsers.add_parser( + 'ci', parents=[commit_parser], conflict_handler='resolve', + help='Alias for commit') + ci_parser.set_defaults(command=self.commit)