Code

Merge branch 'mk/color'
[git.git] / contrib / workdir / git-new-workdir
index 709b2a3ac0e7603eadd9f62a795967c415d554df..2838546d16073f29b3a87ce9126d92b0f640be5e 100755 (executable)
@@ -24,9 +24,21 @@ git_dir=$(cd "$orig_git" 2>/dev/null &&
   git rev-parse --git-dir 2>/dev/null) ||
   die "\"$orig_git\" is not a git repository!"
 
-if test "$git_dir" == ".git"
-then
+case "$git_dir" in
+.git)
        git_dir="$orig_git/.git"
+       ;;
+.)
+       git_dir=$orig_git
+       ;;
+esac
+
+# don't link to a configured bare repository
+isbare=$(git --git-dir="$git_dir" config --bool --get core.bare)
+if test ztrue = z$isbare
+then
+       die "\"$git_dir\" has core.bare set to true," \
+               " remove from \"$git_dir/config\" to use $0"
 fi
 
 # don't link to a workdir
@@ -36,6 +48,12 @@ then
                "a complete repository."
 fi
 
+# don't recreate a workdir over an existing repository
+if test -e "$new_workdir"
+then
+       die "destination directory '$new_workdir' already exists."
+fi
+
 # make sure the the links use full paths
 git_dir=$(cd "$git_dir"; pwd)