Skip to content

Commit bdb4b6d

Browse files
author
Jakub Ruzicka
committed
distgit: new -H/--commit-header-file option
allows custom commit message header for new-version, patch and amend actions: rdopkg patch --commit-header-file myfile Use '-' for stdin: echo 'My commit message' | rdopkg amend -H - Change-Id: I902f10132c9c7390629cc8ddd44ec39cc1d913d5 Fixes: #118
1 parent caedd0a commit bdb4b6d

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

rdopkg/actions/distgit/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
Arg('changelog', shortcut='-C',
7474
choices=['detect', 'count', 'plain'],
7575
help="how to generate changelog from patches"),
76+
Arg('commit_header_file', shortcut='-H', metavar='FILE',
77+
help="start commit message with FILE contents, "
78+
"- for stdin"),
7679
],
7780
steps=[
7881
Action('get_package_env'),
@@ -113,6 +116,9 @@
113116
Arg('bug', shortcut='-B', metavar='BUG(S)',
114117
help="reference BUG(S) in changelog. (example:"
115118
" --bug rhbz#1234,rhbz#5678)"),
119+
Arg('commit_header_file', shortcut='-H', metavar='FILE',
120+
help="start commit message with FILE contents, "
121+
"- for stdin"),
116122
],
117123
steps=[
118124
Action('get_package_env'),
@@ -149,7 +155,12 @@
149155
help="local git branch containing patches"),
150156
]),
151157
Action('amend', atomic=True,
152-
help="amend last commit and recreate commit message"),
158+
help="amend last commit and recreate commit message",
159+
optional_args=[
160+
Arg('commit_header_file', shortcut='-H', metavar='FILE',
161+
help="start commit message with FILE contents, "
162+
"- for stdin"),
163+
]),
153164
Action('squash', atomic=True,
154165
help="squash HEAD into HEAD~ using HEAD~ commit message"),
155166
Action('get_source', atomic=True, help="fetch source archive",

rdopkg/actions/distgit/actions.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import itertools
66
import os
77
import re
8+
import sys
89

910
from rdopkg.conf import cfg, cfg_files
1011
from rdopkg import exception
@@ -677,12 +678,20 @@ def new_sources(branch=None, fedpkg=FEDPKG, new_sources=False):
677678
run(*cmd, direct=True)
678679

679680

680-
def _commit_message(changes=None):
681+
def _commit_message(changes=None, header_file=None):
681682
if not changes:
682683
_, changes = specfile.Spec().get_last_changelog_entry(strip=True)
683684
if not changes:
684685
raise exception.IncompleteChangelog()
685-
if len(changes) == 1:
686+
if header_file:
687+
try:
688+
if header_file == '-':
689+
msg = sys.stdin.read()
690+
else:
691+
msg = open(header_file).read()
692+
except IOError as ex:
693+
raise exception.FileNotFound(msg=str(ex))
694+
elif len(changes) == 1:
686695
msg = re.sub(r'\s+\(.*\)\s*$', '', changes[0])
687696
else:
688697
msg = specfile.Spec().get_nvr(epoch=False)
@@ -700,17 +709,17 @@ def _commit_message(changes=None):
700709
return msg
701710

702711

703-
def commit_distgit_update(branch=None, amend=False):
712+
def commit_distgit_update(branch=None, amend=False, commit_header_file=None):
704713
_ensure_branch(branch)
705-
msg = _commit_message()
714+
msg = _commit_message(header_file=commit_header_file)
706715
cmd = ['commit', '-a', '-F', '-']
707716
if amend:
708717
cmd.append('--amend')
709718
git(*cmd, input=msg, print_output=True)
710719

711720

712-
def amend():
713-
msg = _commit_message()
721+
def amend(commit_header_file=None):
722+
msg = _commit_message(header_file=commit_header_file)
714723
git('commit', '-a', '--amend', '-F', '-', input=msg, print_output=True)
715724
print("")
716725
git('--no-pager', 'log', '--name-status', 'HEAD~..HEAD', direct=True)

0 commit comments

Comments
 (0)