-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List files if "$to_ref" == "$z40" first init repo #112
Comments
Check out the examples section in our docs, it has a few examples of your case to_ref == z40 https://external-hooks.reconquest.io/docs/example.bitbucket-add_hook_javascript_linter/ so basically you just need to retrieve list of commits:
|
My bash script: #!/bin/bash
failed=false
export PATH="$PATH:/usr/local/bin"
EXT_FILES='\.kt$|\.kts$'
FIRST_INIT="0000000000000000000000000000000000000000"
LINT_PARAMS='--relative --editorconfig=./.editorconfig'
echo "Checked files: ${EXT_FILES}"
while read from_ref to_ref ref_name; do
if [[ $from_ref = $FIRST_INIT ]]
then
echo " FIRST INIT for repo/branch"
TEMPDIR=$(mktemp -d)
echo $TEMPDIR
git cat-file -p "$to_ref:.editorconfig" > "$TEMPDIR/.editorconfig"
echo " Old value: $from_ref"
echo " New value: $to_ref"
echo " Ref name: $ref_name"
boundaries=($(git rev-list --simplify-by-decoration -2 "$to_ref"))
echo "boundaries=${boundaries}"
commits=($(git rev-list "${boundaries[0]}".."$to_ref"))
echo "commits=${commits[@]}"
for commit in "${commits[@]}"; do
files=($(git show --name-only ${commit} | grep -E ${EXT_FILES}))
for file in "${files[@]}"; do
mkdir -p "$TEMPDIR/$(dirname "$file")"
git cat-file -p "$to_ref:${file}" > "$TEMPDIR/$file"
echo "Checked files = ${file}"
done
done
echo "#files=${#files}"
if [[ ${#files} -eq 0 ]]; then
echo "no ${EXT_FILES} files found, skipping"
#rm -rf "$TEMPDIR"
continue
fi
cd "$TEMPDIR"
echo -e "\n FIRST_INIT: KtLint running "
ktlint "${LINT_PARAMS}" "${files[@]}"
if [[ $? -ne 0 ]]
then
echo " KtLint: changeset $from_ref → $to_ref has not passed checks"
failed=true
else
echo " FIRST_INIT: KtLint succesfull"
fi
#rm -rf "$TEMPDIR"
if $failed; then
exit 1
else
exit 0
fi
else
echo "No FIRST_INIT: repositories/branch"
fi
done Command execute:
In out:
|
Which version of Bitbucket and External Hooks add-on are you using? |
Feel free to re-open the issue if you still have any questions. |
how can I get all list of files during the first repository initialization (when there are no commits yet)?
The text was updated successfully, but these errors were encountered: