]> ToastFreeware Gitweb - gregoa/movein.git/blobdiff - movein
Add "locate" command to movein
[gregoa/movein.git] / movein
diff --git a/movein b/movein
index c6c51370d26ad90d78d30a5a51e91fe00ec0ea01..8030ee318869aeee1b6c13561cca5c9551712bbd 100755 (executable)
--- a/movein
+++ b/movein
@@ -39,6 +39,7 @@ SYNOPSIS
   $bn add repository_name
   $bn new repository_name file1 [file2 file3...]
   $bn login repository_name
+  $bn exec repository_name command [arg1 arg2...]
 
 COMMANDS
   init 
@@ -52,8 +53,11 @@ COMMANDS
   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...]  
@@ -64,6 +68,11 @@ COMMANDS
   login repository_name
       start a subshell in repository_name
 
+  exec repository_name command [arg1 arg2...]
+      execute a command in the context of repository_name, for example:
+        $bn exec myrepo git status
+        $bn exec myrepo git ls-files
+
 EOF
 
     exit 1
@@ -90,6 +99,11 @@ init() {
        exit 1
     fi
 
+    if ! which mr > /dev/null; then
+        echo '"mr" not found in the PATH'
+        exit 1
+    fi
+
     echo -n "git server hostname? [git.vireo.org] " 
     read GIT_HOST
     if [ -z "$GIT_HOST" ]; then 
@@ -140,33 +154,49 @@ login() {
     GIT_PS1_SHOWUNTRACKEDFILES= PSMOVEIN="movein:${1}" $SHELL -i || :
 }
 
-add() {
-    if [ $# -ne 1 ]; then 
+execin() {
+    local REPO
+    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
-       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
+    REPO=$1;shift
 
-       mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' 'REPO_NAME' '../../'"
+    export GIT_DIR="$LOCAL_REPOS/${REPO}.git"
+    export GIT_WORK_TREE="$GIT_DIR/$(git config --get core.worktree)"
+
+    "$@"
+}
+
+add() {
+    if [ $# -lt 1 ]; then 
+       usage
     fi
+
+    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
+    done
 }
 
 list() {
@@ -179,6 +209,13 @@ listremote() {
     " </dev/null
 }
 
+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
@@ -227,16 +264,19 @@ new() {
 command=$1 ; shift
 case "$command" in 
     init)
-       init $@
+       init "$@"
        ;;
     add)
-       add $@
+       add "$@"
        ;;
     new)
-       new $@
+       new "$@"
        ;;
     login)
-       login $@
+       login "$@"
+       ;;
+    exec)
+       execin "$@"
        ;;
     ls)
        list
@@ -250,6 +290,9 @@ case "$command" in
     list-remote)
        listremote
        ;;
+    locate)
+       locate "$@"
+       ;;
 
     *)
        usage