Ver código fonte

Automatically add multiple subtree remotes

Willy-JL 1 ano atrás
pai
commit
e7f3242184
2 arquivos alterados com 31 adições e 10 exclusões
  1. 25 2
      .utils/add-subtree.sh
  2. 6 8
      README.md

+ 25 - 2
.utils/add-subtree.sh

@@ -5,6 +5,10 @@ if [ "$(git rev-parse --show-prefix)" != "" ]; then
     echo "Must be in root of git repo!"
     exit
 fi
+if ! git diff --quiet || ! git diff --cached --quiet || ! git merge HEAD &> /dev/null; then
+    echo "Workdir must be clean!"
+    exit
+fi
 
 if [ "$1" = "" ] || [ "$2" = "" ]; then
     echo "Usage 1: <path> <repo url> <branch> [subdir]"
@@ -19,6 +23,16 @@ else
     branch="${3}"
     subdir="${4%/}"
 fi
+gitsubtree="${path}/.gitsubtree"
+
+prevremotedir=""
+if [ -e "${gitsubtree}" ]; then
+    echo "Subtree already exists, adding new remote to it."
+    prevremotedir="$(mktemp -d /tmp/gitsubtree-XXXXXXXX)"
+    mv -T "${path}" "${prevremotedir}"
+    git add "${path}"
+    git commit -m "Add new remote for ${path}"
+fi
 
 if [ "${subdir}" = "" ]; then
     subdir="/"
@@ -27,7 +41,16 @@ else
     bash .utils/.subtree-subdir-helper.sh "${path}" "${repo}" "${branch}" "${subdir}" add
 fi
 
-gitsubtree="${path}/.gitsubtree"
-echo "${repo} ${branch} ${subdir}" > "${gitsubtree}"
+if [ "${prevremotedir}" != "" ]; then
+    rm -r "${path}"
+    mv -T "${prevremotedir}" "${path}"
+fi
+
+echo "${repo} ${branch} ${subdir}" >> "${gitsubtree}"
 git add "${gitsubtree}"
 git commit --amend --no-edit
+
+if [ "${prevremotedir}" != "" ]; then
+    prevremotedir=""
+    echo "Added new remote for existing subtree, you must solve conflicts manually..."
+fi

+ 6 - 8
README.md

@@ -32,12 +32,10 @@ To make updating more manageable, we have added some scripts on top of subtrees:
 - or run `.utils/bulk-update-subtrees.sh` to do it for all subtrees
 
 Most apps have a remote subtree URL for both the original repository, and for any forks / other sources such as [@xMasterX's pack](https://github.com/xMasterX/all-the-plugins).
-Unfortunately, this process is currently manual as our helper scripts don't cover it. We instead:
-- add from one remote
-- delete the directory in a commit
-- add from another remote
-- replace the new directory with the previous one
-- compare the changes between forks and keep the best of both
-- add any eventual edits we have on our end
-If you're an app developer wanting to add your app, or a third party who wants to include something they find useful, you don't need to bother with this cumbersome process.
+This process is assisted by `.utils/add-subtree.sh`, if the specified subtree path already exists, it will:
+- remove the previous subtree with a commit
+- add the subtree from the new remote
+- restore the previous subtree and merge the remotes
+After this, you will just need to resolve the conflicts (content differences between remotes) manually to keep the best of both, and commit.
+If you're an app developer wanting to add your app, or a third party who wants to include something they find useful, you don't need to bother with this process.
 We will do it for you, just add from a single remote URL, or simply make an issue requesting an app to be added!