-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
copy the pre-commit-hook into this repository and convert it to py3 #23
Conversation
Signed-off-by: Sebastian Wagner <[email protected]>
Signed-off-by: Sebastian Wagner <[email protected]>
Signed-off-by: Sebastian Wagner <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pre-commit hook for adding the "Resolves: rhbz#..." is completely unnecessary. It can easily be performed with the git interpret-trailers
command.
def which(executable): | ||
locations = ( | ||
'/usr/local/bin', | ||
'/bin', | ||
'/usr/bin', | ||
'/usr/local/sbin', | ||
'/usr/sbin', | ||
'/sbin', | ||
) | ||
|
||
for location in locations: | ||
executable_path = os.path.join(location, executable) | ||
if os.path.exists(executable_path): | ||
return executable_path | ||
|
||
GIT = which('git') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shutil.which()
?
def prepend_commit_msg(branch): | ||
"""Prepend the commit message with `text`""" | ||
msgfile = sys.argv[1] | ||
with open(msgfile) as f: | ||
contents = f.read() | ||
|
||
if not branch: | ||
return contents | ||
|
||
try: | ||
prefix, ticket_id = branch.split('-') | ||
ticket_id = int(ticket_id) | ||
except ValueError: | ||
# We used to raise here, but if cherry-picking to a different branch | ||
# that doesn't comply it would break preventing the cherry-pick. So we | ||
# print out the warning, but end up returning the contents. | ||
print('skipping commit msg change: Branch name "%s" does not follow required format: {tracker}-{ID}' % branch) # NOQA | ||
return contents | ||
|
||
if prefix == 'wip': | ||
# Skip "wip" branches, ie "work in progress" | ||
return contents | ||
|
||
resolves_line = "\nResolves: %s#%s" % (prefix.lower(), ticket_id) | ||
|
||
with open(msgfile, 'a') as f: | ||
# Don't append if it's already there | ||
if resolves_line not in contents: | ||
f.write(resolves_line) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we're invoking the git command, this could be easily done with git interpret-trailers
command:
subprocess.run(['git', 'interpret-trailers', f'--trailer Resolves: rhbz#{ticket_id}', '--in-place', sys.argv[1]], shell=True, check=True)
That said, a pre-commit hook is not needed for this, and IMHO it should rather be done with interepreter trailers:
- git('-c', 'core.editor=/bin/true', 'cherry-pick', '-x', '%s~..%s' % (first, last))
+ git('-c', 'core.editor=/bin/true', 'cherry-pick', '-x', '--no-commit', '%s~..%s' % (first, last))
+ git('commit', '--trailer "Resolves: rhbz#{$bz}"', '--no-edit')
# Merge this rhbz branch back into our starting branch.
git('checkout', starting_branch)
git('merge', '--ff-only', 'rhbz-' + bz)
git('branch', '-d', 'rhbz-' + bz)
also the hook fails:
|
Are we ok with using #24 instead? |
Fixes #22