Reputation: 13025
Below is my hook for commit message it works fine for all merges and commits which is manually done. When I try to use it with rebase it stop saying
"This branch is only for Merge Commits, cannot commit the code directly here" .
It is directly committing the code to default. Is that not a merge?
The need of hook is to avoid any direct commits to default branch and commit should only be done to the feature branch (other branches other than default). Also if a proper naming convention is not followed in the branch it will fail.
Please let me know how can I allow rebase commits or if I'm missing anything on the hook?
import re
def commitmessage(ui, repo, *args, **kwargs):
changectx = repo[kwargs['node']]
if changectx.branch() == 'default' :
if kwargs['parent2'] == '':
if changectx.rev() == 0:
return 0
tagsfilepresent = 0
totalfiles = 0
for aFile in changectx.files():
totalfiles = totalfiles + 1
if aFile == '.hgtags':
tagsfilepresent = 1
if totalfiles == 1 and tagsfilepresent == 1:
return 0
ui.write(changectx.branch() + ' This branch is only for Merge Commits, cannot commit the code directly here\n\n')
return 1
secondarybranchname = repo[kwargs['parent2']].branch()
ui.write('Merging ' + secondarybranchname + ' to default\n')
ui.write('Merge Commit Successful to default for ticket: ' + secondarybranchname[1:] + '\n')
return 0
m = re.match('^t(\d{4,5})$', changectx.branch())
if m:
ui.write('Commit Successful to ' + m.group(1) + '\n')
return 0
else:
ui.write('Branch name is not Acceptable, it should be either default or t(numeric)\n')
return 1
ui.write('If you think this special case is not handled here, please notify' + '\n')
return 1
Upvotes: 0
Views: 166
Reputation: 7661
Seems like RebaseExtension manual clearly shows what happens.
Rebase is not merge (not hg merge
). If it was, why rebase, why not merge? Actually, in most cases it is closer to using the patch queue to take some revisions from their place and move to another parent. For the revision history it looks like if you've stripped several revisions and committed others (very similar but not the same actually) over the new parent. That's why kwargs['parent2'] == ''
is true.
To see what exactly happens to history, you'd better read the RebaseExtension manual carefully.
The operation involves merging of changes in order to resolve conflicts between the original parent and the target one. It is what makes the extension usable when the patch queue cannot help: you cannot apply a patch through the queue if any hunk in the patch doesn't match exactly with the target file contents. But it only relates to files contents, not to the history. After all, TortoiseHg can also merge local changes during an update operation, but it's not a 'hg merge'.
So, rebasing contradicts with your policy of prohibiting commits to the 'default' branch, and you seem to have a rather good hook if it stops here. I think you should use regular merge command to bring your changes to the branch.
Upvotes: 1