diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2017-02-08 08:11:56 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2017-02-08 08:11:56 +0000 |
commit | 12592ce0fd1f3f9123620d6bbc79d4ac2c75dd2f (patch) | |
tree | ed391ec42f4d46a9e2b55f25a257a198a63fda79 |
First version of construct-tree.sh
... this one doesn't work.
-rwxr-xr-x | construct-tree.sh | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/construct-tree.sh b/construct-tree.sh new file mode 100755 index 0000000..4298f93 --- /dev/null +++ b/construct-tree.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +set -e + +files=() +verbose="" +verbose_opt="" + +OPTS="`getopt -o v -l verbose -- "$@"`" +while [ $# -gt 0 ]; do + case $1 in + -v|--verbose) verbose="set -x"; verbose_opt="$1" ;; + *) break ;; + esac + shift +done + +$verbose + +if [ $# -gt 1 ]; then + echo "ERROR: wrong arguments: $@" +fi + +declare -a files +declare -A indices +. ./file-index.map + +for file in "${files[@]}"; do + if [ x"$(git diff -- $file | wc -l)" = x"0" ]; then + continue + fi + + orig_tag=$(git rev-parse HEAD) + + index=${indices["$file"]} + tag=$(echo "${index}_$@" | tr "_" "\n" | sort -n | tr "\n" "_" \ + | sed -e "s/^_//g" -e "s/__/_/g" -e "s/_\$/\n/") + echo "Starting $tag" + + if git rev-parse --verify $tag >/dev/null 2>&1; then + git stash >/dev/null + parents="$(git rev-list --parents -n 1 $tag | cut -d" " -f 2-)" + echo "Merging $parents" + git merge -m $tag $parents >/dev/null + git stash pop >/dev/null + + for branch in $(git br --contains $tag | grep -v "^*"); do + echo "Deleting branch: $branch" + git br -D $branch >/dev/null + done + else + echo "Committing $file" + git add $file + git ci -m $tag >/dev/null + fi + + git br $tag + + echo "Recursing into $tag: $(git rev-parse $tag)" + + $0 $verbose_opt $tag + + echo "Finished $tag: $(git rev-parse $tag)" + git reset $orig_tag >/dev/null +done |