Skip to contentSkip to conversation

git: make "git -C '' <cmd>" not to barf

PATCH Superseded Karthik Nayak 3 participants 4 messages Jun 15, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git: make "git -C '' <cmd>" not to barf

now it works like cd "" which silently succeeds

---
 git.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
git.c +3 -1
index 8c7ee9c..f4c2285 100644
@@ -204,7 +204,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 				fprintf(stderr, "No directory given for -C.\n" );
 				usage(git_usage_string);
 			}
-			if (chdir((*argv)[1]))
+			if (*(*argv)[1] == 0)
+				; /* Ignore "" as a directory */
+			else if (chdir((*argv)[1]))
 				die_errno("Cannot change to '%s'", (*argv)[1]);
 			if (envchanged)
 				*envchanged = 1;
Signature · 1 line
2.3.1.167.g7f4ba4b.dirty
#1 lore raw
Quoted 1 line · Karthik Nayak

now it works like cd "" which silently succeeds

Missing "." at end of sentence.

Quoted 1 line
 git.c | 4 +++-

That would probably also deserve a test.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#2 lore raw
Quoted 5 lines · Matthieu Moy
Quoted 1 line · Karthik Nayak

now it works like cd "" which silently succeeds

Missing "." at end of sentence.

And lack of capitalization at the beginning.

More importantly, lack of justification--why is it a good idea to make "it works like cd ''" in the first place?

Quoted 4 lines
Quoted 2 lines
 git.c | 4 +++-

That would probably also deserve a test.

Another "huh?" I had on the actual code was if this counts as "envchanged", if you are not actually changing the directory at all.

Is this meant as a "micro" for GSoC, by the way?

#3 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Matthieu Moy
Quoted 1 line · Karthik Nayak

now it works like cd "" which silently succeeds

Missing "." at end of sentence.

And lack of capitalization at the beginning.

Yes, noted, Will fix with next patch.

Quoted 8 lines

More importantly, lack of justification--why is it a good idea to make "it works like cd ''" in the first place?

Quoted 4 lines
Quoted 2 lines
 git.c | 4 +++-

That would probably also deserve a test.

Will include a patch with next patch version.

Quoted 6 lines

Another "huh?" I had on the actual code was if this counts as "envchanged", if
you are not actually changing the directory at all.

Is this meant as a "micro" for GSoC, by the way?

Yes, it's meant for GSoC.
I did overlook that. Will fix in next patch version. Thanks for your suggestions