]> ToastFreeware Gitweb - gregoa/movein.git/blobdiff - movein
Merge branch 'master' into gregoa
[gregoa/movein.git] / movein
diff --git a/movein b/movein
index 47c01fcc3f530b0b58ffc4c89b9ed3e7853a16d3..10658ba8f2222406ca5ad1ae9d80bd0d52ca0283 100755 (executable)
--- a/movein
+++ b/movein
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # Copyright © 2008 Mike O'Connor <stew@vireo.org>
 #
 #
 # Copyright © 2008 Mike O'Connor <stew@vireo.org>
 #
@@ -80,11 +80,12 @@ EOF
 
 [ $# -ge 1 ] || usage
 
 
 [ $# -ge 1 ] || usage
 
-GIT_HOST=git.$(hostname -d)
+GIT_HOST=git.$(hostname -d || echo "example.com")
 REMOTE_REPOS=~/git
 LOCAL_REPOS=~/.movein
 MRCONFIG=~/.mrconfig
 MOVEINRC=~/.moveinrc
 REMOTE_REPOS=~/git
 LOCAL_REPOS=~/.movein
 MRCONFIG=~/.mrconfig
 MOVEINRC=~/.moveinrc
+CREATE_REMOTE=1
 
 [ -e "$MOVEINRC" ] && . "$MOVEINRC"
 
 
 [ -e "$MOVEINRC" ] && . "$MOVEINRC"
 
@@ -111,6 +112,25 @@ init() {
         REMOTE_REPOS=~/git
     fi
 
         REMOTE_REPOS=~/git
     fi
 
+    case $GIT_HOST in
+        *github*)
+            DEFAULT_CREATE_REMOTE=0
+            CREATE_REMOTE_OPTIONS="[yN]"
+            ;;
+        *)
+            DEFAULT_CREATE_REMOTE=1
+            CREATE_REMOTE_OPTIONS="[Yn]"
+            ;;
+    esac
+
+    echo -n "should \"movein new\" run \"git init\" on the remote host? (github users should say \"no\") $CREATE_REMOTE_OPTIONS"
+    read CREATE_REMOTE_SELECTION
+    case "$CREATE_REMOTE_SELECTION" in
+        [yY]) CREATE_REMOTE=1 ;;
+        [nN]) CREATE_REMOTE=0 ;;
+        *) CREATE_REMOTE=$DEFAULT_CREATE_REMOTE
+    esac
+
     echo -n "Local repository directory? [~/.movein] "
     read LOCAL_REPOS
     if [ -z "$LOCAL_REPOS" ]; then
     echo -n "Local repository directory? [~/.movein] "
     read LOCAL_REPOS
     if [ -z "$LOCAL_REPOS" ]; then
@@ -128,6 +148,7 @@ GIT_HOST=$GIT_HOST
 REMOTE_REPOS=$REMOTE_REPOS
 LOCAL_REPOS=$LOCAL_REPOS
 MRCONFIG=$MRCONFIG
 REMOTE_REPOS=$REMOTE_REPOS
 LOCAL_REPOS=$LOCAL_REPOS
 MRCONFIG=$MRCONFIG
+CREATE_REMOTE=$CREATE_REMOTE
 EOF
 
     if [ ! -d "$LOCAL_REPOS" ]; then
 EOF
 
     if [ ! -d "$LOCAL_REPOS" ]; then
@@ -138,13 +159,23 @@ EOF
 
 }
 
 
 }
 
+git_work_tree() {
+    local TEMP_REPO
+    TEMP_REPO=$1
+    GIT_WORK_TREE=../../
+
+    while [ "${TEMP_REPO#*/}" != "$TEMP_REPO" ]; do
+        TEMP_REPO="${TEMP_REPO#*/}"
+        GIT_WORK_TREE="../$GIT_WORK_TREE"
+    done
+}
+
 login() {
     if [ $# -ne 1 ]; then
        usage
     fi
 
     export GIT_DIR="$LOCAL_REPOS/${1}.git"
 login() {
     if [ $# -ne 1 ]; then
        usage
     fi
 
     export GIT_DIR="$LOCAL_REPOS/${1}.git"
-    export GIT_WORK_TREE="$GIT_DIR/$(git config --get core.worktree)"
 
     GIT_PS1_SHOWUNTRACKEDFILES= PSMOVEIN="movein:${1}" $SHELL -i || :
 }
 
     GIT_PS1_SHOWUNTRACKEDFILES= PSMOVEIN="movein:${1}" $SHELL -i || :
 }
@@ -158,7 +189,6 @@ execin() {
     REPO=$1;shift
 
     export GIT_DIR="$LOCAL_REPOS/${REPO}.git"
     REPO=$1;shift
 
     export GIT_DIR="$LOCAL_REPOS/${REPO}.git"
-    export GIT_WORK_TREE="$GIT_DIR/$(git config --get core.worktree)"
 
     "$@"
 }
 
     "$@"
 }
@@ -177,36 +207,40 @@ add() {
             echo $LOCAL_REPO already exists
             exit 1
         else
             echo $LOCAL_REPO already exists
             exit 1
         else
-            trap "rm -rf $LOCAL_REPO" 0
-            mkdir "$LOCAL_REPO"
+            trap "unset GIT_DIR; unset GIT_WORK_TREE; rm -rf $LOCAL_REPO" 0
+            mkdir -p "$LOCAL_REPO"
             export GIT_DIR="$LOCAL_REPO"
             export GIT_DIR="$LOCAL_REPO"
+            git_work_tree "$REPO_NAME"
             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 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 core.worktree "$GIT_WORK_TREE"
             git config status.showUntrackedFiles no
             git config status.showUntrackedFiles no
-            GIT_WORK_TREE="$LOCAL_REPO/../../" git pull
+            git pull
             trap - 0
 
             trap - 0
 
-            mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' 'REPO_NAME' '../../'"
+            mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' '$REPO_NAME' '$GIT_WORK_TREE'"
         fi
     done
 }
 
 list() {
         fi
     done
 }
 
 list() {
-    find "${LOCAL_REPOS}" -mindepth 1 -maxdepth 1 -type d | sed 's,^.*/\([^/]*\).git$,\1,'
+    find "${LOCAL_REPOS}" -mindepth 1 -type d -name '*.git' | sed "s,${LOCAL_REPOS}/,,"
 }
 
 listremote() {
     ssh $GIT_HOST "
 }
 
 listremote() {
     ssh $GIT_HOST "
-        find '${REMOTE_REPOS}' -mindepth 1 -maxdepth 1 -type d | sed 's,^.*/\([^/]*\).git$,\1,'
+        find '${REMOTE_REPOS}' -mindepth 1 -type d -name '*.git' | sed 's,${REMOTE_REPOS}/,,'
     " </dev/null
 }
 
 locate() {
     local REPO
     " </dev/null
 }
 
 locate() {
     local REPO
+    if [ $# -ne 1 ]; then
+        usage
+    fi
     for REPO in $($0 list); do
         (cd /; $0 exec "$REPO" git ls-files | sed -nr "/$1/{s/^/$REPO:/p}")
     done
     for REPO in $($0 list); do
         (cd /; $0 exec "$REPO" git ls-files | sed -nr "/$1/{s/^/$REPO:/p}")
     done
@@ -229,29 +263,31 @@ new() {
         echo $LOCAL_REPO already exists
         exit 1
     else
         echo $LOCAL_REPO already exists
         exit 1
     else
-        trap "rm -rf $LOCAL_REPO" 0
+        trap "unset GIT_DIR; unset GIT_WORK_TREE; rm -rf $LOCAL_REPO" 0
         mkdir -p "$LOCAL_REPO"
 
         mkdir -p "$LOCAL_REPO"
 
-        ssh $GIT_HOST "
-            GIT_DIR=$REMOTE_REPOS/$REPO_NAME git --bare init
-        " </dev/null
+        if [ $CREATE_REMOTE -ne 0 ]; then
+            ssh $GIT_HOST "
+                GIT_DIR=$REMOTE_REPOS/$REPO_NAME git --bare init
+            " </dev/null
+        fi
 
         export GIT_DIR="$LOCAL_REPO"
 
         export GIT_DIR="$LOCAL_REPO"
+        git_work_tree "$REPO_NAME"
         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 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 core.worktree "$GIT_WORK_TREE"
         git config status.showUntrackedFiles no
         git config status.showUntrackedFiles no
-        export GIT_WORK_TREE="$LOCAL_REPO/../../"
         git add "$@"
         git commit -m "initial checkin"
         git push --all
 
         trap - 0
 
         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' '../../'"
+        mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' '$REPO_NAME' '$GIT_WORK_TREE'"
     fi
 
 }
     fi
 
 }