Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:git:git-subtree [2012/01/14 07:39] – alex | en:git:git-subtree [2012/08/27 07:42] (current) – alex | ||
|---|---|---|---|
| Line 83: | Line 83: | ||
| Slick. | Slick. | ||
| + | |||
| + | ===== Helper Script ===== | ||
| + | |||
| + | As I have been using the commands listed here quite often, I decided to put together a helper script for managing these subtrees. | ||
| + | |||
| + | <code sh> | ||
| + | #!/bin/bash | ||
| + | |||
| + | # Git subtree manager | ||
| + | # Alex Forencich < | ||
| + | # This script facilitates easy management of subtrees | ||
| + | # included in larger repositories as this script can | ||
| + | # be included in the repository itself. | ||
| + | |||
| + | # Note: | ||
| + | # Requires git-subtree | ||
| + | # https:// | ||
| + | |||
| + | # Settings | ||
| + | # uncomment to use --squash | ||
| + | # | ||
| + | # Remote repository | ||
| + | repo=" | ||
| + | # Remote name | ||
| + | remote=" | ||
| + | # Subdirectory to store code in | ||
| + | subdir=" | ||
| + | # Remote branch | ||
| + | branch=" | ||
| + | # Backport branch name (only used for pushing) | ||
| + | backportbranch=" | ||
| + | # Add commit message | ||
| + | addmsg=" | ||
| + | # Merge commit message | ||
| + | mergemsg=" | ||
| + | |||
| + | # Usage | ||
| + | # add - adds subtree | ||
| + | # pull - default, pulls from remote | ||
| + | # push - pushes to remote | ||
| + | |||
| + | squashflag="" | ||
| + | |||
| + | if [ $squash ]; then | ||
| + | squashflag=" | ||
| + | fi | ||
| + | |||
| + | action=" | ||
| + | |||
| + | cd $(git rev-parse --show-toplevel) | ||
| + | |||
| + | if [ ! -d " | ||
| + | action=" | ||
| + | fi | ||
| + | |||
| + | if [ -n " | ||
| + | action=" | ||
| + | fi | ||
| + | |||
| + | # array contains value | ||
| + | # usage: contains array value | ||
| + | function contains() { | ||
| + | local n=$# | ||
| + | local value=${!n} | ||
| + | for ((i=1;i < $n;i++)) { | ||
| + | if [ " | ||
| + | echo " | ||
| + | return 0 | ||
| + | fi | ||
| + | } | ||
| + | echo " | ||
| + | return 1 | ||
| + | } | ||
| + | |||
| + | case " | ||
| + | add) | ||
| + | if [ $(contains $(git remote) " | ||
| + | git remote add " | ||
| + | fi | ||
| + | git fetch " | ||
| + | git subtree add -P " | ||
| + | ;; | ||
| + | pull) | ||
| + | if [ $(contains $(git remote) " | ||
| + | git remote add " | ||
| + | fi | ||
| + | git fetch " | ||
| + | git subtree merge -P " | ||
| + | ;; | ||
| + | push) | ||
| + | if [ $(contains $(git remote) " | ||
| + | git remote add " | ||
| + | fi | ||
| + | git subtree split -P " | ||
| + | git push " | ||
| + | ;; | ||
| + | *) | ||
| + | echo " | ||
| + | exit 1 | ||
| + | esac | ||
| + | |||
| + | exit 0 | ||
| + | |||
| + | </ | ||