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 checkout the repository from the remote host and add it to
60 new repository_name file1 [file2 file3...]
61 create a new repository on the remote host, and checkin the
62 listed files to the new repository. Add the new repository
66 start a subshell in repository_name
68 exec repository_name command [arg1 arg2...]
69 execute a command in the context of repository_name, for example:
70 $bn exec myrepo git status
71 $bn exec myrepo git ls-files
80 GIT_HOST=git.vireo.org
86 [ -e "$MOVEINRC" ] && . "$MOVEINRC"
94 if [ -e $MOVEINRC ]; then
95 echo $MOVEINRC already exists
99 if ! which mr > /dev/null; then
100 echo '"mr" not found in the PATH'
104 echo -n "git server hostname? [git.vireo.org] "
106 if [ -z "$GIT_HOST" ]; then
107 GIT_HOST=git.vireo.org
110 echo -n "path to remote repositories? [~/git] "
112 if [ -z "$REMOTE_REPOS" ]; then
116 echo -n "Local repository directory? [~/.movein] "
118 if [ -z "$LOCAL_REPOS" ]; then
119 LOCAL_REPOS=~/.movein
122 echo -n "Location of .mrconfig file? [~/.mrconfig] "
124 if [ -z "$MRCONFIG" ]; then
128 cat <<EOF > $MOVEINRC
130 REMOTE_REPOS=$REMOTE_REPOS
131 LOCAL_REPOS=$LOCAL_REPOS
135 if [ ! -d "$LOCAL_REPOS" ]; then
136 mkdir -p "$LOCAL_REPOS"
139 mr -c "$MRCONFIG" config DEFAULT include="cat /usr/share/mr/git-fake-bare"
144 if [ $# -ne 1 ]; then
148 export GIT_DIR="$LOCAL_REPOS/${1}.git"
149 export GIT_WORK_TREE="$GIT_DIR/$(git config --get core.worktree)"
151 GIT_PS1_SHOWUNTRACKEDFILES= PSMOVEIN="movein:${1}" $SHELL -i || :
156 if [ $# -lt 1 ]; then
162 export GIT_DIR="$LOCAL_REPOS/${REPO}.git"
163 export GIT_WORK_TREE="$GIT_DIR/$(git config --get core.worktree)"
169 if [ $# -ne 1 ]; then
172 REPO_NAME=$1.git ; shift
173 LOCAL_REPO=$LOCAL_REPOS/$REPO_NAME
174 REPO_URL=ssh://$GIT_HOST/$REMOTE_REPOS/$REPO_NAME
176 if [ -e "$LOCAL_REPO" ]; then
177 echo $LOCAL_REPO already exists
180 trap "rm -rf $LOCAL_REPO" 0
182 export GIT_DIR="$LOCAL_REPO"
184 git remote add origin $REPO_URL
185 git config branch.master.remote origin
186 git config branch.master.merge refs/heads/master
187 git config core.bare false
188 git config core.worktree ../../
189 git config status.showUntrackedFiles no
190 GIT_WORK_TREE="$LOCAL_REPO/../../" git pull
193 mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' 'REPO_NAME' '../../'"
198 find "${LOCAL_REPOS}" -mindepth 1 -maxdepth 1 -type d | sed 's,^.*/\([^/]*\).git$,\1,'
203 find '${REMOTE_REPOS}' -mindepth 1 -maxdepth 1 -type d | sed 's,^.*/\([^/]*\).git$,\1,'
208 if [ $# -lt 2 ]; then
211 REPO_NAME=$1.git ; shift
212 LOCAL_REPO="$LOCAL_REPOS/$REPO_NAME"
213 REPO_URL="ssh://$GIT_HOST/$REMOTE_REPOS/$REPO_NAME"
215 if [ ! -e "$1" ]; then
220 if [ -e "$LOCAL_REPO" ]; then
221 echo $LOCAL_REPO already exists
224 trap "rm -rf $LOCAL_REPO" 0
225 mkdir -p "$LOCAL_REPO"
228 GIT_DIR=$REMOTE_REPOS/$REPO_NAME git --bare init
231 export GIT_DIR="$LOCAL_REPO"
233 git remote add origin $REPO_URL
234 git config branch.master.remote origin
235 git config branch.master.merge refs/heads/master
236 git config core.bare false
237 git config core.worktree ../../
238 git config status.showUntrackedFiles no
239 export GIT_WORK_TREE="$LOCAL_REPO/../../"
241 git commit -m "initial checkin"
246 mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' 'REPO_NAME' '../../'"