如何检查钩子中的rebase提交?

2024-06-25 06:07:52 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我的提交消息钩子,它适用于所有手动完成的合并和提交。当我试着用它来做回扣的时候,别再说了

“此分支仅用于合并提交,不能在此处直接提交代码”。在

它直接将代码提交到默认值。这不是合并吗?在

hook的需要是避免任何直接提交到默认分支,并且提交应该只对特性分支(除了default之外的其他分支)执行。另外,如果在分支中没有遵循适当的命名约定,它将失败。在

请让我知道我怎样才能允许rebase提交或者如果我在钩子上遗漏了什么?在

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

Tags: branchdefaultuiforreturnifis分支
1条回答
网友
1楼 · 发布于 2024-06-25 06:07:52

似乎RebaseExtension manual清楚地表明了发生了什么。在

Rebase不是merge(不是hg merge)。如果是,为什么要重新设置基,为什么不合并?实际上,在大多数情况下,它更接近于使用补丁队列从它们的位置获取一些修订并转移到另一个父节点。对于修订历史来说,如果您已经剥离了几个修订,并提交了其他修订(非常相似,但实际上并不相同)来覆盖新的父级。这就是为什么kwargs['parent2'] == ''是真的。在

要想知道历史到底发生了什么,你最好仔细阅读RebaseExtension manual。在

该操作包括合并更改,以解决原始父级与目标父级之间的冲突。当补丁队列无能为力时,这就是扩展可用的原因:如果修补程序中的任何块与目标文件内容不完全匹配,则无法通过队列应用修补程序。但它只与档案内容有关,与历史无关。毕竟,TortoiseHg也可以在更新操作期间合并本地更改,但它不是“hg merge”。在

因此,重设基与您禁止提交到“default”分支的策略相矛盾,如果它停止在这里,您似乎有一个相当好的钩子。我认为您应该使用常规的merge命令将您的更改带到分支。在

相关问题 更多 >