Przeglądaj źródła

Improve subtree subdir caching

Willy-JL 1 rok temu
rodzic
commit
8c9a5017e5

+ 34 - 0
.utils/.check-merge.sh

@@ -0,0 +1,34 @@
+#!/bin/bash
+set -e
+
+if [ "$(git rev-parse --show-prefix)" != "" ]; then
+    echo "Must be in root of git repo!"
+    exit
+fi
+
+if [ "${1}" = "" ] || [ "${2}" = "" ]; then
+    echo "Usage: <path> <repo url> <merge output>"
+    exit
+fi
+path="${1}"
+repo="${2}"
+result="${3}"
+
+if grep "Automatic merge failed; fix conflicts and then commit the result." <<< "$result" > /dev/null; then
+    echo "MERGE_MSG: Merge ${path} from ${repo}"
+    notify-send -a Git -i git "Subtree merge failed" "Resolve current index to continue" &> /dev/null | true
+    while true; do
+        echo "Resolve current index then press Enter..."
+        read
+        if git diff --quiet && git diff --cached --quiet && git merge HEAD &> /dev/null; then
+            break
+        fi
+        sleep 1
+    done
+fi
+if grep "Please commit your changes or stash them before you switch branches." <<< "$result" > /dev/null; then
+    exit 1
+fi
+if grep "^fatal: " <<< "$result" > /dev/null; then
+    exit 1
+fi

+ 9 - 3
.utils/subtree-subdir-helper.sh → .utils/.subtree-subdir-helper.sh

@@ -16,7 +16,7 @@ branch="${3}"
 subdir="${4}"
 subdir="${4}"
 action="${5}"
 action="${5}"
 
 
-prev="$(git branch --show-current)"
+prevbranch="$(git branch --show-current)"
 temp="$(rev <<< "${repo%/}" | cut -d/ -f1,2 | rev | tr / -)-$(tr / - <<< "${branch}")"
 temp="$(rev <<< "${repo%/}" | cut -d/ -f1,2 | rev | tr / -)-$(tr / - <<< "${branch}")"
 fetch="_fetch-${temp}"
 fetch="_fetch-${temp}"
 split="_split-${temp}-$(tr / - <<< "${subdir}")"
 split="_split-${temp}-$(tr / - <<< "${subdir}")"
@@ -44,9 +44,15 @@ else
     if grep "^fatal: " <<< "$result" > /dev/null; then
     if grep "^fatal: " <<< "$result" > /dev/null; then
         ok=false
         ok=false
     fi
     fi
-    git checkout "${prev}"
+    git checkout "${prevbranch}"
     if $ok; then
     if $ok; then
-        git subtree "${action}" -P "${path}" "${split}" -m "${action^} ${path} from ${repo}"
+        prevhead="$(git rev-parse HEAD)"
+        exec {capture}>&1
+        result="$(git subtree "${action}" -P "${path}" "${split}" -m "${action^} ${path} from ${repo}" 2>&1 | tee /proc/self/fd/$capture)"
+        bash .utils/.check-merge.sh "${path}" "${repo}" "${result}"
+        if [ "${prevhead}" = "$(git rev-parse HEAD)" ]; then
+            ok=false
+        fi
     fi
     fi
 fi
 fi
 if $ok; then
 if $ok; then

+ 1 - 1
.utils/add-subtree.sh

@@ -24,7 +24,7 @@ if [ "${subdir}" = "" ]; then
     subdir="/"
     subdir="/"
     git subtree add -P "${path}" "${repo}" "${branch}" -m "Add ${path} from ${repo}"
     git subtree add -P "${path}" "${repo}" "${branch}" -m "Add ${path} from ${repo}"
 else
 else
-    bash .utils/subtree-subdir-helper.sh "${path}" "${repo}" "${branch}" "${subdir}" add
+    bash .utils/.subtree-subdir-helper.sh "${path}" "${repo}" "${branch}" "${subdir}" add
 fi
 fi
 
 
 gitsubtree="${path}/.gitsubtree"
 gitsubtree="${path}/.gitsubtree"

+ 3 - 20
.utils/update-subtree.sh

@@ -16,28 +16,11 @@ while read -u $remote repo branch subdir; do
     if [ "${repo:0:1}" = "#" ]; then
     if [ "${repo:0:1}" = "#" ]; then
         continue
         continue
     fi
     fi
-    exec {capture}>&1
     if [ "${subdir}" = "/" ]; then
     if [ "${subdir}" = "/" ]; then
+        exec {capture}>&1
         result="$(git subtree pull -P "${path}" "${repo}" "${branch}" -m "Merge ${path} from ${repo}" 2>&1 | tee /proc/self/fd/$capture)"
         result="$(git subtree pull -P "${path}" "${repo}" "${branch}" -m "Merge ${path} from ${repo}" 2>&1 | tee /proc/self/fd/$capture)"
+        bash .utils/.check-merge.sh "${path}" "${repo}" "${result}"
     else
     else
-        result="$(bash .utils/subtree-subdir-helper.sh "${path}" "${repo}" "${branch}" "${subdir}" merge 2>&1 | tee /proc/self/fd/$capture)"
-    fi
-    if grep "Automatic merge failed; fix conflicts and then commit the result." <<< "$result" > /dev/null; then
-        echo "MERGE_MSG: Merge ${path} from ${repo}"
-        notify-send -a Git -i git "Subtree merge failed" "Resolve current index to continue" &> /dev/null | true
-        while true; do
-            echo "Resolve current index then press Enter..."
-            read
-            if git diff --quiet && git diff --cached --quiet && git merge HEAD &> /dev/null; then
-                break
-            fi
-            sleep 1
-        done
-    fi
-    if grep "Please commit your changes or stash them before you switch branches." <<< "$result" > /dev/null; then
-        exit 1
-    fi
-    if grep "^fatal: " <<< "$result" > /dev/null; then
-        exit 1
+        bash .utils/.subtree-subdir-helper.sh "${path}" "${repo}" "${branch}" "${subdir}" merge
     fi
     fi
 done {remote}< "${path}/.gitsubtree"
 done {remote}< "${path}/.gitsubtree"