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.$(hostname -d || echo "example.com")
90 [ -e "$MOVEINRC" ] && . "$MOVEINRC"
98 if [ -e $MOVEINRC ]; then
99 echo $MOVEINRC already exists
103 echo -n "git server hostname? [${GIT_HOST}] "
105 if [ -z "$GIT_HOST" ]; then
106 GIT_HOST=git.$(hostname -d)
109 echo -n "path to remote repositories? [~/git] "
111 if [ -z "$REMOTE_REPOS" ]; then
117 DEFAULT_CREATE_REMOTE=0
118 CREATE_REMOTE_OPTIONS="[yN]"
121 DEFAULT_CREATE_REMOTE=1
122 CREATE_REMOTE_OPTIONS="[Yn]"
126 echo -n "should \"movein new\" run \"git init\" on the remote host? (github users should say \"no\") $CREATE_REMOTE_OPTIONS"
127 read CREATE_REMOTE_SELECTION
128 case "$CREATE_REMOTE_SELECTION" in
129 [yY]) CREATE_REMOTE=1 ;;
130 [nN]) CREATE_REMOTE=0 ;;
131 *) CREATE_REMOTE=$DEFAULT_CREATE_REMOTE
134 echo -n "Local repository directory? [~/.movein] "
136 if [ -z "$LOCAL_REPOS" ]; then
137 LOCAL_REPOS=~/.movein
140 echo -n "Location of .mrconfig file? [~/.mrconfig] "
142 if [ -z "$MRCONFIG" ]; then
146 cat <<EOF > $MOVEINRC
148 REMOTE_REPOS=$REMOTE_REPOS
149 LOCAL_REPOS=$LOCAL_REPOS
151 CREATE_REMOTE=$CREATE_REMOTE
154 if [ ! -d "$LOCAL_REPOS" ]; then
155 mkdir -p "$LOCAL_REPOS"
158 mr -c "$MRCONFIG" config DEFAULT include="cat /usr/share/mr/git-fake-bare"
167 while [ "${TEMP_REPO#*/}" != "$TEMP_REPO" ]; do
168 TEMP_REPO="${TEMP_REPO#*/}"
169 GIT_WORK_TREE="../$GIT_WORK_TREE"
174 if [ $# -ne 1 ]; then
178 export GIT_DIR="$LOCAL_REPOS/${1}.git"
180 GIT_PS1_SHOWUNTRACKEDFILES= PSMOVEIN="movein:${1}" $SHELL -i || :
185 if [ $# -lt 2 ]; then
191 export GIT_DIR="$LOCAL_REPOS/${REPO}.git"
197 if [ $# -lt 1 ]; then
203 LOCAL_REPO=$LOCAL_REPOS/$REPO_NAME
204 REPO_URL=ssh://$GIT_HOST/$REMOTE_REPOS/$REPO_NAME
206 if [ -e "$LOCAL_REPO" ]; then
207 echo $LOCAL_REPO already exists
210 trap "unset GIT_DIR; unset GIT_WORK_TREE; rm -rf $LOCAL_REPO" 0
211 mkdir -p "$LOCAL_REPO"
212 export GIT_DIR="$LOCAL_REPO"
213 git_work_tree "$REPO_NAME"
215 git remote add origin $REPO_URL
216 git config branch.master.remote origin
217 git config branch.master.merge refs/heads/master
218 git config core.bare false
219 git config core.worktree "$GIT_WORK_TREE"
220 git config status.showUntrackedFiles no
224 mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' '$REPO_NAME' '$GIT_WORK_TREE'"
230 find "${LOCAL_REPOS}" -mindepth 1 -type d -name '*.git' | sed "s,${LOCAL_REPOS}/,,"
235 find '${REMOTE_REPOS}' -mindepth 1 -type d -name '*.git' | sed 's,${REMOTE_REPOS}/,,'
241 if [ $# -ne 1 ]; then
244 for REPO in $($0 list); do
245 (cd /; $0 exec "$REPO" git ls-files | sed -nr "/$1/{s/^/$REPO:/p}")
250 if [ $# -lt 2 ]; then
253 REPO_NAME=$1.git ; shift
254 LOCAL_REPO="$LOCAL_REPOS/$REPO_NAME"
255 REPO_URL="ssh://$GIT_HOST/$REMOTE_REPOS/$REPO_NAME"
257 if [ ! -e "$1" ]; then
262 if [ -e "$LOCAL_REPO" ]; then
263 echo $LOCAL_REPO already exists
266 trap "unset GIT_DIR; unset GIT_WORK_TREE; rm -rf $LOCAL_REPO" 0
267 mkdir -p "$LOCAL_REPO"
269 if [ $CREATE_REMOTE -ne 0 ]; then
271 GIT_DIR=$REMOTE_REPOS/$REPO_NAME git --bare init
275 export GIT_DIR="$LOCAL_REPO"
276 git_work_tree "$REPO_NAME"
278 git remote add origin $REPO_URL
279 git config branch.master.remote origin
280 git config branch.master.merge refs/heads/master
281 git config core.bare false
282 git config core.worktree "$GIT_WORK_TREE"
283 git config status.showUntrackedFiles no
285 git commit -m "initial checkin"
290 mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' '$REPO_NAME' '$GIT_WORK_TREE'"
296 # Check a few requirements before doing any work
299 for binary in mr git; do
300 bin=$(which ${binary})
301 if [ -z "${bin}" ]; then
302 echo "Missing required program: ${binary}"
303 errors=$(( errors + 1 ))
307 if [ $errors -ne 0 ]; then
308 echo "Errors found, exiting"
313 if [ $# -lt 1 ]; then