Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #18 from vdechenaux/only-git-changed
Browse files Browse the repository at this point in the history
Add option to coke only Git changed files
  • Loading branch information
b-viguier authored May 16, 2017
2 parents 9df20fc + 5b53f33 commit b11b5ee
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ standard=Symfony2
# Verbose mode (optional - default: false)
verbose=true
# Only Git changed mode (optional - default: false)
only-git-changed=true
# White list of files and directories (optional)
src/
test.php
Expand Down Expand Up @@ -47,6 +50,7 @@ The order of arguments is not important
`src test.php` Files/Directories to include in the check
`--standard=Symfony2` Standard to use for check
`--ignore=Tests,src/OldFile.php` URL patterns to ignore in the check
`--only-git-changed` Check only changed files
`-v` Use verbose mode


Expand Down
38 changes: 38 additions & 0 deletions coke
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ignored=0
allowed=0
verbose=0
fix=0
onlyGitChanged=0

function allow
{
Expand Down Expand Up @@ -104,6 +105,9 @@ do
elif [ "${CUR_PARAM:2:5}" = "fix" ]
then
fix=1
elif [ "${CUR_PARAM:2:16}" = "only-git-changed" ]
then
onlyGitChanged=1
else
params="$params $CUR_PARAM"
fi
Expand Down Expand Up @@ -159,6 +163,9 @@ then
elif [ "$verbose" -eq 0 ] && [ "${ligne:0:8}" = "verbose=" ] && [ "${ligne:8}" = "true" ]
then
verbose=1
elif [ "$onlyGitChanged" -eq 0 ] && [ "${ligne:0:17}" = "only-git-changed=" ] && [ "${ligne:17}" = "true" ]
then
onlyGitChanged=1
elif [ "$ignored" -eq 0 ] && [ "${ligne:0:1}" = "!" ]
then
ignore "${ligne:1}"
Expand Down Expand Up @@ -195,6 +202,37 @@ then
$commandPath$command --config-set installed_paths $standardPath
fi

# Check Git changes

if [ $onlyGitChanged -eq 1 ]
then
command -v git >/dev/null 2>&1 || { fail "Cannot find git. Git is required when --only-git-changed is used."; }

filesAllowedAndChanged=""
for file in $(git --no-pager diff --name-only --diff-filter=MARC)
do
allowed=0

for ligne in $filesAllowed
do
if [ "${ligne:0:1}" = '!' ] && [[ "$file" == *"${ligne:1}"* ]]
then
continue 2
elif [[ "$file" == "$ligne"* ]]
then
allowed=1
fi
done

if [ "$allowed" -eq 1 ]
then
filesAllowedAndChanged="$filesAllowedAndChanged $file"
fi
done

filesAllowed=$filesAllowedAndChanged
fi

# Punch it!

if [ -n "$filesAllowed" ]
Expand Down

0 comments on commit b11b5ee

Please sign in to comment.