# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
- #
+ #
-# this program is distributed in the hope that it will be useful,
+# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
list-remote
show a list of remote repositories
+ locate pattern
+ locate which repositories contain files matching pattern
+
add repository_name
- checkout the repository from the remote host and add it to
+ checkout one or more repositories from the remote host and add it to
mr's configuration
- new repository_name file1 [file2 file3...]
+ new repository_name file1 [file2 file3...]
create a new repository on the remote host, and checkin the
listed files to the new repository. Add the new repository
to mr's configuration
init() {
- if [ $# -ne 0 ]; then
- usage
- fi
-
- if [ -e $MOVEINRC ]; then
- echo $MOVEINRC already exists
- exit 1
+ if [ $# -ne 0 ]; then
- usage
++ usage
fi
- if ! which mr > /dev/null; then
- echo '"mr" not found in the PATH'
+ if [ -e $MOVEINRC ]; then
+ echo $MOVEINRC already exists
exit 1
fi
}
add() {
- if [ $# -lt 1 ]; then
- usage
- if [ $# -ne 1 ]; then
++ if [ $# -lt 1 ]; then
+ usage
fi
- REPO_NAME=$1.git ; shift
- LOCAL_REPO=$LOCAL_REPOS/$REPO_NAME
- REPO_URL=ssh://$GIT_HOST/$REMOTE_REPOS/$REPO_NAME
- if [ -e "$LOCAL_REPO" ]; then
+ for REPO in "$@"; do
- REPO_NAME=$REPO.git
- LOCAL_REPO=$LOCAL_REPOS/$REPO_NAME
- REPO_URL=ssh://$GIT_HOST/$REMOTE_REPOS/$REPO_NAME
- if [ -e "$LOCAL_REPO" ]; then
- echo $LOCAL_REPO already exists
- exit 1
- else
- trap "rm -rf $LOCAL_REPO" 0
- mkdir "$LOCAL_REPO"
- export GIT_DIR="$LOCAL_REPO"
- git init --bare
- git remote add origin $REPO_URL
- git config branch.master.remote origin
- git config branch.master.merge refs/heads/master
- git config core.bare false
- git config core.worktree ../../
- git config status.showUntrackedFiles no
- GIT_WORK_TREE="$LOCAL_REPO/../../" git pull
- trap - 0
-
- mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' 'REPO_NAME' '../../'"
- fi
++ REPO_NAME=$REPO.git
++ LOCAL_REPO=$LOCAL_REPOS/$REPO_NAME
++ REPO_URL=ssh://$GIT_HOST/$REMOTE_REPOS/$REPO_NAME
++
++ if [ -e "$LOCAL_REPO" ]; then
+ echo $LOCAL_REPO already exists
+ exit 1
- else
- trap "rm -rf $LOCAL_REPO" 0
- mkdir "$LOCAL_REPO"
- export GIT_DIR="$LOCAL_REPO"
- git init --bare
- git remote add origin $REPO_URL
- git config branch.master.remote origin
- git config branch.master.merge refs/heads/master
- git config core.bare false
- git config core.worktree ../../
- git config status.showUntrackedFiles no
- GIT_WORK_TREE="$LOCAL_REPO/../../" git pull
- trap - 0
-
- mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' 'REPO_NAME' '../../'"
- fi
++ else
++ trap "rm -rf $LOCAL_REPO" 0
++ mkdir "$LOCAL_REPO"
++ export GIT_DIR="$LOCAL_REPO"
++ git init --bare
++ git remote add origin $REPO_URL
++ git config branch.master.remote origin
++ git config branch.master.merge refs/heads/master
++ git config core.bare false
++ git config core.worktree ../../
++ git config status.showUntrackedFiles no
++ GIT_WORK_TREE="$LOCAL_REPO/../../" git pull
++ trap - 0
++
++ mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' 'REPO_NAME' '../../'"
++ fi
+ done
}
list() {
" </dev/null
}
- (cd /; $0 exec "$REPO" git ls-files | sed -nr "/$1/{s/^/$REPO:/p}")
+locate() {
+ local REPO
+ for REPO in $($0 list); do
++ (cd /; $0 exec "$REPO" git ls-files | sed -nr "/$1/{s/^/$REPO:/p}")
+ done
+}
+
new() {
- if [ $# -lt 2 ]; then
- usage
+ if [ $# -lt 2 ]; then
- usage
++ usage
fi
REPO_NAME=$1.git ; shift
LOCAL_REPO="$LOCAL_REPOS/$REPO_NAME"
REPO_URL="ssh://$GIT_HOST/$REMOTE_REPOS/$REPO_NAME"
if [ ! -e "$1" ]; then
- echo $1 not found
- exit 1
- echo $1 not found
- exit 1
++ echo $1 not found
++ exit 1
fi
if [ -e "$LOCAL_REPO" ]; then
- echo $LOCAL_REPO already exists
- exit 1
- echo $LOCAL_REPO already exists
- exit 1
++ echo $LOCAL_REPO already exists
++ exit 1
else
- trap "rm -rf $LOCAL_REPO" 0
- mkdir -p "$LOCAL_REPO"
- trap "rm -rf $LOCAL_REPO" 0
- mkdir -p "$LOCAL_REPO"
++ trap "rm -rf $LOCAL_REPO" 0
++ mkdir -p "$LOCAL_REPO"
- ssh $GIT_HOST "
- ssh $GIT_HOST "
-- GIT_DIR=$REMOTE_REPOS/$REPO_NAME git --bare init
++ ssh $GIT_HOST "
++ GIT_DIR=$REMOTE_REPOS/$REPO_NAME git --bare init
" </dev/null
- export GIT_DIR="$LOCAL_REPO"
- git init --bare
- git remote add origin $REPO_URL
- git config branch.master.remote origin
- git config branch.master.merge refs/heads/master
- git config core.bare false
- git config core.worktree ../../
- git config status.showUntrackedFiles no
- export GIT_WORK_TREE="$LOCAL_REPO/../../"
- git add "$@"
- git commit -m "initial checkin"
- git push --all
-
- trap - 0
-
- mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' 'REPO_NAME' '../../'"
+ export GIT_DIR="$LOCAL_REPO"
+ git init --bare
+ git remote add origin $REPO_URL
+ git config branch.master.remote origin
+ git config branch.master.merge refs/heads/master
+ git config core.bare false
+ git config core.worktree ../../
+ git config status.showUntrackedFiles no
+ export GIT_WORK_TREE="$LOCAL_REPO/../../"
+ git add "$@"
+ git commit -m "initial checkin"
+ git push --all
+
+ trap - 0
+
+ mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' 'REPO_NAME' '../../'"
fi
}
+ preflight() {
+ # Check a few requirements before doing any work
+ errors=0
+ set +e
+ for binary in mr git; do
+ bin=$(which ${binary})
+ if [ -z "${bin}" ]; then
+ echo "Missing required program: ${binary}"
+ errors=$(( errors + 1 ))
+ fi
+ done
+ set -e
+ if [ $errors -ne 0 ]; then
+ echo "Errors found, exiting"
+ exit 2
+ fi
+ }
+
+ if [ $# -lt 1 ]; then
+ usage
+ exit 1
+ fi
command=$1 ; shift
- case "$command" in
+ case "$command" in
init)
- init "$@"
- ;;
+ preflight
- init $@
++ init "$@"
+ ;;
add)
- add "$@"
- ;;
+ preflight
- add $@
++ add "$@"
+ ;;
new)
- new "$@"
- ;;
+ preflight
- new $@
++ new "$@"
+ ;;
login)
- login "$@"
- ;;
- login $@
++ login "$@"
+ ;;
exec)
- execin "$@"
- ;;
+ execin "$@"
+ ;;
ls)
- list
- ;;
+ list
+ ;;
list)
- list
- ;;
+ list
+ ;;
ls-r)
- listremote
- ;;
+ listremote
+ ;;
list-remote)
- listremote
- ;;
+ listremote
+ ;;
+ locate)
- locate "$@"
- ;;
++ locate "$@"
++ ;;
*)
- usage
- exit 1
- ;;
+ usage
+ exit 1
+ ;;
esac