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