git-submodule-integrate (878B)
1 #!/bin/sh 2 3 [ $# -ne 2 ] && { 4 printf "usage: $0 path_to_child subdir_in_parent" 1>&2 5 exit 1 6 } 7 8 if git diff-files --quiet || git diff-index --quiet --cached HEAD -- 9 then 10 printf "Changes in the index or working tree will be lost. Continue? [y/n]: " 11 read yn 12 case $yn in 13 [Yy]*) ;; 14 *) printf "No changes were made\n"; exit 1 ;; 15 esac 16 fi 17 18 child="$1" 19 where="$2" 20 21 # pull the child's objects into the parent 22 git fetch "$child" 23 24 total=$(git -C "$child" rev-list --count FETCH_HEAD) 25 finished=0 26 27 for commit in $(git -C "$child" rev-list --reverse FETCH_HEAD) 28 do 29 # read tree of new commit into index 30 git read-tree --prefix="$where" "$commit" 31 git commit --allow-empty -C "$commit" 32 git rm -q -r --cached "$where" 33 34 finished=$(( finished + 1 )) 35 printf "%s/%s finished\n" "$finished" "$total" 36 done 37 38 # force worktree to reflect updated HEAD 39 git checkout -f HEAD