@matheusbsbs / matheus-bagliano / commits / 2e4aef5893
Fork 0

Allow contrib new-workdir to link into bare repositories

On one particular system I like to keep a cluster of bare Git repositories and spawn new-workdirs off of them. Since the bare repositories don't have working directories associated with them they don't have a .git/ subdirectory that hosts the repository we are linking to. Using a bare repository as the backing repository for a workdir created by this script does require that the user delete core.bare from the repository's configuration file, so that Git auto-senses the bareness of a repository based on pathname information, and not based on the config file. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed May 26, 2007 at 23:09 UTC 2e4aef58932cdb345893103d77823a9dd6a146a6
1 file changed +7 -5
contrib/workdir/git-new-workdir
+7 -5
@@ -20,17 +20,19 @@ new_workdir=$2
20 branch=$3
21
22 # want to make sure that what is pointed to has a .git directory ...
23 -test -d "$orig_git/.git" || die "\"$orig_git\" is not a git repository!"
23 +git_dir=$(cd "$orig_git" 2>/dev/null &&
24 + git rev-parse --git-dir 2>/dev/null) ||
25 + die "\"$orig_git\" is not a git repository!"
26
27 # don't link to a workdir
26 -if test -L "$orig_git/.git/config"
28 +if test -L "$git_dir/config"
29 then
30 die "\"$orig_git\" is a working directory only, please specify" \
31 "a complete repository."
32 fi
33
34 # make sure the the links use full paths
33 -orig_git=$(cd "$orig_git"; pwd)
35 +git_dir=$(cd "$git_dir"; pwd)
36
37 # create the workdir
38 mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!"
@@ -45,13 +47,13 @@ do
47 mkdir -p "$(dirname "$new_workdir/.git/$x")"
48 ;;
49 esac
48 - ln -s "$orig_git/.git/$x" "$new_workdir/.git/$x"
50 + ln -s "$git_dir/$x" "$new_workdir/.git/$x"
51 done
52
53 # now setup the workdir
54 cd "$new_workdir"
55 # copy the HEAD from the original repository as a default branch
54 -cp "$orig_git/.git/HEAD" .git/HEAD
56 +cp "$git_dir/HEAD" .git/HEAD
57 # checkout the branch (either the same as HEAD from the original repository, or
58 # the one that was asked for)
59 git checkout -f $branch