3 # Copyright © 2008 Mike O'Connor <stew@vireo.org>
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option) any
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 $0: manage home directory using mr
29 $bn - a command to manage detached git repositories using mr
39 $bn add repository_name
40 $bn new repository_name file1 [file2 file3...]
41 $bn login repository_name
42 $bn exec repository_name command [arg1 arg2...]
46 create ~/.moveinrc, create/update ~/.mrconfig
50 show a list of local repositories
54 show a list of remote repositories
57 locate which repositories contain files matching pattern
60 checkout one or more repositories from the remote host and add it to
63 new repository_name file1 [file2 file3...]
64 create a new repository on the remote host, and checkin the
65 listed files to the new repository. Add the new repository
69 start a subshell in repository_name
71 exec repository_name command [arg1 arg2...]
72 execute a command in the context of repository_name, for example:
73 $bn exec myrepo git status
74 $bn exec myrepo git ls-files
83 GIT_HOST=git.vireo.org
89 [ -e "$MOVEINRC" ] && . "$MOVEINRC"
97 if [ -e $MOVEINRC ]; then
98 echo $MOVEINRC already exists
102 if ! which mr > /dev/null; then
103 echo '"mr" not found in the PATH'
107 echo -n "git server hostname? [git.vireo.org] "
109 if [ -z "$GIT_HOST" ]; then
110 GIT_HOST=git.vireo.org
113 echo -n "path to remote repositories? [~/git] "
115 if [ -z "$REMOTE_REPOS" ]; then
119 echo -n "Local repository directory? [~/.movein] "
121 if [ -z "$LOCAL_REPOS" ]; then
122 LOCAL_REPOS=~/.movein
125 echo -n "Location of .mrconfig file? [~/.mrconfig] "
127 if [ -z "$MRCONFIG" ]; then
131 cat <<EOF > $MOVEINRC
133 REMOTE_REPOS=$REMOTE_REPOS
134 LOCAL_REPOS=$LOCAL_REPOS
138 if [ ! -d "$LOCAL_REPOS" ]; then
139 mkdir -p "$LOCAL_REPOS"
142 mr -c "$MRCONFIG" config DEFAULT include="cat /usr/share/mr/git-fake-bare"
147 if [ $# -ne 1 ]; then
151 export GIT_DIR="$LOCAL_REPOS/${1}.git"
152 export GIT_WORK_TREE="$GIT_DIR/$(git config --get core.worktree)"
154 GIT_PS1_SHOWUNTRACKEDFILES= PSMOVEIN="movein:${1}" $SHELL -i || :
159 if [ $# -lt 1 ]; then
165 export GIT_DIR="$LOCAL_REPOS/${REPO}.git"
166 export GIT_WORK_TREE="$GIT_DIR/$(git config --get core.worktree)"
172 if [ $# -lt 1 ]; then
178 LOCAL_REPO=$LOCAL_REPOS/$REPO_NAME
179 REPO_URL=ssh://$GIT_HOST/$REMOTE_REPOS/$REPO_NAME
180 if [ -e "$LOCAL_REPO" ]; then
181 echo $LOCAL_REPO already exists
184 trap "rm -rf $LOCAL_REPO" 0
186 export GIT_DIR="$LOCAL_REPO"
188 git remote add origin $REPO_URL
189 git config branch.master.remote origin
190 git config branch.master.merge refs/heads/master
191 git config core.bare false
192 git config core.worktree ../../
193 git config status.showUntrackedFiles no
194 GIT_WORK_TREE="$LOCAL_REPO/../../" git pull
197 mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' 'REPO_NAME' '../../'"
203 find "${LOCAL_REPOS}" -mindepth 1 -maxdepth 1 -type d | sed 's,^.*/\([^/]*\).git$,\1,'
208 find '${REMOTE_REPOS}' -mindepth 1 -maxdepth 1 -type d | sed 's,^.*/\([^/]*\).git$,\1,'
214 for REPO in $($0 list); do
215 (cd /; $0 exec "$REPO" git ls-files | sed -nr "/$1/{s/^/$REPO:/p}")
220 if [ $# -lt 2 ]; then
223 REPO_NAME=$1.git ; shift
224 LOCAL_REPO="$LOCAL_REPOS/$REPO_NAME"
225 REPO_URL="ssh://$GIT_HOST/$REMOTE_REPOS/$REPO_NAME"
227 if [ ! -e "$1" ]; then
232 if [ -e "$LOCAL_REPO" ]; then
233 echo $LOCAL_REPO already exists
236 trap "rm -rf $LOCAL_REPO" 0
237 mkdir -p "$LOCAL_REPO"
240 GIT_DIR=$REMOTE_REPOS/$REPO_NAME git --bare init
243 export GIT_DIR="$LOCAL_REPO"
245 git remote add origin $REPO_URL
246 git config branch.master.remote origin
247 git config branch.master.merge refs/heads/master
248 git config core.bare false
249 git config core.worktree ../../
250 git config status.showUntrackedFiles no
251 export GIT_WORK_TREE="$LOCAL_REPO/../../"
253 git commit -m "initial checkin"
258 mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' 'REPO_NAME' '../../'"