git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] t1020-subdirectory: test alias expansion in a subdirectory
@ 2010-11-08  8:32 Michael J Gruber
  2010-11-08 10:20 ` Nguyen Thai Ngoc Duy
  2010-11-08 10:23 ` [PATCH] t0001: test git init when run via an alias Nguyễn Thái Ngọc Duy
  0 siblings, 2 replies; 5+ messages in thread
From: Michael J Gruber @ 2010-11-08  8:32 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy, Junio C Hamano

Add a test for alias expansion in a subdirectory of the worktree.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>

---
    65f3a9e (Remove all logic from get_git_work_tree(), 2010-11-01) breaks this test,
    which is why I am adding it.
    
    In fact, we don't really have tests for alias expansion at all, but that's a different issue.

 t/t1020-subdirectory.sh |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh
index a3ac338..1fd187c 100755
--- a/t/t1020-subdirectory.sh
+++ b/t/t1020-subdirectory.sh
@@ -110,6 +110,14 @@ test_expect_success 'read-tree' '
 	)
 '
 
+test_expect_success 'alias expansion' '
+	(
+		git config alias.ss status &&
+		cd dir &&
+		git status &&
+		git ss
+	)
+'
 test_expect_success 'no file/rev ambiguity check inside .git' '
 	git commit -a -m 1 &&
 	(
-- 
1.7.3.2.193.g78bbb

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] t1020-subdirectory: test alias expansion in a subdirectory
  2010-11-08  8:32 [PATCH] t1020-subdirectory: test alias expansion in a subdirectory Michael J Gruber
@ 2010-11-08 10:20 ` Nguyen Thai Ngoc Duy
  2010-11-08 20:25   ` Junio C Hamano
  2010-11-08 10:23 ` [PATCH] t0001: test git init when run via an alias Nguyễn Thái Ngọc Duy
  1 sibling, 1 reply; 5+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2010-11-08 10:20 UTC (permalink / raw)
  To: Michael J Gruber; +Cc: git, Junio C Hamano

On Mon, Nov 08, 2010 at 09:32:03AM +0100, Michael J Gruber wrote:
> Add a test for alias expansion in a subdirectory of the worktree.
> 
> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
> 
> ---
>     65f3a9e (Remove all logic from get_git_work_tree(), 2010-11-01) breaks this test,
>     which is why I am adding it.

How about squashing this in?

--8<--
Subject: Allow set_git_work_tree() to be called more than once

Usually one of the setup functions is called once. However alias
handling code needs to look ahead in $GIT_DIR/config for aliases. So
set_git_work_tree() may be called twice: once when alias is searched,
once when the actual command is run.

Loosen the condition and let it through. We can stricten it back when
alias handling is fixed.
---
diff --git a/environment.c b/environment.c
index 6db00da..f0d0b07 100644
--- a/environment.c
+++ b/environment.c
@@ -128,8 +128,6 @@ const char *get_git_dir(void)
 	return git_dir;
 }
 
-static int git_work_tree_initialized;
-
 /*
  * Note.  This works only before you used a work tree.  This was added
  * primarily to support git-clone to work in a new repository it just
@@ -137,9 +135,7 @@ static int git_work_tree_initialized;
  */
 void set_git_work_tree(const char *new_work_tree)
 {
-	if (git_work_tree_initialized)
-		die("internal error: work tree has already been set");
-	git_work_tree_initialized = 1;
+	free(work_tree);
 	work_tree = xstrdup(make_absolute_path(new_work_tree));
 }
 
--8<--
-- 
Duy

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] t0001: test git init when run via an alias
  2010-11-08  8:32 [PATCH] t1020-subdirectory: test alias expansion in a subdirectory Michael J Gruber
  2010-11-08 10:20 ` Nguyen Thai Ngoc Duy
@ 2010-11-08 10:23 ` Nguyễn Thái Ngọc Duy
  1 sibling, 0 replies; 5+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-11-08 10:23 UTC (permalink / raw)
  To: git, Junio C Hamano, git
  Cc: Jonathan Nieder, Nguyễn Thái Ngọc Duy

From: Jonathan Nieder <jrnieder@gmail.com>

Add some tests to document the correct behavior of (possibly aliased)
init when run within and outside a git directory.

If I set up a simple git alias “quietinit = init --quiet”, usually it
will work just like ‘git init --quiet’.

There are some differences, unfortunately, since in the process of
checking for aliases, git has to look for a .git/config file.  If ‘git
quietinit’ is run from a subdirectory of an existing git repository,
that repository’s configuration will affect the configuration of the
new repository.  In particular, the new repository can inherit
bogus values for core.bare and core.worktree.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 >     In fact, we don't really have tests for alias expansion at all, but that's a different issue.

 It reminds me of this old patch. Let's push them together.

 t/t0001-init.sh |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 7fe8883..28c1858 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -33,6 +33,62 @@ test_expect_success 'plain' '
 	check_config plain/.git false unset
 '
 
+test_expect_success 'plain nested in bare' '
+	(
+		unset GIT_DIR GIT_WORK_TREE &&
+		git init --bare bare-ancestor.git &&
+		cd bare-ancestor.git &&
+		mkdir plain-nested &&
+		cd plain-nested &&
+		git init
+	) &&
+	check_config bare-ancestor.git/plain-nested/.git false unset
+'
+
+test_expect_success 'plain through aliased command, outside any git repo' '
+	(
+		unset GIT_DIR GIT_WORK_TREE GIT_CONFIG_NOGLOBAL &&
+		HOME=$(pwd)/alias-config &&
+		export HOME &&
+		mkdir alias-config &&
+		echo "[alias] aliasedinit = init" >alias-config/.gitconfig &&
+
+		GIT_CEILING_DIRECTORIES=$(pwd) &&
+		export GIT_CEILING_DIRECTORIES &&
+
+		mkdir plain-aliased &&
+		cd plain-aliased &&
+		git aliasedinit
+	) &&
+	check_config plain-aliased/.git false unset
+'
+
+test_expect_success 'plain nested through aliased command' '
+	(
+		unset GIT_DIR GIT_WORK_TREE &&
+		git init plain-ancestor-aliased &&
+		cd plain-ancestor-aliased &&
+		echo "[alias] aliasedinit = init" >>.git/config &&
+		mkdir plain-nested &&
+		cd plain-nested &&
+		git aliasedinit
+	) &&
+	check_config plain-ancestor-aliased/plain-nested/.git false unset
+'
+
+test_expect_failure 'plain nested in bare through aliased command' '
+	(
+		unset GIT_DIR GIT_WORK_TREE &&
+		git init --bare bare-ancestor-aliased.git &&
+		cd bare-ancestor-aliased.git &&
+		echo "[alias] aliasedinit = init" >>config &&
+		mkdir plain-nested &&
+		cd plain-nested &&
+		git aliasedinit
+	) &&
+	check_config bare-ancestor-aliased.git/plain-nested/.git false unset
+'
+
 test_expect_success 'plain with GIT_WORK_TREE' '
 	if (
 		unset GIT_DIR
-- 
1.7.3.2.210.g045198

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] t1020-subdirectory: test alias expansion in a subdirectory
  2010-11-08 10:20 ` Nguyen Thai Ngoc Duy
@ 2010-11-08 20:25   ` Junio C Hamano
  2010-11-09  1:29     ` Nguyen Thai Ngoc Duy
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2010-11-08 20:25 UTC (permalink / raw)
  To: Nguyen Thai Ngoc Duy; +Cc: Michael J Gruber, git

Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:

> On Mon, Nov 08, 2010 at 09:32:03AM +0100, Michael J Gruber wrote:
>> Add a test for alias expansion in a subdirectory of the worktree.
>> 
>> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
>> 
>> ---
>>     65f3a9e (Remove all logic from get_git_work_tree(), 2010-11-01) breaks this test,
>>     which is why I am adding it.
>
> How about squashing this in?
>
> --8<--
> Subject: Allow set_git_work_tree() to be called more than once
>
> Usually one of the setup functions is called once. However alias
> handling code needs to look ahead in $GIT_DIR/config for aliases. So
> set_git_work_tree() may be called twice: once when alias is searched,
> once when the actual command is run.
>
> Loosen the condition and let it through. We can stricten it back when
> alias handling is fixed.

Sounds like sweeping something under rug.  

Without this hack, alias does not work, but if your plan is to rework this
part right when alias is fixed, then what's the point of loosening it?
Either way your alias is broken, no?

Shouldn't it at least make sure that the function is giving a consistent
picture to the outside world between the time it was called for the first
time and the second time?  E.g.  the second time around new-work-tree must
be the same as whatever was given the first time, or something.

> ---
> diff --git a/environment.c b/environment.c
> index 6db00da..f0d0b07 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -128,8 +128,6 @@ const char *get_git_dir(void)
>  	return git_dir;
>  }
>  
> -static int git_work_tree_initialized;
> -
>  /*
>   * Note.  This works only before you used a work tree.  This was added
>   * primarily to support git-clone to work in a new repository it just
> @@ -137,9 +135,7 @@ static int git_work_tree_initialized;
>   */
>  void set_git_work_tree(const char *new_work_tree)
>  {
> -	if (git_work_tree_initialized)
> -		die("internal error: work tree has already been set");
> -	git_work_tree_initialized = 1;
> +	free(work_tree);
>  	work_tree = xstrdup(make_absolute_path(new_work_tree));
>  }
>  
> --8<--
> -- 
> Duy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] t1020-subdirectory: test alias expansion in a subdirectory
  2010-11-08 20:25   ` Junio C Hamano
@ 2010-11-09  1:29     ` Nguyen Thai Ngoc Duy
  0 siblings, 0 replies; 5+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2010-11-09  1:29 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Michael J Gruber, git

On Tue, Nov 9, 2010 at 3:25 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
>
>> On Mon, Nov 08, 2010 at 09:32:03AM +0100, Michael J Gruber wrote:
>>> Add a test for alias expansion in a subdirectory of the worktree.
>>>
>>> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
>>>
>>> ---
>>>     65f3a9e (Remove all logic from get_git_work_tree(), 2010-11-01) breaks this test,
>>>     which is why I am adding it.
>>
>> How about squashing this in?
>>
>> --8<--
>> Subject: Allow set_git_work_tree() to be called more than once
>>
>> Usually one of the setup functions is called once. However alias
>> handling code needs to look ahead in $GIT_DIR/config for aliases. So
>> set_git_work_tree() may be called twice: once when alias is searched,
>> once when the actual command is run.
>>
>> Loosen the condition and let it through. We can stricten it back when
>> alias handling is fixed.
>
> Sounds like sweeping something under rug.
>
> Without this hack, alias does not work, but if your plan is to rework this
> part right when alias is fixed, then what's the point of loosening it?
> Either way your alias is broken, no?
>
> Shouldn't it at least make sure that the function is giving a consistent
> picture to the outside world between the time it was called for the first
> time and the second time?  E.g.  the second time around new-work-tree must
> be the same as whatever was given the first time, or something.

Right. Will do that.
-- 
Duy

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-11-09  1:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-08  8:32 [PATCH] t1020-subdirectory: test alias expansion in a subdirectory Michael J Gruber
2010-11-08 10:20 ` Nguyen Thai Ngoc Duy
2010-11-08 20:25   ` Junio C Hamano
2010-11-09  1:29     ` Nguyen Thai Ngoc Duy
2010-11-08 10:23 ` [PATCH] t0001: test git init when run via an alias Nguyễn Thái Ngọc Duy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).