From 062fcc17bc5dd92d86c4b7e9b588f2e88accf751 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Aug 06 2021 14:17:24 +0000 Subject: Make sure all commits have a proper subject Until the first empty line, Git will always consider all of the commit message to be part of the subject line. When generating the clog from the RPM changelog, this means that all lines in the changelog end up as part of the subject. This patch reworks the clog() function to always have a distinct subject line, either by accepting the `-m` argument or by treating the first line of the changelog as special and inserting an extra newline for it. Signed-off-by: Stephen Gallagher --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index ae82697..142df55 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -2342,7 +2342,7 @@ class Commands(object): self.kojiweburl, task_id) return task_id - def clog(self, raw=False): + def clog(self, raw=False, subject=None): """Write the latest spec changelog entry to a clog file""" spec_file = os.path.join(self.path, self.spec) @@ -2360,7 +2360,11 @@ class Commands(object): if proc.returncode > 0: raise rpkgError(stderr.strip()) - clog_lines = [] + firstline = True + if subject: + clog_lines = [subject + "\n", "\n"] + else: + clog_lines = [] buf = six.StringIO(stdout) for line in buf: if line == '\n' or line.startswith('$'): @@ -2375,6 +2379,12 @@ class Commands(object): clog_lines.append(line) else: clog_lines.append(line.replace('- ', '', 1)) + if firstline and not subject: + # Add a newline after the first line to ensure that Git doesn't + # concatenate them all as the subject. + clog_lines.append("\n") + firstline = False + buf.close() # Now open the clog file and write out the lines diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index f64a97f..0d3eb76 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1974,23 +1974,11 @@ class cliClient(object): 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: - # Combose 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) + if self.args.clog or (self.args.message and self.args.with_changelog): + self.cmd.clog(raw=self.args.raw, subject=self.args.message) # This assignment is a magic because commit message is in the file # commit-message already. self.args.message = None - elif self.args.clog: - self.cmd.clog(self.args.raw) self.args.file = os.path.abspath(os.path.join(self.args.path, 'clog')) # It is okay without specifying either -m or --clog. Changes will be