Просмотр исходного кода

Refactor update system for subdirs

Willy-JL 2 лет назад
Родитель
Сommit
9c6aca5d1a
6 измененных файлов с 61 добавлено и 8 удалено
  1. 0 4
      .gitconfig
  2. 22 0
      .utils/add-app.sh
  3. 4 0
      .utils/gitconfig
  4. 22 0
      .utils/subdir-helper.sh
  5. 11 0
      .utils/update-app.sh
  6. 2 4
      README.md

+ 0 - 4
.gitconfig

@@ -1,4 +0,0 @@
-[alias]
-    add-app = "!f() { if [ \"$1\" = \"\" -o \"$2\" = \"\" -o \"$3\" = \"\" ]; then echo \"Usage: git add-app <path> <repo> <branch> [link-subdir] [link-dest]\" && exit; fi; set -e; git subtree add -P \"$1\" \"$2\" \"$3\"; echo \"$2 $3\" > \"$1/.gitremote\" && git add \"$1/.gitremote\"; [ \"$4\" = \"\" -a \"$5\" = \"\" ] || (ln -s \"$1/$4\" \"$5\" && git add \"$5\"); git commit -m \"Add configs for ${5:-$1}\"; }; f"
-    update-app = "!f() { git subtree pull -P $GIT_PREFIX $(<${GIT_PREFIX}.gitremote); }; f"
-    bulk-update-apps = "!f() { find . -name .gitremote -execdir git update-app \\;; }; f"

+ 22 - 0
.utils/add-app.sh

@@ -0,0 +1,22 @@
+#!/bin/bash
+set -e
+
+if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then
+    echo "Usage: git add-app <path> <repo> <branch> [subdir]"
+    exit
+fi
+path=${1%/}
+repo=${2%/}
+branch=${3}
+subdir=${4%/}
+
+if [ "${subdir}" = "" ]; then
+    git subtree add -P ${path} ${repo} ${branch} -m "Add ${path} from ${repo}"
+else
+    bash .utils/subdir-helper.sh ${path} ${repo} ${branch} ${subdir} add
+fi
+
+gitsubtree=${path}/.gitsubtree
+echo ${repo} ${branch} ${subdir} > ${gitsubtree}
+git add ${gitsubtree}
+git commit --amend --no-edit

+ 4 - 0
.utils/gitconfig

@@ -0,0 +1,4 @@
+[alias]
+    add-app = "!bash .utils/add-app.sh"
+    update-app = "!bash .utils/update-app.sh"
+    bulk-update-apps = "!f() { find . -name .gitremote -execdir git update-app \\;; }; f"

+ 22 - 0
.utils/subdir-helper.sh

@@ -0,0 +1,22 @@
+#!/bin/bash
+set -e
+
+if [ "${1}" = "" ] || [ "${2}" = "" ] || [ "${3}" = "" ] || [ "${4}" = "" ] || [ "${5}" = "" ]; then
+    echo "Usage: <path> <repo> <branch> <subdir> <action>"
+    exit
+fi
+path=${1}
+repo=${2}
+branch=${3}
+subdir=${4}
+action=${5}
+
+prev=$(git branch --show-current)
+temp=$(echo ${repo%/} | rev | cut -d/ -f1,2 | rev | tr / -)-${branch}
+fetch=_fetch-${temp}
+split=_split-${temp}-$(echo ${subdir} | tr / -)
+git fetch ${repo} ${branch}:${fetch}
+git checkout ${fetch}
+git subtree split -P ${subdir} -b ${split}
+git checkout ${prev}
+git subtree ${action} -P ${path} ${split} -m "${action^} ${path} from ${repo}"

+ 11 - 0
.utils/update-app.sh

@@ -0,0 +1,11 @@
+#!/bin/bash
+set -e
+
+path=${GIT_PREFIX%/}
+read repo branch subdir < ${GIT_PREFIX}.gitsubtree
+
+if [ "${subdir}" = "" ]; then
+    git subtree pull -P ${path} ${repo} ${branch} -m "Merge ${path} from ${repo}"
+else
+    bash .utils/subdir-helper.sh ${path} ${repo} ${branch} ${subdir} merge
+fi

+ 2 - 4
README.md

@@ -20,9 +20,7 @@ Subtrees work in a very peculiar way, where they pull and compare commit history
 That's why the commit history for our repo is so huge, it contains all the commits for all the apps, plus our edits.
 That's why the commit history for our repo is so huge, it contains all the commits for all the apps, plus our edits.
 
 
 To make updating more manageable, we have added another layer on top of subtrees:
 To make updating more manageable, we have added another layer on top of subtrees:
-- set it up by running `git config --local include.path ../.gitconfig`
-- add a new app with `git add-app <path> <repo> <branch>`, this will pull the commit history and create a `path/.gitremote` to remember the url and branch
+- set it up by running `git config --local include.path ../.utils/gitconfig`
+- add a new app with `git add-app <path> <repo> <branch> [subdir]`, this will pull the history and create `path/.gitsubtree` to remember the url, branch and subdir
 - run `git update-app` to pull updates based on the current subtree directory
 - run `git update-app` to pull updates based on the current subtree directory
 - or run `git bulk-update-apps` to do it for all subtrees
 - or run `git bulk-update-apps` to do it for all subtrees
-
-Also, some repos dont have the code in their top-level folders, so for those we have symlinks from our root folder to the approriate place in `.modules/`.