2016-06-15 15 views
0

私はREADME.mdファイルの文字列パターンを見つけるためにGIT pre-commitフックを使用しています。ex。 {{STRING_PATTERN}}を編集し、文字列パターンを現在のブランチ名も含む希望のテキスト/コード出力に変更します。GITプリコミットフックの変更ファイルがコミットに追加されない

ここが問題です。 pre-commitスクリプトは、文字列パターンを見つけて正しいテキスト/コードに置き換えるという立場から働きますが、変更をコミットする前にこれを行うようには見えません。つまり、git commit -m "Updated README.md"を実行してgit statusチェックREADME.mdファイルは変更されていると表示され、実行する場合はgit push origin branch_name README.mdファイルには実際の{{STRING_PATTERN}}識別子(望ましくない)が含まれています。欲しい)。それだけではない - 私はこれはそれが文字列{{がstring_pattern}}識別子と、動的に作成されたテキスト/コードを使用してアップデートを見つけ観点から作業を行うことに注意してください、言ったようにここで

は、pre-commitコードです実際にそれらの変更をコミットすることが問題です。

#!/usr/bin/env bash 

# Echo out text to ensure pre-commit is running 
echo "pre-commit working" 

# Get the current branch name 
function git_branch { 
    git rev-parse --abbrev-ref HEAD 
} 

# Set branch variable to current branch 
branch=$(git_branch) 

# Define the string/pattern marker to search for 
# This pattern/string serves as a marker that 
# gets replaced with the dynamically created text/code 
id="{{STRING_PATTERN}}" 

# Dynamically create text/code 
# Inject the $branch variable into the correct location of the text 
updated_text="Example text containing that is being added to the $branch branch" 

# Find the string/pattern and replace it with the text/code 
# Then replace it with the build status image 
sed -i '' -e "s%{{STRING_PATTERN}}%$updated_text%g" README.md 

答えて

0

あなたはレポに変更を加えるために、プリコミットフックでもgit addを行う必要があります。

+0

あなたが 'git add'を追加すると、それはスクリプトの最後に追加されるべきことを意味しますか?それで 'sed'コードブロックを実行した後は?また、 'git commit'を再実行する必要があることを意味しませんか? – corey

+0

はい、まさに、スクリプトの最後に 'git add'があります –

関連する問題