Skip to content

Commit 2e4aef5

Browse files
spearceJunio C Hamano
authored andcommitted
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>
1 parent b332718 commit 2e4aef5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

contrib/workdir/git-new-workdir

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ new_workdir=$2
2020
branch=$3
2121

2222
# 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!"
2426

2527
# don't link to a workdir
26-
if test -L "$orig_git/.git/config"
28+
if test -L "$git_dir/config"
2729
then
2830
die "\"$orig_git\" is a working directory only, please specify" \
2931
"a complete repository."
3032
fi
3133

3234
# make sure the the links use full paths
33-
orig_git=$(cd "$orig_git"; pwd)
35+
git_dir=$(cd "$git_dir"; pwd)
3436

3537
# create the workdir
3638
mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!"
@@ -45,13 +47,13 @@ do
4547
mkdir -p "$(dirname "$new_workdir/.git/$x")"
4648
;;
4749
esac
48-
ln -s "$orig_git/.git/$x" "$new_workdir/.git/$x"
50+
ln -s "$git_dir/$x" "$new_workdir/.git/$x"
4951
done
5052

5153
# now setup the workdir
5254
cd "$new_workdir"
5355
# 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
5557
# checkout the branch (either the same as HEAD from the original repository, or
5658
# the one that was asked for)
5759
git checkout -f $branch

0 commit comments

Comments
 (0)