X-Git-Url: https://git.toastfreeware.priv.at/gregoa/movein.git/blobdiff_plain/609067ddcb8bdea0ebe0a1e0ebdbb8199fc90db0..HEAD:/movein diff --git a/movein b/movein index 08bb7ff..10658ba 100755 --- a/movein +++ b/movein @@ -1,8 +1,24 @@ -#!/bin/sh +#!/bin/bash # # Copyright © 2008 Mike O'Connor +# +# This program is free software; you can redistribute it and/or modify it +# 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, +# 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. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. set -e +set -u usage() { bn=$(basename $0) @@ -16,181 +32,327 @@ SYNOPSIS $bn command [options] $bn init + $bn ls + $bn list + $bn ls-r + $bn list-remote $bn add repository_name $bn new repository_name file1 [file2 file3...] + $bn login repository_name + $bn exec repository_name command [arg1 arg2...] COMMANDS - init - create ~/.mrconfig + init + create ~/.moveinrc, create/update ~/.mrconfig + + ls + list + show a list of local repositories + + ls-r + 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 + + 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 } +[ $# -ge 1 ] || usage -GIT_HOST=flounder.vireo.org +GIT_HOST=git.$(hostname -d || echo "example.com") REMOTE_REPOS=~/git -LOCAL_REPOS=~/.fgits +LOCAL_REPOS=~/.movein MRCONFIG=~/.mrconfig -MOVEIN=~/.movein +MOVEINRC=~/.moveinrc +CREATE_REMOTE=1 -source $MOVEIN +[ -e "$MOVEINRC" ] && . "$MOVEINRC" init() { - if [ $# -ne 0 ]; then - usage + if [ $# -ne 0 ]; then + usage fi - - if [ -e $MRCONFIG ]; then - echo $MRCONFIG already exists - exit 1 - fi - - if [ -e $MOVEIN ]; then - echo $MOVEIN already exists - exit 1 + + if [ -e $MOVEINRC ]; then + echo $MOVEINRC already exists + exit 1 fi - echo -n "git server hostname? [git.vireo.org] " + echo -n "git server hostname? [${GIT_HOST}] " read GIT_HOST - if [ -z "$GIT_HOST" ]; then - GIT_HOST=git.vireo.org + if [ -z "$GIT_HOST" ]; then + GIT_HOST=git.$(hostname -d) fi - echo -n "path to remote repositories? [~/git] " + echo -n "path to remote repositories? [~/git] " read REMOTE_REPOS - if [ -z "$REMOTE_REPOS" ]; then - REMOTE_REPOS=~/git + if [ -z "$REMOTE_REPOS" ]; then + REMOTE_REPOS=~/git fi - echo -n "Local repository directory? [~/.fgit] " + 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 - LOCAL_REPOS=~/.fgits + if [ -z "$LOCAL_REPOS" ]; then + LOCAL_REPOS=~/.movein fi - echo -n "Location of .mrconfig file? [~/.mrconfig] " + echo -n "Location of .mrconfig file? [~/.mrconfig] " read MRCONFIG - if [ -z "$MRCONFIG" ]; then - MRCONFIG=~/.mrconfig + if [ -z "$MRCONFIG" ]; then + MRCONFIG=~/.mrconfig fi - cat < .movein + cat < $MOVEINRC GIT_HOST=$GIT_HOST REMOTE_REPOS=$REMOTE_REPOS LOCAL_REPOS=$LOCAL_REPOS MRCONFIG=$MRCONFIG +CREATE_REMOTE=$CREATE_REMOTE EOF - mkdir $LOCAL_REPOS - cat < $MRCONFIG -[DEFAULT] -include = cat /usr/share/mr/git-fake-bare -END + if [ ! -d "$LOCAL_REPOS" ]; then + mkdir -p "$LOCAL_REPOS" + fi + + mr -c "$MRCONFIG" config DEFAULT include="cat /usr/share/mr/git-fake-bare" - } +git_work_tree() { + local TEMP_REPO + TEMP_REPO=$1 + GIT_WORK_TREE=../../ -add() { - if [ $# -ne 1 ]; then - usage + while [ "${TEMP_REPO#*/}" != "$TEMP_REPO" ]; do + TEMP_REPO="${TEMP_REPO#*/}" + GIT_WORK_TREE="../$GIT_WORK_TREE" + done +} + +login() { + if [ $# -ne 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.worktree ../../ - git config core.bare false - GIT_WORK_TREE="$PWD" git pull - trap - 0 - cat <> $MRCONFIG - -[$LOCAL_REPO] -checkout = git_fake_bare_checkout '$REPO_URL' '$REPO_NAME' '../../' -END + export GIT_DIR="$LOCAL_REPOS/${1}.git" + + GIT_PS1_SHOWUNTRACKEDFILES= PSMOVEIN="movein:${1}" $SHELL -i || : +} + +execin() { + local REPO + if [ $# -lt 2 ]; then + usage + fi + + REPO=$1;shift + + export GIT_DIR="$LOCAL_REPOS/${REPO}.git" + + "$@" +} + +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 "unset GIT_DIR; unset GIT_WORK_TREE; rm -rf $LOCAL_REPO" 0 + mkdir -p "$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 config core.worktree "$GIT_WORK_TREE" + git config status.showUntrackedFiles no + git pull + trap - 0 + + mr -c "$MRCONFIG" config "$LOCAL_REPO" checkout="git_fake_bare_checkout '$REPO_URL' '$REPO_NAME' '$GIT_WORK_TREE'" + fi + done +} + +list() { + find "${LOCAL_REPOS}" -mindepth 1 -type d -name '*.git' | sed "s,${LOCAL_REPOS}/,," +} + +listremote() { + ssh $GIT_HOST " + find '${REMOTE_REPOS}' -mindepth 1 -type d -name '*.git' | sed 's,${REMOTE_REPOS}/,,' + " > $MRCONFIG - -[$LOCAL_REPO] -checkout = git_fake_bare_checkout '$REPO_URL' '$REPO_NAME' '../../' -END + trap "unset GIT_DIR; unset GIT_WORK_TREE; rm -rf $LOCAL_REPO" 0 + mkdir -p "$LOCAL_REPO" + + if [ $CREATE_REMOTE -ne 0 ]; then + ssh $GIT_HOST " + GIT_DIR=$REMOTE_REPOS/$REPO_NAME git --bare init + "