2011-12-08 65 views
0

下面是我的提交消息的鉤子,它適用於手動完成的所有合併和提交。當我嘗試用底墊中使用它,它停止說如何檢查rebase提交鉤子?

「這個分支僅用於合併提交,不能直接在這裏提交的代碼」。

它直接將代碼提交到默認值。這不是合併嗎?

需要掛鉤的是避免任何直接提交到默認分支,並承諾只應做的特性分支(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 

回答

1

好像RebaseExtension manual清楚地表明會發生什麼。

Rebase不合並(不是hg merge)。如果是這樣,爲什麼要重組,爲什麼不合並?實際上,在大多數情況下是,它更接近於使用修補程序隊列從它們的位置進行修改並移動到另一個父級。對於修訂歷史記錄,看起來您是否已經剝離了幾個修訂版,並將其他修訂版(實際上非​​常相似但實際上不同)放在新父版上。這就是爲什麼kwargs['parent2'] == ''是真的。

要看到究竟發生了什麼歷史,你最好仔細閱讀RebaseExtension manual

該操作涉及合併更改以解決原始父級和目標級別之間的衝突。當修補程序隊列無法幫助時,它使擴展可用:如果修補程序中的任何塊與目標文件內容不完全匹配,則無法通過隊列應用修補程序。但它只涉及文件內容,而不涉及歷史。畢竟,TortoiseHg也可以在更新操作期間合併本地更改,但它不是「hg合併」。

因此,重訂基期與禁止提交到「默認」分支的政策相矛盾,而且你似乎有一個相當不錯的鉤子,如果它停在這裏。我認爲你應該使用常規的合併命令將你的改變帶到分支。