From 4f01748d51b530c297eeb5a0ece9af923d5db937 Mon Sep 17 00:00:00 2001 From: Julian Phillips Date: Tue, 27 Mar 2007 00:15:32 +0100 Subject: contrib/workdir: add a simple script to create a working directory Add a simple script to create a working directory that uses symlinks to point at an exisiting repository. This allows having different branches in different working directories but all from the same repository. Based on a description from Junio of how he creates multiple working directories[1]. With the following caveat: "This risks confusion for an uninitiated if you update a ref that is checked out in another working tree, but modulo that caveat it works reasonably well." [1] http://article.gmane.org/gmane.comp.version-control.git/41513/ Signed-off-by: Julian Phillips Signed-off-by: Junio C Hamano --- contrib/workdir/git-new-workdir | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 contrib/workdir/git-new-workdir (limited to 'contrib/workdir/git-new-workdir') diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir new file mode 100755 index 0000000000..9877b98508 --- /dev/null +++ b/contrib/workdir/git-new-workdir @@ -0,0 +1,57 @@ +#!/bin/sh + +usage () { + echo "usage:" $@ + exit 127 +} + +die () { + echo $@ + exit 128 +} + +if test $# -lt 2 || test $# -gt 3 +then + usage "$0 []" +fi + +orig_git=$1 +new_workdir=$2 +branch=$3 + +# want to make sure that what is pointed to has a .git directory ... +test -d "$orig_git/.git" || die "\"$orig_git\" is not a git repository!" + +# don't link to a workdir +if test -L "$orig_git/.git/config" +then + die "\"$orig_git\" is a working directory only, please specify" \ + "a complete repository." +fi + +# make sure the the links use full paths +orig_git=$(cd "$orig_git"; pwd) + +# create the workdir +mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!" + +# create the links to the original repo. explictly exclude index, HEAD and +# logs/HEAD from the list since they are purely related to the current working +# directory, and should not be shared. +for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache +do + case $x in + */*) + mkdir -p "$(dirname "$new_workdir/.git/$x")" + ;; + esac + ln -s "$orig_git/.git/$x" "$new_workdir/.git/$x" +done + +# now setup the workdir +cd "$new_workdir" +# copy the HEAD from the original repository as a default branch +cp "$orig_git/.git/HEAD" .git/HEAD +# checkout the branch (either the same as HEAD from the original repository, or +# the one that was asked for) +git checkout -f $branch -- cgit v1.2.3 From 2e4aef58932cdb345893103d77823a9dd6a146a6 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 26 May 2007 23:09:27 -0400 Subject: 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 Signed-off-by: Junio C Hamano --- contrib/workdir/git-new-workdir | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'contrib/workdir/git-new-workdir') diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir index 9877b98508..f2a3615bbc 100755 --- a/contrib/workdir/git-new-workdir +++ b/contrib/workdir/git-new-workdir @@ -20,17 +20,19 @@ new_workdir=$2 branch=$3 # want to make sure that what is pointed to has a .git directory ... -test -d "$orig_git/.git" || die "\"$orig_git\" is not a git repository!" +git_dir=$(cd "$orig_git" 2>/dev/null && + git rev-parse --git-dir 2>/dev/null) || + die "\"$orig_git\" is not a git repository!" # don't link to a workdir -if test -L "$orig_git/.git/config" +if test -L "$git_dir/config" then die "\"$orig_git\" is a working directory only, please specify" \ "a complete repository." fi # make sure the the links use full paths -orig_git=$(cd "$orig_git"; pwd) +git_dir=$(cd "$git_dir"; pwd) # create the workdir mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!" @@ -45,13 +47,13 @@ do mkdir -p "$(dirname "$new_workdir/.git/$x")" ;; esac - ln -s "$orig_git/.git/$x" "$new_workdir/.git/$x" + ln -s "$git_dir/$x" "$new_workdir/.git/$x" done # now setup the workdir cd "$new_workdir" # copy the HEAD from the original repository as a default branch -cp "$orig_git/.git/HEAD" .git/HEAD +cp "$git_dir/HEAD" .git/HEAD # checkout the branch (either the same as HEAD from the original repository, or # the one that was asked for) git checkout -f $branch -- cgit v1.2.3 From 09381b458f5f1ac1a78df1aaeeb53aa79fcf2c4f Mon Sep 17 00:00:00 2001 From: Julian Phillips Date: Tue, 19 Jun 2007 12:44:43 +0100 Subject: new-workdir: handle rev-parse --git-dir not always giving full path rev-parse --git-dir outputs a full path - except for the single case of when the path would be $(pwd)/.git, in which case it outputs simply .git. Check for this special case and handle it. Signed-off-by: Julian Phillips Signed-off-by: Junio C Hamano --- contrib/workdir/git-new-workdir | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'contrib/workdir/git-new-workdir') diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir index f2a3615bbc..709b2a3ac0 100755 --- a/contrib/workdir/git-new-workdir +++ b/contrib/workdir/git-new-workdir @@ -24,6 +24,11 @@ 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 + git_dir="$orig_git/.git" +fi + # don't link to a workdir if test -L "$git_dir/config" then -- cgit v1.2.3 From b658d50325c938d87d4891cb62e2eefb0b58a62c Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 25 Jun 2007 13:04:26 +0200 Subject: git-new-workdir: Fix shell warning about operator == used with test. Use = instead of == with test to test for equality. Signed-off-by: Simon Hausmann Signed-off-by: Junio C Hamano --- contrib/workdir/git-new-workdir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/workdir/git-new-workdir') diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir index 709b2a3ac0..3ff6bd166a 100755 --- a/contrib/workdir/git-new-workdir +++ b/contrib/workdir/git-new-workdir @@ -24,7 +24,7 @@ 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" +if test "$git_dir" = ".git" then git_dir="$orig_git/.git" fi -- cgit v1.2.3 From e301bfeea19e284344868840793c58d2e7529c74 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 21 Aug 2007 21:50:12 -0400 Subject: Fix new-workdir (again) to work on bare repositories My day-job workflow involves using multiple workdirs attached to a bunch of bare repositories. Such repositories are stored inside of a directory called "foo.git", which means `git rev-parse --git-dir` will return "." and not ".git". Under such conditions new-workdir was getting confused about where the Git repository it was supplied is actually located. If we get "." for the result of --git-dir query it means we should use the user supplied path as-is, and not attempt to perform any magic on it, as the path is directly to the repository. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- contrib/workdir/git-new-workdir | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'contrib/workdir/git-new-workdir') diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir index 3ff6bd166a..119cff9859 100755 --- a/contrib/workdir/git-new-workdir +++ b/contrib/workdir/git-new-workdir @@ -24,10 +24,14 @@ 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" -fi + ;; +.) + git_dir=$orig_git + ;; +esac # don't link to a workdir if test -L "$git_dir/config" -- cgit v1.2.3 From 8fa0ee3b50736eb869a3e13375bb041c1bf5aa12 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 22 Aug 2007 01:33:49 -0400 Subject: Suggest unsetting core.bare when using new-workdir on a bare repository If core.bare is set to true in the config file of a repository that the user is trying to create a working directory from we should abort and suggest to the user that they remove the option first. If we leave the core.bare=true setting in the config file then working tree operations will get confused when they attempt to execute in the new workdir, as it shares its config file with the bare repository. The working tree operations will assume that the workdir is bare and abort, which is not what the user wants. If we changed core.bare to be false then working tree operations will function in the workdir but other operations may fail in the bare repository, as it claims to not be bare. If we remove core.bare from the config then Git can fallback on the legacy guessing behavior. This allows operations in the bare repository to work as though it were bare, while operations in the workdirs to act as though they are not bare. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- contrib/workdir/git-new-workdir | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'contrib/workdir/git-new-workdir') diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir index 119cff9859..c6e154a84f 100755 --- a/contrib/workdir/git-new-workdir +++ b/contrib/workdir/git-new-workdir @@ -33,6 +33,14 @@ case "$git_dir" in ;; 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 if test -L "$git_dir/config" then -- cgit v1.2.3 From ea09ea22d65d118328642e03ad23c8257304499d Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 5 Sep 2007 23:33:41 -0400 Subject: Don't allow contrib/workdir/git-new-workdir to trash existing dirs Recently I found that doing a sequence like the following: git-new-workdir a b ... git-new-workdir a b by accident will cause a (and now also b) to have an infinite cycle in its refs directory. This is caused by git-new-workdir trying to create the "refs" symlink over again, only during the second time it is being created within a's refs directory and is now also pointing back at a's refs. This causes confusion in git as suddenly branches are named things like "refs/refs/refs/refs/refs/refs/refs/heads/foo" instead of the more commonly accepted "refs/heads/foo". Plenty of commands start to see ambiguous ref names and others just take ages to compute. git-clone has the same safety check, so git-new-workdir should behave just like it. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- contrib/workdir/git-new-workdir | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'contrib/workdir/git-new-workdir') diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir index c6e154a84f..2838546d16 100755 --- a/contrib/workdir/git-new-workdir +++ b/contrib/workdir/git-new-workdir @@ -48,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) -- cgit v1.2.3 From ac378633f3cae46d2c88255e53ee38a6206d3777 Mon Sep 17 00:00:00 2001 From: Bernt Hansen Date: Fri, 14 Mar 2008 22:44:13 -0400 Subject: git-new-workdir: Share SVN meta data between work dirs and the repository Multiple work dirs with git svn caused each work dir to have its own stale copy of the SVN meta data in .git/svn git svn rebase updates commits with git-svn-id: in the repository and stores the SVN meta data information only in that work dir. Attempting to git svn rebase in other work dirs for the same branch would fail because the last revision fetched according to the git-svn-id is greater than the revision in the SVN meta data for that work directory. Signed-off-by: Bernt Hansen Acked-by: Eric Wong Signed-off-by: Junio C Hamano --- contrib/workdir/git-new-workdir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/workdir/git-new-workdir') diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir index 2838546d16..7959eab902 100755 --- a/contrib/workdir/git-new-workdir +++ b/contrib/workdir/git-new-workdir @@ -63,7 +63,7 @@ mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!" # create the links to the original repo. explictly exclude index, HEAD and # logs/HEAD from the list since they are purely related to the current working # directory, and should not be shared. -for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache +for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn do case $x in */*) -- cgit v1.2.3 From f66bc5f928194366ee5eb78ef18a3562fb1bb7cf Mon Sep 17 00:00:00 2001 From: Richard Hartmann Date: Mon, 22 Dec 2008 00:17:32 +0100 Subject: Always show which directory is not a git repository Unify all fatal: Not a git repository error messages so they include path information. Signed-off-by: Richard Hartmann Signed-off-by: Junio C Hamano --- contrib/workdir/git-new-workdir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/workdir/git-new-workdir') diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir index 7959eab902..993cacf324 100755 --- a/contrib/workdir/git-new-workdir +++ b/contrib/workdir/git-new-workdir @@ -22,7 +22,7 @@ branch=$3 # want to make sure that what is pointed to has a .git directory ... git_dir=$(cd "$orig_git" 2>/dev/null && git rev-parse --git-dir 2>/dev/null) || - die "\"$orig_git\" is not a git repository!" + die "Not a git repository: \"$orig_git\"" case "$git_dir" in .git) -- cgit v1.2.3 From 22e5e58a3c75b73764b860907e4d871195f276ac Mon Sep 17 00:00:00 2001 From: Ralf Wildenhues Date: Sun, 22 Aug 2010 13:12:12 +0200 Subject: Typos in code comments, an error message, documentation Signed-off-by: Ralf Wildenhues Signed-off-by: Junio C Hamano --- contrib/workdir/git-new-workdir | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'contrib/workdir/git-new-workdir') diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir index 993cacf324..3ad2c0cea5 100755 --- a/contrib/workdir/git-new-workdir +++ b/contrib/workdir/git-new-workdir @@ -54,13 +54,13 @@ then die "destination directory '$new_workdir' already exists." fi -# make sure the the links use full paths +# make sure the links use full paths git_dir=$(cd "$git_dir"; pwd) # create the workdir mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!" -# create the links to the original repo. explictly exclude index, HEAD and +# create the links to the original repo. explicitly exclude index, HEAD and # logs/HEAD from the list since they are purely related to the current working # directory, and should not be shared. for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn -- cgit v1.2.3 From afa0876050496d4250e8b27680e5cbc60fbda760 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 21 Sep 2010 20:35:59 -0400 Subject: prefer test -h over test -L in shell scripts Even though "-L" is POSIX, the former is more portable, and we tend to prefer it already. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- contrib/workdir/git-new-workdir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/workdir/git-new-workdir') diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir index 3ad2c0cea5..75e8b25817 100755 --- a/contrib/workdir/git-new-workdir +++ b/contrib/workdir/git-new-workdir @@ -42,7 +42,7 @@ then fi # don't link to a workdir -if test -L "$git_dir/config" +if test -h "$git_dir/config" then die "\"$orig_git\" is a working directory only, please specify" \ "a complete repository." -- cgit v1.2.3