X-Git-Url: https://git.madduck.net/code/myrepos.git/blobdiff_plain/22abbafff6704623678e9c65b7aaa5f2a6339fb0..0930c82183317ae2cd44bfa9c871325467406de2:/mr diff --git a/mr b/mr index 4c4d267..0e14168 100755 --- a/mr +++ b/mr @@ -931,10 +931,17 @@ ls = list [DEFAULT] order = 10 lib = + PWD="$pwd" error() { echo "mr: $@" >&2 exit 1 } + warning() { + echo "mr (warning): $@" >&2 + } + info() { + echo "mr: $@" >&2 + } hours_since() { if [ -z "$1" ] || [ -z "$2" ]; then error "mr: usage: hours_since action num" @@ -1076,7 +1083,7 @@ register = if [ -n "$1" ]; then cd "$1" fi - basedir="$(basename $(pwd))" + basedir="${PWD##*/}" case "$(get_repo_type .)" in svn) url=$(LANG=C svn info . | grep -i ^URL: | cut -d ' ' -f 2) @@ -1084,7 +1091,7 @@ register = error "cannot determine svn url" fi echo "Registering svn url: $url in $MR_CONFIG" - mr -c "$MR_CONFIG" config "$(pwd)" checkout="svn co $url $basedir" + mr -c "$MR_CONFIG" config "$PWD" checkout="svn co $url $basedir" ;; git) local repo_type; repo_type="$(get_git_repo_type .)" @@ -1093,26 +1100,34 @@ register = non-bare) config=.git/config;; bare|fake-bare) config=config;; esac - url="$(LANG=C GIT_CONFIG="$config" git-config --get remote.origin.url)" + url="$(LANG=C GIT_CONFIG="$config" git-config --get remote.origin.url)" || : if [ -z "$url" ]; then error "cannot determine git url" fi + local clone_opts add_cmd work_tree suffix case "$repo_type" in - bare|fake-bare) - # this seems like a bare repo as it has no - # worktree. - local work_tree + fake-bare) + # this seems like a fake bare repo and needs a worktree work_tree="$(git-config --get core.worktree)" || : + work_tree="${work_tree%%/}/" if [ ! -d "$work_tree" ]; then - error "git worktree $work_tree does not exist" + error "git worktree '$work_tree' does not exist" fi + clone_opts=" --no-checkout" + add_cmd="$add_cmd && cd $basedir" + add_cmd="$add_cmd && git read-tree HEAD" + add_cmd="$add_cmd && git checkout-index -a --prefix='$work_tree' || :" + add_cmd="$add_cmd; git config core.worktree '$work_tree'" + add_cmd="$add_cmd && mv .git/* . && rmdir .git" suffix=" (with worktree $work_tree)" - mr -c "$MR_CONFIG" config "$(pwd)" \ - lib="GIT_WORK_TREE=$work_tree; export GIT_WORK_TREE" + ;; + bare) + clone_opts=" --bare" + suffix=" (bare repository)" ;; esac echo "Registering git url: $url in $MR_CONFIG${suffix:-}" - mr -c "$MR_CONFIG" config "$(pwd)" checkout="git clone $url $basedir" + mr -c "$MR_CONFIG" config "$PWD" checkout="git clone${clone_opts:-} $url $basedir${add_cmd:-}" ;; bzr) url=$(cat .bzr/branch/parent) @@ -1120,7 +1135,7 @@ register = error "cannot determine bzr url" fi echo "Registering bzr url: $url in $MR_CONFIG" - mr -c "$MR_CONFIG" config "$(pwd)" checkout="bzr clone $url $basedir" + mr -c "$MR_CONFIG" config "$PWD" checkout="bzr clone $url $basedir" ;; CVS) repo=$(cat CVS/Repository) @@ -1129,19 +1144,19 @@ register = error "cannot determine cvs root" fi echo "Registering cvs repository $repo at root $root" - mr -c "$MR_CONFIG" config "$(pwd)" \ + mr -c "$MR_CONFIG" config "$PWD" \ checkout="cvs -d '$root' co -d $basedir $repo" ;; hg) url=$(hg showconfig paths.default) echo "Registering mercurial repo url: $url in $MR_CONFIG" - mr -c "$MR_CONFIG" config "$(pwd)" \ + mr -c "$MR_CONFIG" config "$PWD" \ checkout="hg clone $url $basedir" ;; darcs) url=$(cat _darcs/prefs/defaultrepo) echo "Registering darcs repository $url in $MR_CONFIG" - mr -c "$MR_CONFIG" config "$(pwd)" \ + mr -c "$MR_CONFIG" config "$PWD" \ checkout="darcs get $url $basedir" ;; *) error "unable to register this repo type";;