Jeff Gaston | ca0bc71 | 2021-01-14 19:32:39 -0500 | [diff] [blame] | 1 | set -e |
| 2 | |
| 3 | if [ ! -e .git ]; then |
| 4 | echo "This script must be run from the root of the git repository" |
| 5 | exit 1 |
| 6 | fi |
| 7 | |
| 8 | function usage() { |
| 9 | echo "Usage: split_change_into_owners.sh <commit message>" |
| 10 | echo |
| 11 | echo "Splits changes in the current repository based on OWNERS files" |
| 12 | exit 1 |
| 13 | } |
| 14 | |
| 15 | commitMessage="$1" |
| 16 | if [ "$commitMessage" == "" ]; then |
| 17 | usage |
| 18 | fi |
| 19 | |
| 20 | ownersFiles="$(find -name OWNERS)" |
| 21 | ownedDirs="$(echo "$ownersFiles" | sed 's|/OWNERS||' | sort -r)" |
| 22 | |
| 23 | for d in $ownedDirs; do |
| 24 | git add "$d" |
| 25 | if git status | grep -i "changes to be committed" >/dev/null; then |
| 26 | echo making commit for "$d" |
| 27 | git commit -m "$commitMessage |
| 28 | |
| 29 | This change includes files under $d" |
| 30 | fi |
| 31 | done |