threads / patch / 25667

patcht1020-subdirectory: test alias expansion in a subdirectory

Subject: [PATCH] t1020-subdirectory: test alias expansion in a subdirectory

## tl;dr

5 messages between Nov 8, 2010 and Nov 9, 2010. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Michael J Gruber· Nov 8, 2010, 08:32 UTC · lore
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(-)
Show changes to t/t1020-subdirectory.sh +8 −0
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
Nguyen Thai Ngoc Duy· Nov 8, 2010, 10:20 UTC · re: Michael J Gruber · lore

Re: [PATCH] t1020-subdirectory: test alias expansion in a subdirectory

On Mon, Nov 08, 2010 at 09:32:03AM +0100, Michael J Gruber wrote:
Show 7 quoted lines
> 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. ---

Show changes to environment.c +1 −6
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
Junio C Hamano· Nov 8, 2010, 20:25 UTC · re: Nguyen Thai Ngoc Duy · lore

Re: [PATCH] t1020-subdirectory: test alias expansion in a subdirectory

Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
Show 21 quoted lines
> 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.

Show 28 quoted lines
> ---
> 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
Nguyen Thai Ngoc Duy· Nov 9, 2010, 01:29 UTC · re: Junio C Hamano · lore

Re: [PATCH] t1020-subdirectory: test alias expansion in a subdirectory

On Tue, Nov 9, 2010 at 3:25 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 34 quoted lines
> 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
Nguyễn Thái Ngọc Duy· Nov 8, 2010, 10:23 UTC · re: Michael J Gruber · lore

[PATCH] t0001: test git init when run via an alias

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(-)
Show changes to t/t0001-init.sh +56 −0
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

← back to recent threads