From 61dde8f91672ab362f3cfd3af8d6d09d448d4ffe Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 16 Dec 2006 01:14:39 -0800 Subject: [PATCH 01/10] git-clone: use wildcard specification for tracking branches This stops enumerating the set of branches found on the remote side when a clone was made in the configuration file. Instead, a single entry that maps each remote branch to the local tracking branch for the remote under the same name is created. Doing it this way not only shortens the configuration file, but automatically adjusts to a new branch added on the remote side after the clone is made. Unfortunately this cannot be done for the traditional layout, where we always need to special case the 'master' to 'origin' mapping within the local branch namespace. But that is Ok; it will be going away before v1.5.0. We could also lose the "primary branch" mapping at the beginning, but that has to wait until we implement the "forbid 'git pull' when we do not have branch.$current.merge for the current branch" policy we earlier discussed. That should also be in v1.5.0 Signed-off-by: Junio C Hamano --- git-clone.sh | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/git-clone.sh b/git-clone.sh index 1f5d07a057..422499a537 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -366,41 +366,54 @@ then ) ) - # Write out remotes/$origin file, and update our "$head_points_at". + # Write out remote.$origin config, and update our "$head_points_at". case "$head_points_at" in ?*) - mkdir -p "$GIT_DIR/remotes" && + # Local default branch git-symbolic-ref HEAD "refs/heads/$head_points_at" && + + # Tracking branch for the primary branch at the remote. case "$use_separate_remote" in t) origin_track="$remote_top/$head_points_at" git-update-ref HEAD "$head_sha1" ;; *) origin_track="$remote_top/$origin" git-update-ref "refs/heads/$origin" "$head_sha1" ;; esac && + + # Upstream URL and the primary branch tracking git-repo-config remote."$origin".url "$repo" && git-repo-config remote."$origin".fetch \ "refs/heads/$head_points_at:$origin_track" && - (cd "$GIT_DIR/$remote_top" && find . -type f -print) | - while read dotslref - do - name=`expr "$dotslref" : './\(.*\)'` - if test "z$head_points_at" = "z$name" - then - continue - fi - if test "$use_separate_remote" = '' && - test "z$origin" = "z$name" - then - continue - fi - git-repo-config remote."$origin".fetch "refs/heads/${name}:$remote_top/${name}" '^$' - done && + + # Set up the mappings to track the remaining branches. + case "$use_separate_remote" in + t) + git-repo-config remote."$origin".fetch \ + "refs/heads/*:$remote_top/*" '^$' + ;; + *) + (cd "$GIT_DIR/$remote_top" && find . -type f -print) | + while read dotslref + do + name=`expr "$dotslref" : './\(.*\)'` + if test "z$head_points_at" = "z$name" || + test "z$origin" = "z$name" + then + continue + fi + git-repo-config remote."$origin".fetch \ + "refs/heads/${name}:$remote_top/${name}" '^$' + done + ;; + esac && + case "$use_separate_remote" in t) rm -f "refs/remotes/$origin/HEAD" git-symbolic-ref "refs/remotes/$origin/HEAD" \ "refs/remotes/$origin/$head_points_at" esac && + git-repo-config branch."$head_points_at".remote "$origin" && git-repo-config branch."$head_points_at".merge "refs/heads/$head_points_at" esac From a71fb0a1412c82405f078fb536797d3f5de68d53 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 16 Dec 2006 01:36:32 -0800 Subject: [PATCH 02/10] git-pull: refuse default merge without branch.*.merge Everybody hated the pull behaviour of merging the first branch listed on remotes/* file (or remote.*.fetch config) into the current branch. This finally corrects that UI wart by forbidding "git pull" without an explicit branch name on the command line or branch.$current.merge for the current branch. The matching change to git-clone was made to prepare the default branch.*.merge entry for the primary branch some time ago. Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-parse-remote.sh b/git-parse-remote.sh index 6ae534bf89..f27c3c231b 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -144,7 +144,8 @@ canon_refs_list_for_fetch () { curr_branch=$(git-symbolic-ref HEAD | \ sed -e 's|^refs/heads/||') merge_branches=$(git-repo-config \ - --get-all "branch.${curr_branch}.merge") + --get-all "branch.${curr_branch}.merge") || + merge_branches=.this.would.never.match.any.ref. fi set x $(expand_refs_wildcard "$@") shift From 3dd3d5b0e20a74a82a7e684d63d9af86a983fbf6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 16 Dec 2006 01:41:51 -0800 Subject: [PATCH 03/10] git-clone: lose the artificial "first" fetch refspec Now we lost the "first refspec is the one that is merged by default" rule, there is no reason for clone to list the remote primary branch in the config file explicitly anymore. We still need it for the traditional layout for other reasons, though. Signed-off-by: Junio C Hamano --- git-clone.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git-clone.sh b/git-clone.sh index 422499a537..68dc4f200a 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -380,18 +380,18 @@ then git-update-ref "refs/heads/$origin" "$head_sha1" ;; esac && - # Upstream URL and the primary branch tracking + # Upstream URL git-repo-config remote."$origin".url "$repo" && - git-repo-config remote."$origin".fetch \ - "refs/heads/$head_points_at:$origin_track" && - # Set up the mappings to track the remaining branches. + # Set up the mappings to track the remote branches. case "$use_separate_remote" in t) git-repo-config remote."$origin".fetch \ "refs/heads/*:$remote_top/*" '^$' ;; *) + git-repo-config remote."$origin".fetch \ + "refs/heads/$head_points_at:$origin_track" && (cd "$GIT_DIR/$remote_top" && find . -type f -print) | while read dotslref do From 63085fabbdeaad9eb8b29d39d0998c704e6cd232 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 16 Dec 2006 01:53:10 -0800 Subject: [PATCH 04/10] git-clone: lose the traditional 'no-separate-remote' layout Finally. The separate-remote layout is so much more organized than traditional and easier to work with especially when you need to deal with remote repositories with multiple branches and/or you need to deal with more than one remote repositories, and using traditional layout for new repositories simply does not make much sense. Internally we still have code for 1:1 mappings to create a bare clone; that is a good thing and will not go away. Signed-off-by: Junio C Hamano --- Documentation/git-clone.txt | 15 +--------- git-clone.sh | 58 ++++++++----------------------------- 2 files changed, 13 insertions(+), 60 deletions(-) diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index bfddb21fee..874934a332 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -11,8 +11,7 @@ SYNOPSIS [verse] 'git-clone' [--template=] [-l [-s]] [-q] [-n] [--bare] [-o ] [-u ] [--reference ] - [--use-separate-remote | --no-separate-remote] - [] + [] DESCRIPTION ----------- @@ -99,18 +98,6 @@ OPTIONS if unset the templates are taken from the installation defined default, typically `/usr/share/git-core/templates`. ---use-separate-remote:: - Save remotes heads under `$GIT_DIR/refs/remotes/origin/` instead - of `$GIT_DIR/refs/heads/`. Only the local master branch is - saved in the latter. This is the default. - ---no-separate-remote:: - Save remotes heads in the same namespace as the local - heads, `$GIT_DIR/refs/heads/'. In regular repositories, - this is a legacy setup git-clone created by default in - older Git versions, and will be removed before the next - major release. - :: The (possibly remote) repository to clone from. It can be any URL git-fetch supports. diff --git a/git-clone.sh b/git-clone.sh index 68dc4f200a..490f3e48db 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -14,7 +14,7 @@ die() { } usage() { - die "Usage: $0 [--template=] [--no-separate-remote] [--reference ] [--bare] [-l [-s]] [-q] [-u ] [--origin ] [-n] []" + die "Usage: $0 [--template=] [--reference ] [--bare] [-l [-s]] [-q] [-u ] [--origin ] [-n] []" } get_repo_base() { @@ -137,11 +137,9 @@ while *,--template=*) template="$1" ;; *,-q|*,--quiet) quiet=-q ;; - *,--use-separate-remote) - # default - use_separate_remote=t ;; + *,--use-separate-remote) ;; *,--no-separate-remote) - use_separate_remote= ;; + die "clones are always made with separate-remote layout" ;; 1,--reference) usage ;; *,--reference) shift; reference="$1" ;; @@ -327,12 +325,8 @@ cd "$D" || exit if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD" then - # Figure out which remote branch HEAD points at. - case "$use_separate_remote" in - '') remote_top=refs/heads ;; - *) remote_top="refs/remotes/$origin" ;; - esac - + # a non-bare repository is always in separate-remote layout + remote_top="refs/remotes/$origin" head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"` case "$head_sha1" in 'ref: refs/'*) @@ -373,46 +367,18 @@ then git-symbolic-ref HEAD "refs/heads/$head_points_at" && # Tracking branch for the primary branch at the remote. - case "$use_separate_remote" in - t) origin_track="$remote_top/$head_points_at" - git-update-ref HEAD "$head_sha1" ;; - *) origin_track="$remote_top/$origin" - git-update-ref "refs/heads/$origin" "$head_sha1" ;; - esac && + origin_track="$remote_top/$head_points_at" && + git-update-ref HEAD "$head_sha1" && # Upstream URL git-repo-config remote."$origin".url "$repo" && # Set up the mappings to track the remote branches. - case "$use_separate_remote" in - t) - git-repo-config remote."$origin".fetch \ - "refs/heads/*:$remote_top/*" '^$' - ;; - *) - git-repo-config remote."$origin".fetch \ - "refs/heads/$head_points_at:$origin_track" && - (cd "$GIT_DIR/$remote_top" && find . -type f -print) | - while read dotslref - do - name=`expr "$dotslref" : './\(.*\)'` - if test "z$head_points_at" = "z$name" || - test "z$origin" = "z$name" - then - continue - fi - git-repo-config remote."$origin".fetch \ - "refs/heads/${name}:$remote_top/${name}" '^$' - done - ;; - esac && - - case "$use_separate_remote" in - t) - rm -f "refs/remotes/$origin/HEAD" - git-symbolic-ref "refs/remotes/$origin/HEAD" \ - "refs/remotes/$origin/$head_points_at" - esac && + git-repo-config remote."$origin".fetch \ + "refs/heads/*:$remote_top/*" '^$' && + rm -f "refs/remotes/$origin/HEAD" + git-symbolic-ref "refs/remotes/$origin/HEAD" \ + "refs/remotes/$origin/$head_points_at" && git-repo-config branch."$head_points_at".remote "$origin" && git-repo-config branch."$head_points_at".merge "refs/heads/$head_points_at" From 74d20040cafdced657efbf49795183d209a3a07b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 18 Dec 2006 15:27:43 -0800 Subject: [PATCH 05/10] fix testsuite: make sure they use templates freshly built from the source The initial t/trash repository for testing was created properly but over time we gained many tests that create secondary test repositories with init-db or clone and they were not careful enough. This fixes it. Signed-off-by: Junio C Hamano --- t/t4116-apply-reverse.sh | 4 ++-- t/t5300-pack-object.sh | 6 +++--- t/t5400-send-pack.sh | 2 +- t/t5500-fetch-pack.sh | 2 +- t/t5510-fetch.sh | 8 ++++---- t/t5520-pull.sh | 2 +- t/t5600-clone-fail-cleanup.sh | 6 +++--- t/t5700-clone-reference.sh | 4 ++-- t/t5710-info-alternate.sh | 14 +++++++------- t/t7001-mv.sh | 4 ++-- t/test-lib.sh | 10 ++++++++++ 11 files changed, 36 insertions(+), 26 deletions(-) diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh index 74f5c2a575..a79c77af39 100755 --- a/t/t4116-apply-reverse.sh +++ b/t/t4116-apply-reverse.sh @@ -50,12 +50,12 @@ test_expect_success 'setup separate repository lacking postimage' ' git tar-tree initial initial | tar xf - && ( - cd initial && git init-db && git add . + cd initial && git_init_db && git add . ) && git tar-tree second second | tar xf - && ( - cd second && git init-db && git add . + cd second && git_init_db && git add . ) ' diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index de45ac4e0f..8a8152b257 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -44,7 +44,7 @@ test_expect_success \ 'unpack without delta' \ "GIT_OBJECT_DIRECTORY=.git2/objects && export GIT_OBJECT_DIRECTORY && - git-init-db && + git_init_db && git-unpack-objects -n > log2.txt + git_init_db 2>> log2.txt ) add A1 diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index a11ab0ad41..e2e8c894f9 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -15,12 +15,12 @@ test_expect_success setup ' git commit -a -m original' test_expect_success "clone and setup child repos" ' - git clone . one && + git_clone . one && cd one && echo >file updated by one && git commit -a -m "updated by one" && cd .. && - git clone . two && + git_clone . two && cd two && git repo-config branch.master.remote one && { @@ -28,7 +28,7 @@ test_expect_success "clone and setup child repos" ' echo "Pull: refs/heads/master:refs/heads/one" } >.git/remotes/one cd .. && - git clone . three && + git_clone . three && cd three && git repo-config branch.master.remote two && git repo-config branch.master.merge refs/heads/one && @@ -74,7 +74,7 @@ test_expect_success 'fetch following tags' ' mkdir four && cd four && - git init-db && + git_init_db && git fetch .. :track && git show-ref --verify refs/tags/anno && diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index f841574573..66ef92f41f 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -17,7 +17,7 @@ test_expect_success setup ' test_expect_success 'pulling into void' ' mkdir cloned && cd cloned && - git init-db && + git_init_db && git pull .. ' diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh index 041be04f5c..1913a12d71 100755 --- a/t/t5600-clone-fail-cleanup.sh +++ b/t/t5600-clone-fail-cleanup.sh @@ -13,7 +13,7 @@ remove the directory before attempting a clone again.' test_expect_failure \ 'clone of non-existent source should fail' \ - 'git-clone foo bar' + 'git_clone foo bar' test_expect_failure \ 'failed clone should not leave a directory' \ @@ -29,11 +29,11 @@ test_create_repo foo # current path not to the target dir test_expect_failure \ 'clone of non-existent (relative to $PWD) source should fail' \ - 'git-clone ../foo baz' + 'git_clone ../foo baz' test_expect_success \ 'clone should work now that source exists' \ - 'git-clone foo bar' + 'git_clone foo bar' test_expect_success \ 'successfull clone must leave the directory' \ diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh index dd9caad1c2..52dab2d484 100755 --- a/t/t5700-clone-reference.sh +++ b/t/t5700-clone-reference.sh @@ -17,7 +17,7 @@ git commit -m initial' cd "$base_dir" test_expect_success 'preparing second repository' \ -'git clone A B && cd B && +'git_clone A B && cd B && echo second > file2 && git add file2 && git commit -m addition && @@ -27,7 +27,7 @@ git prune' cd "$base_dir" test_expect_success 'cloning with reference' \ -'git clone -l -s --reference B A C' +'git_clone -l -s --reference B A C' cd "$base_dir" diff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh index b9f6d96363..3c43554c69 100755 --- a/t/t5710-info-alternate.sh +++ b/t/t5710-info-alternate.sh @@ -34,7 +34,7 @@ git prune' cd "$base_dir" test_expect_success 'preparing second repository' \ -'git clone -l -s A B && cd B && +'git_clone -l -s A B && cd B && echo "foo bar" > file2 && git add file2 && git commit -m "next commit" file2 && @@ -44,7 +44,7 @@ git prune' cd "$base_dir" test_expect_success 'preparing third repository' \ -'git clone -l -s B C && cd C && +'git_clone -l -s B C && cd C && echo "Goodbye, cruel world" > file3 && git add file3 && git commit -m "one more" file3 && @@ -54,11 +54,11 @@ git prune' cd "$base_dir" test_expect_failure 'creating too deep nesting' \ -'git clone -l -s C D && -git clone -l -s D E && -git clone -l -s E F && -git clone -l -s F G && -git clone -l -s G H && +'git_clone -l -s C D && +git_clone -l -s D E && +git_clone -l -s E F && +git_clone -l -s F G && +git_clone -l -s G H && cd H && test_valid_repo' diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 2f4ff82e14..ae597e80dd 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -88,7 +88,7 @@ test_expect_success \ test_expect_success "Michael Cassar's test case" ' rm -fr .git papers partA && - git init-db && + git_init_db && mkdir -p papers/unsorted papers/all-papers partA && echo a > papers/unsorted/Thesis.pdf && echo b > partA/outline.txt && @@ -109,7 +109,7 @@ rm -fr papers partA path? test_expect_success "Sergey Vlasov's test case" ' rm -fr .git && - git init-db && + git_init_db && mkdir ab && date >ab.c && date >ab/d && diff --git a/t/test-lib.sh b/t/test-lib.sh index ac7be769b4..7e9149751e 100755 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -182,6 +182,16 @@ test_create_repo () { cd "$owd" } +# Many tests do init-db and clone but they must be told about the freshly +# built templates. +git_init_db () { + git init-db --template="$GIT_EXEC_PATH/templates/blt/" "$@" +} + +git_clone () { + git clone --template="$GIT_EXEC_PATH/templates/blt/" "$@" +} + test_done () { trap - exit case "$test_failure" in From 171e800b374c98dd703e906bd9955b2b0410cabe Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 19 Dec 2006 01:14:35 -0800 Subject: [PATCH 06/10] Revert "fix testsuite: make sure they use templates freshly built from the source" This reverts commit 74d20040cafdced657efbf49795183d209a3a07b. Version from Johannes to introduce GIT_TEMPLATE_DIR is simpler, although I unconsciously stayed away from introducing yet another environment variable. --- t/t4116-apply-reverse.sh | 4 ++-- t/t5300-pack-object.sh | 6 +++--- t/t5400-send-pack.sh | 2 +- t/t5500-fetch-pack.sh | 2 +- t/t5510-fetch.sh | 8 ++++---- t/t5520-pull.sh | 2 +- t/t5600-clone-fail-cleanup.sh | 6 +++--- t/t5700-clone-reference.sh | 4 ++-- t/t5710-info-alternate.sh | 14 +++++++------- t/t7001-mv.sh | 4 ++-- t/test-lib.sh | 10 ---------- 11 files changed, 26 insertions(+), 36 deletions(-) diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh index a79c77af39..74f5c2a575 100755 --- a/t/t4116-apply-reverse.sh +++ b/t/t4116-apply-reverse.sh @@ -50,12 +50,12 @@ test_expect_success 'setup separate repository lacking postimage' ' git tar-tree initial initial | tar xf - && ( - cd initial && git_init_db && git add . + cd initial && git init-db && git add . ) && git tar-tree second second | tar xf - && ( - cd second && git_init_db && git add . + cd second && git init-db && git add . ) ' diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 8a8152b257..de45ac4e0f 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -44,7 +44,7 @@ test_expect_success \ 'unpack without delta' \ "GIT_OBJECT_DIRECTORY=.git2/objects && export GIT_OBJECT_DIRECTORY && - git_init_db && + git-init-db && git-unpack-objects -n > log2.txt + git-init-db 2>> log2.txt ) add A1 diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index e2e8c894f9..a11ab0ad41 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -15,12 +15,12 @@ test_expect_success setup ' git commit -a -m original' test_expect_success "clone and setup child repos" ' - git_clone . one && + git clone . one && cd one && echo >file updated by one && git commit -a -m "updated by one" && cd .. && - git_clone . two && + git clone . two && cd two && git repo-config branch.master.remote one && { @@ -28,7 +28,7 @@ test_expect_success "clone and setup child repos" ' echo "Pull: refs/heads/master:refs/heads/one" } >.git/remotes/one cd .. && - git_clone . three && + git clone . three && cd three && git repo-config branch.master.remote two && git repo-config branch.master.merge refs/heads/one && @@ -74,7 +74,7 @@ test_expect_success 'fetch following tags' ' mkdir four && cd four && - git_init_db && + git init-db && git fetch .. :track && git show-ref --verify refs/tags/anno && diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 66ef92f41f..f841574573 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -17,7 +17,7 @@ test_expect_success setup ' test_expect_success 'pulling into void' ' mkdir cloned && cd cloned && - git_init_db && + git init-db && git pull .. ' diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh index 1913a12d71..041be04f5c 100755 --- a/t/t5600-clone-fail-cleanup.sh +++ b/t/t5600-clone-fail-cleanup.sh @@ -13,7 +13,7 @@ remove the directory before attempting a clone again.' test_expect_failure \ 'clone of non-existent source should fail' \ - 'git_clone foo bar' + 'git-clone foo bar' test_expect_failure \ 'failed clone should not leave a directory' \ @@ -29,11 +29,11 @@ test_create_repo foo # current path not to the target dir test_expect_failure \ 'clone of non-existent (relative to $PWD) source should fail' \ - 'git_clone ../foo baz' + 'git-clone ../foo baz' test_expect_success \ 'clone should work now that source exists' \ - 'git_clone foo bar' + 'git-clone foo bar' test_expect_success \ 'successfull clone must leave the directory' \ diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh index 52dab2d484..dd9caad1c2 100755 --- a/t/t5700-clone-reference.sh +++ b/t/t5700-clone-reference.sh @@ -17,7 +17,7 @@ git commit -m initial' cd "$base_dir" test_expect_success 'preparing second repository' \ -'git_clone A B && cd B && +'git clone A B && cd B && echo second > file2 && git add file2 && git commit -m addition && @@ -27,7 +27,7 @@ git prune' cd "$base_dir" test_expect_success 'cloning with reference' \ -'git_clone -l -s --reference B A C' +'git clone -l -s --reference B A C' cd "$base_dir" diff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh index 3c43554c69..b9f6d96363 100755 --- a/t/t5710-info-alternate.sh +++ b/t/t5710-info-alternate.sh @@ -34,7 +34,7 @@ git prune' cd "$base_dir" test_expect_success 'preparing second repository' \ -'git_clone -l -s A B && cd B && +'git clone -l -s A B && cd B && echo "foo bar" > file2 && git add file2 && git commit -m "next commit" file2 && @@ -44,7 +44,7 @@ git prune' cd "$base_dir" test_expect_success 'preparing third repository' \ -'git_clone -l -s B C && cd C && +'git clone -l -s B C && cd C && echo "Goodbye, cruel world" > file3 && git add file3 && git commit -m "one more" file3 && @@ -54,11 +54,11 @@ git prune' cd "$base_dir" test_expect_failure 'creating too deep nesting' \ -'git_clone -l -s C D && -git_clone -l -s D E && -git_clone -l -s E F && -git_clone -l -s F G && -git_clone -l -s G H && +'git clone -l -s C D && +git clone -l -s D E && +git clone -l -s E F && +git clone -l -s F G && +git clone -l -s G H && cd H && test_valid_repo' diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index ae597e80dd..2f4ff82e14 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -88,7 +88,7 @@ test_expect_success \ test_expect_success "Michael Cassar's test case" ' rm -fr .git papers partA && - git_init_db && + git init-db && mkdir -p papers/unsorted papers/all-papers partA && echo a > papers/unsorted/Thesis.pdf && echo b > partA/outline.txt && @@ -109,7 +109,7 @@ rm -fr papers partA path? test_expect_success "Sergey Vlasov's test case" ' rm -fr .git && - git_init_db && + git init-db && mkdir ab && date >ab.c && date >ab/d && diff --git a/t/test-lib.sh b/t/test-lib.sh index 7e9149751e..ac7be769b4 100755 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -182,16 +182,6 @@ test_create_repo () { cd "$owd" } -# Many tests do init-db and clone but they must be told about the freshly -# built templates. -git_init_db () { - git init-db --template="$GIT_EXEC_PATH/templates/blt/" "$@" -} - -git_clone () { - git clone --template="$GIT_EXEC_PATH/templates/blt/" "$@" -} - test_done () { trap - exit case "$test_failure" in From 8683a45d66967b0969516a2b72cdbf136c2064a2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 19 Dec 2006 09:18:09 +0100 Subject: [PATCH 07/10] Introduce GIT_TEMPLATE_DIR Instead of passing --template explicitely to init-db and clone, you can just set the environment variable GIT_TEMPLATE_DIR. Also make use of it in the tests, to make sure that the templates are copied. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-init-db.c | 7 +++++-- t/test-lib.sh | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/builtin-init-db.c b/builtin-init-db.c index 1d7d15e8d5..c8ed5c2a0b 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -124,8 +124,11 @@ static void copy_templates(const char *git_dir, int len, const char *template_di int template_len; DIR *dir; - if (!template_dir) - template_dir = DEFAULT_GIT_TEMPLATE_DIR; + if (!template_dir) { + template_dir = getenv("GIT_TEMPLATE_DIR"); + if (!template_dir) + template_dir = DEFAULT_GIT_TEMPLATE_DIR; + } strcpy(template_path, template_dir); template_len = strlen(template_path); if (template_path[template_len-1] != '/') { diff --git a/t/test-lib.sh b/t/test-lib.sh index ac7be769b4..f0f9cd6be0 100755 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -208,8 +208,9 @@ test_done () { # t/ subdirectory and are run in trash subdirectory. PATH=$(pwd)/..:$PATH GIT_EXEC_PATH=$(pwd)/.. +GIT_TEMPLATE_DIR=$(pwd)/../templates/blt HOME=$(pwd)/trash -export PATH GIT_EXEC_PATH HOME +export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR HOME GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git export GITPERLLIB From 75c384efb52d0e3eb1e8c2f53668b4066fe6a8d6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 19 Dec 2006 01:50:37 -0800 Subject: [PATCH 08/10] Do not create $GIT_DIR/remotes/ directory anymore. Because we do not use --no-separate-remote anymore, there is no reason to create that directory from the template. t5510 test is updated to test both $GIT_DIR/remotes/ based configuration and $GIT_DIR/config variable (credits to Johannes). Signed-off-by: Junio C Hamano --- t/t5510-fetch.sh | 7 +++---- templates/remotes-- | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 templates/remotes-- diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index a11ab0ad41..90eeeba2a3 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -23,15 +23,14 @@ test_expect_success "clone and setup child repos" ' git clone . two && cd two && git repo-config branch.master.remote one && - { - echo "URL: ../one/.git/" - echo "Pull: refs/heads/master:refs/heads/one" - } >.git/remotes/one + git repo-config remote.one.url ../one/.git/ && + git repo-config remote.one.fetch refs/heads/master:refs/heads/one && cd .. && git clone . three && cd three && git repo-config branch.master.remote two && git repo-config branch.master.merge refs/heads/one && + mkdir -p .git/remotes && { echo "URL: ../two/.git/" echo "Pull: refs/heads/master:refs/heads/two" diff --git a/templates/remotes-- b/templates/remotes-- deleted file mode 100644 index fae88709a6..0000000000 --- a/templates/remotes-- +++ /dev/null @@ -1 +0,0 @@ -: this is just to ensure the directory exists. From d4ebc36c5ee964592303c59260417b758d024c31 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 19 Dec 2006 01:28:15 -0800 Subject: [PATCH 09/10] Use preprocessor constants for environment variable names. We broke the discipline Linus set up to allow compiler help us avoid typos in environment names in the early days of git over time. This defines a handful preprocessor constants for environment variable names used in relatively core parts of the system. I've left out variable names specific to subsystems such as HTTP and SSL as I do not think they are big problems. Signed-off-by: Junio C Hamano --- builtin-init-db.c | 2 +- builtin-repo-config.c | 4 ++-- cache.h | 4 ++++ config.c | 12 ++++++------ exec_cmd.c | 4 ++-- merge-recursive.c | 2 +- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/builtin-init-db.c b/builtin-init-db.c index c8ed5c2a0b..01f366ad0b 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -125,7 +125,7 @@ static void copy_templates(const char *git_dir, int len, const char *template_di DIR *dir; if (!template_dir) { - template_dir = getenv("GIT_TEMPLATE_DIR"); + template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT); if (!template_dir) template_dir = DEFAULT_GIT_TEMPLATE_DIR; } diff --git a/builtin-repo-config.c b/builtin-repo-config.c index a38099a63d..4885930ca4 100644 --- a/builtin-repo-config.c +++ b/builtin-repo-config.c @@ -67,10 +67,10 @@ static int get_value(const char* key_, const char* regex_) char *global = NULL, *repo_config = NULL; const char *local; - local = getenv("GIT_CONFIG"); + local = getenv(CONFIG_ENVIRONMENT); if (!local) { const char *home = getenv("HOME"); - local = getenv("GIT_CONFIG_LOCAL"); + local = getenv(CONFIG_LOCAL_ENVIRONMENT); if (!local) local = repo_config = xstrdup(git_path("config")); if (home) diff --git a/cache.h b/cache.h index 8ad5920d2b..4943056c19 100644 --- a/cache.h +++ b/cache.h @@ -122,6 +122,10 @@ extern int cache_errno; #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY" #define INDEX_ENVIRONMENT "GIT_INDEX_FILE" #define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE" +#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR" +#define CONFIG_ENVIRONMENT "GIT_CONFIG" +#define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL" +#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" extern int is_bare_git_dir(const char *dir); extern const char *get_git_dir(void); diff --git a/config.c b/config.c index 663993fefa..6a4224e98c 100644 --- a/config.c +++ b/config.c @@ -350,10 +350,10 @@ int git_config(config_fn_t fn) * $GIT_CONFIG_LOCAL will make it process it in addition to the * global config file, the same way it would the per-repository * config file otherwise. */ - filename = getenv("GIT_CONFIG"); + filename = getenv(CONFIG_ENVIRONMENT); if (!filename) { home = getenv("HOME"); - filename = getenv("GIT_CONFIG_LOCAL"); + filename = getenv(CONFIG_LOCAL_ENVIRONMENT); if (!filename) filename = repo_config = xstrdup(git_path("config")); } @@ -544,9 +544,9 @@ int git_config_set_multivar(const char* key, const char* value, char* lock_file; const char* last_dot = strrchr(key, '.'); - config_filename = getenv("GIT_CONFIG"); + config_filename = getenv(CONFIG_ENVIRONMENT); if (!config_filename) { - config_filename = getenv("GIT_CONFIG_LOCAL"); + config_filename = getenv(CONFIG_LOCAL_ENVIRONMENT); if (!config_filename) config_filename = git_path("config"); } @@ -754,9 +754,9 @@ int git_config_rename_section(const char *old_name, const char *new_name) int out_fd; char buf[1024]; - config_filename = getenv("GIT_CONFIG"); + config_filename = getenv(CONFIG_ENVIRONMENT); if (!config_filename) { - config_filename = getenv("GIT_CONFIG_LOCAL"); + config_filename = getenv(CONFIG_LOCAL_ENVIRONMENT); if (!config_filename) config_filename = git_path("config"); } diff --git a/exec_cmd.c b/exec_cmd.c index 5d6a1247b4..3996bce33f 100644 --- a/exec_cmd.c +++ b/exec_cmd.c @@ -21,7 +21,7 @@ const char *git_exec_path(void) if (current_exec_path) return current_exec_path; - env = getenv("GIT_EXEC_PATH"); + env = getenv(EXEC_PATH_ENVIRONMENT); if (env && *env) { return env; } @@ -35,7 +35,7 @@ int execv_git_cmd(const char **argv) char git_command[PATH_MAX + 1]; int i; const char *paths[] = { current_exec_path, - getenv("GIT_EXEC_PATH"), + getenv(EXEC_PATH_ENVIRONMENT), builtin_exec_path }; for (i = 0; i < ARRAY_SIZE(paths); ++i) { diff --git a/merge-recursive.c b/merge-recursive.c index 6dd6e2e5af..ae4dcfbe5b 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1279,7 +1279,7 @@ int main(int argc, char *argv[]) struct commit *result, *h1, *h2; git_config(git_default_config); /* core.filemode */ - original_index_file = getenv("GIT_INDEX_FILE"); + original_index_file = getenv(INDEX_ENVIRONMENT); if (!original_index_file) original_index_file = xstrdup(git_path("index")); From 4363dfbe3d2f3fe3a4bd0fa7e9b22a14532c6cdb Mon Sep 17 00:00:00 2001 From: Josef Weidendorfer Date: Tue, 19 Dec 2006 01:39:07 +0100 Subject: [PATCH 10/10] Move "no merge candidate" warning into git-pull The warning triggered even when running "git fetch" only when resulting .git/FETCH_HEAD only contained branches marked as 'not-for-merge'. Signed-off-by: Josef Weidendorfer Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 10 ---------- git-pull.sh | 4 ++++ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/git-parse-remote.sh b/git-parse-remote.sh index 11c4aba244..ea7511e8a0 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -132,7 +132,6 @@ canon_refs_list_for_fetch () { # or the first one otherwise; add prefix . to the rest # to prevent the secondary branches to be merged by default. merge_branches= - found_mergeref= curr_branch= if test "$1" = "-d" then @@ -172,10 +171,6 @@ canon_refs_list_for_fetch () { dot_prefix= && break done fi - if test -z $dot_prefix - then - found_mergeref=true - fi case "$remote" in '') remote=HEAD ;; refs/heads/* | refs/tags/* | refs/remotes/*) ;; @@ -196,11 +191,6 @@ canon_refs_list_for_fetch () { fi echo "${dot_prefix}${force}${remote}:${local}" done - if test -z "$found_mergeref" -a "$curr_branch" - then - echo >&2 "Warning: No merge candidate found because value of config option - \"branch.${curr_branch}.merge\" does not match any remote branch fetched." - fi } # Returns list of src: (no store), or src:dst (store) diff --git a/git-pull.sh b/git-pull.sh index e23beb685d..1703091bbb 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -76,6 +76,10 @@ merge_head=$(sed -e '/ not-for-merge /d' \ case "$merge_head" in '') + curr_branch=$(git-symbolic-ref HEAD | \ + sed -e 's|^refs/heads/||') + echo >&2 "Warning: No merge candidate found because value of config option + \"branch.${curr_branch}.merge\" does not match any remote branch fetched." echo >&2 "No changes." exit 0 ;;