2016-04-06 5 views
0

私は、次の文字列は、コミットされていないファイルに存在している場合は、私のローカルのWindowsのMercurialのリポジトリへのコミットを防ぐために探しています:Windows上で文字列を含むMercurial Commitを防ぐ方法は?

は私に

をコミットしない私はhook I needを事前にコミットすることを知っていますpretxncommitです。動作しているようですegrepを、私は、FINDSTR /I /C:"do not commit"を持っているの代替として

[hooks] 
pretxncommit.donotcommitme = hg export tip | (! grep -E -q -i 'do not commit me') 

(テスト/検証this linkからの引用ではなく)

:私はLinux上だったら、私はちょうどこのような何かをするだろう良い。しかし、私は上記のLinuxの例のようにその結果を "無効にする"ものは何も見つかりません。

純粋なコマンドプロンプトコマンドの代わりに、大きなバイナリをチェックするthis PowerShell scriptを実行しました。しかし、私はPowerShellを知らないので、この全部が私には見えません。

Python、Cygwin、またはその他のものをインストールすることなく、私が何をしたのか簡単に知る人はいますか?または、上記のPowerShellスクリプトをファイルサイズの検査ではなく文字列検査に適応させる方法を知っていますか?

TortoiseHGも使用していますので、純粋なMercurialではなくTortoiseHGを使用することもできます。

答えて

0

PowerShellの部分が私が予想していたよりも簡単だったことが分かります。私はちょうどthis gistに基づいて自分の簡単なスクリプトを書くことになった。

# This is like an "include" needed for the MessageBox 
Add-Type -AssemblyName System.Windows.Forms 

function Show-MessageBox() 
{ 
    $message = "Found a ""DO NOT COMMIT ME"" message in your code!`r`n`r`nIf you are doing a pull or rebase this is probably okay.`r`n`r`nCommit anyway?" 
    $title = "DO NOT COMMIT ME DETECTED!" 
    $buttons = [System.Windows.Forms.MessageBoxButtons]::YesNo 
    $icon = [System.Windows.Forms.MessageBoxIcon]::Warning 

    [System.Windows.Forms.MessageBox]::Show($message, $title, $buttons, $icon) 
} 

# Use `hg export` to search for the string "do not commit me" (case insensitive) 
write "Checking for DO NOT COMMIT ME comments in your code..." 
$whoops = (hg export tip | Select-String -pattern "do not commit me"); 

# If we have it in our changeset, abort the commit! 
if ($whoops) 
{ 
    $a = Show-MessageBox 

    if ($a -eq "Yes") 
    { 
     write "`r`n!!! COMMITING ANYWAY !!!`r`n" 
     exit 0 
    } 

    write "`r`n*** ABORTING COMMIT! ***`r`n" 
    exit 1 
} 

write "Okay to commit!" 
exit 0 

注:

は、ここでは、interstedているすべての人のためである私も(管理者としてPowerShellを実行している間)Set-ExecutionPolicy RemoteSignedでPowerShellスクリプトを実行する機能をオンにする必要がありました。コマンドライン-ExecutionPolicy Bypassフラグが正しく動作せず、TortoiseHGであらゆる種類の問題が発生しました!

関連する問題