Skip to content

Instantly share code, notes, and snippets.

@jukben
Last active January 22, 2019 15:20
Show Gist options
  • Save jukben/d17d52ca225a926e9cabf135ac1c0b7f to your computer and use it in GitHub Desktop.
Save jukben/d17d52ca225a926e9cabf135ac1c0b7f to your computer and use it in GitHub Desktop.
git-master-branch-changed-files.sh
#!/bin/bash
# This is complementary script to our lint-staged setup. This is a bit of magic, but please bare with me.
# This script finds new files during the CI job (compared to the master), and
# 1. prints all the files in all commits which are not in the master
# 2. sorts them and unique them
# 3. we care just for src/*.tsx?
# 4. ignore return code of grep :)
# http://mywiki.wooledge.org/BashFAQ/105
set -e
# During the PR you might have created files and then deleted them in another commit,
# those files will be considered as touched so we need to filter them out
fileExists() {
while IFS= read -r f; do
if [ -f $f ]; then
echo $f;
fi
done
}
git log HEAD --not origin/master --no-merges --name-status --pretty=format: \
| awk '{print $2}' \
| sort -u \
| uniq -u \
| grep '.tsx\?$' \
| grep 'src/' \
| fileExists \
| cat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment