Repository version check is only performed when
setup_git_directory() is called. This makes sure
setup_git_directory_gently() does the check too.
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
My worktree work still not done yet, so push this first.
setup.c | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
@@ -367,7 +374,6 @@ int check_repository_format(void)constchar*setup_git_directory(void){constchar*retval=setup_git_directory_gently(NULL);-check_repository_format();/* If the work tree is not the default one, recompute prefix */if(inside_work_tree<0){
Why not move this check before the if? Other than that, ACK.
If so it would be called twice if work_tree_env is not set.
Well, I would have left the original
if (!work_tree_env)
return set_work_tree(gitdirenv);
alone...
If that is not possible, it might be good to add a comment as to why.
Ciao,
Dscho
Why not move this check before the if? Other than that, ACK.
If so it would be called twice if work_tree_env is not set.
Well, I would have left the original
if (!work_tree_env)
return set_work_tree(gitdirenv);
alone...
If that is not possible, it might be good to add a comment as to why.
I did, and the tests failed. I also added a comment "config may
override worktree". set_work_tree() will reset git_work_tree_cfg but
the correct behaviour is config takes precedence (from comment of
set_work_tree). The comment is clearly not clear enough. Maybe this?
+ if (!work_tree_env) {
+ retval = set_work_tree(gitdirenv);
+ /* config may override worktree (see
set_work_tree comment) */
+ check_repository_format();
+ return retval;
+ }
On Dec 1, 2007 9:36 AM, Junio C Hamano [off-list ref] wrote:
Johannes Schindelin [off-list ref] writes:
quoted
On Thu, 29 Nov 2007, Nguyen Thai Ngoc Duy wrote:
quoted
The comment is clearly not clear enough. Maybe this?
+ if (!work_tree_env) {
+ retval = set_work_tree(gitdirenv);
+ /* config may override worktree (see
set_work_tree comment) */
+ check_repository_format();
+ return retval;
+ }
Perfect. Please make it so, and add my ACK.
Looks sensible, but can this be accompanied with a trivial test to
demonstrate the existing breakage?
How can I reliably check setup_git_directory_gently()? I can pick one
command that uses setup_git_directory_gently(). But commands change.
Once they turn to setup_git_directory(), the test will no longer be
valid.
--
Duy
This pushes check_repository_format() (actually _gently() version)
to setup_git_directory_gently() in order to prevent from
using unsupported repositories.
New setup_git_directory_gently()'s behaviour is stop searching
for a valid gitdir and return as if there is no gitdir if a
unsupported repository is found. Warning will be thrown in these
cases.
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
Another round. Test added. Behaviour changed to make it tolerate
unsupported repos as much as possible.
setup.c | 37 ++++++++++++++++++++++++++++++-------
t/t1302-repo-version.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+), 7 deletions(-)
create mode 100755 t/t1302-repo-version.sh
@@ -0,0 +1,46 @@+#!/bin/sh+#+# Copyright (c) 2007 Nguyễn Thái Ngọc Duy+#++test_description='Test repository version check'++../test-lib.sh++cat>test.patch<<EOF+diff--gita/test.txtb/test.txt+newfilemode100644+---/dev/null++++b/test.txt+@@-0,0+1@@++123+EOF++test_create_repo"test"+test_create_repo"test2"++GIT_CONFIG=test2/.git/configgitconfigcore.repositoryformatversion99||exit1++test_expect_success'gitdir selection on normal repos''+(test"$(gitconfigcore.repositoryformatversion)"=0&&+cdtest&&+test"$(gitconfigcore.repositoryformatversion)"=0)'++# Make sure it would stop at test2, not trash+test_expect_success'gitdir selection on unsupported repo''+(cdtest2&&+test"$(gitconfigcore.repositoryformatversion)"=99)'++test_expect_success'gitdir not required mode''+(gitapply--stattest.patch&&+cdtest&&gitapply--stat../test.patch&&+cd../test2&&gitapply--stat../test.patch)'++test_expect_success'gitdir required mode on normal repos''+(gitapply--check--indextest.patch&&+cdtest&&gitapply--check--index../test.patch)'++test_expect_failure'gitdir required mode on unsupported repo''+(cdtest2&&gitapply--check--index../test.patch)'++test_done
This part better be as follow (patch may be damaged as I'm editing it in gmail)
@@ -287,6 +310,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
if (!work_tree_env)
inside_work_tree = 0;
setenv(GIT_DIR_ENVIRONMENT, ".", 1);
+ check_repository_format_gently(nongit_ok);
return NULL;
}
chdir("..");
--
Duy