Skip to contentSkip to conversation

git.c: support "!!" aliases that do not move cwd

PATCH/RFC Nguyễn Thái Ngọc Duy 8 participants 34 messages Oct 6, 2016 – Oct 26, 2016

lore
Share & tools
lore
#0 lore raw

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make handling path arguments hard because they are relative to the original cwd. We set GIT_PREFIX to work around it, but I still think it's more natural to keep cwd where it is.

We have a way to do that now after 441981b (git: simplify environment save/restore logic - 2016-01-26). It's just a matter of choosing the right syntax. I'm going with '!!'. I'm not very happy with it. But I do like this type of alias.

---
 git.c | 4 ++++
 1 file changed, 4 insertions(+)
git.c +4 -0
index 296857a..4c1dcf4 100644
@@ -252,6 +252,10 @@ static int handle_alias(int *argcp, const char ***argv)
 
 			alias_string++;
 			commit_pager_choice();
+			if (*alias_string == '!') {
+				keep_cwd = 0;
+				alias_string++;
+			}
 			restore_env(keep_cwd);
 
 			child.use_shell = 1;
Signature · 1 line
2.8.2.524.g6ff3d78
#1 lore raw
Quoted 8 lines · Nguyễn Thái Ngọc Duy

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make handling path arguments hard because they are relative to the original cwd. We set GIT_PREFIX to work around it, but I still think it's more natural to keep cwd where it is.

Quoted 4 lines

We have a way to do that now after 441981b (git: simplify environment save/restore logic - 2016-01-26). It's just a matter of choosing the right syntax. I'm going with '!!'. I'm not very happy with it. But I do like this type of alias.

I do not know why you are not happy with the syntax, but I personally think it brilliant, both the idea and the preliminary clean-up that made this possible with a simple patch like this.

Quoted 20 lines
---
 git.c | 4 ++++
 1 file changed, 4 insertions(+)
git.c +4 -0
index 296857a..4c1dcf4 100644
@@ -252,6 +252,10 @@ static int handle_alias(int *argcp, const char ***argv)
 
 			alias_string++;
 			commit_pager_choice();
+			if (*alias_string == '!') {
+				keep_cwd = 0;
+				alias_string++;
+			}
 			restore_env(keep_cwd);
 
 			child.use_shell = 1;
#32 lore raw
In reply to Nguyễn Thái Ngọc Duy
Quoted 8 lines · Nguyễn Thái Ngọc Duy

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make handling path arguments hard because they are relative to the original cwd. We set GIT_PREFIX to work around it, but I still think it's more natural to keep cwd where it is.

Quoted 4 lines

We have a way to do that now after 441981b (git: simplify environment save/restore logic - 2016-01-26). It's just a matter of choosing the right syntax. I'm going with '!!'. I'm not very happy with it. But I do like this type of alias.

Hmm. I wonder if any commands will be fooled by not being moved to GIT_WORK_TREE. I know that there is a bug already in this case:

export HOME=$PWD

for i in one two; do
git init $i &&
(cd $i &&
echo "* diff=$i" >.gitattributes &&
git add . &&
git commit -m $i) &&
git config --global diff.$i.textconv "sed s/^/$i:/"
done

  cd two &&
  git --git-dir=$(pwd)/../one/.git --work-tree=$(pwd)/../one show

This shows the contents of repo one using the .gitattributes from repo two. I am not sure if the bug is that when GIT_WORK_TREE is set, git-show doesn't position itself at the toplevel of that tree, or if the attributes machinery should be more careful about looking up paths in the work-tree versus the current directory.

This bug is tangential to your patch (it has nothing to do with aliases, and should be fixed regardless). But I wonder if your "!!" aliases will expose this bug more frequently.

-Peff

PS I think your "!!" syntax conflicts with something like:

    git -c alias.has-changes="!! git diff --quiet' has-changes

I don't know if that is worth worrying about or not. I also notice that using "!!git diff" with no space seems broken, as it seems to skip using the shell. I wonder if that is a bug in run-command.

#33 lore raw
Quoted 7 lines · Jeff King

PS I think your "!!" syntax conflicts with something like:

    git -c alias.has-changes='!! git diff --quiet' has-changes

I don't know if that is worth worrying about or not. I also notice that using "!!git diff" with no space seems broken, as it seems to skip using the shell. I wonder if that is a bug in run-command.

Nevermind this last bit. It is the shell that is complaining (rightfully) about "!git"; the error message is just confusing because it mentions $0, which contains the whole script:

  $ git -c alias.has-changes='!!git diff --quiet' has-changes
  !git diff --quiet: 1: !git diff --quiet: !git: not found

The "!! git diff" syntax sill has the conflict I mentioned (though note I screwed up the quotes in what I wrote above).

-Peff

#2 lore raw
In reply to Junio C Hamano

Hi Junio,

Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Nguyễn Thái Ngọc Duy

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make handling path arguments hard because they are relative to the original cwd. We set GIT_PREFIX to work around it, but I still think it's more natural to keep cwd where it is.

Quoted 8 lines
Quoted 4 lines

We have a way to do that now after 441981b (git: simplify environment save/restore logic - 2016-01-26). It's just a matter of choosing the right syntax. I'm going with '!!'. I'm not very happy with it. But I do like this type of alias.

I do not know why you are not happy with the syntax, but I personally think it brilliant, both the idea and the preliminary clean-up that made this possible with a simple patch like this.

I guess he is not happy with it because "!!" is quite unintuitive a construct. I know that *I* would have been puzzled by it, asking "What the heck does this do?".

Ciao,
Dscho

author
#3 lore raw
Quoted 19 lines · Johannes Schindelin

Hi Junio,

Quoted 15 lines · Junio C Hamano
Quoted 12 lines · Nguyễn Thái Ngọc Duy

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make handling path arguments hard because they are relative to the original cwd. We set GIT_PREFIX to work around it, but I still think it's more natural to keep cwd where it is.

We have a way to do that now after 441981b (git: simplify environment save/restore logic - 2016-01-26). It's just a matter of choosing the right syntax. I'm going with '!!'. I'm not very happy with it. But I do like this type of alias.

Quoted 7 lines
Quoted 3 lines

I do not know why you are not happy with the syntax, but I personally think it brilliant, both the idea and the preliminary clean-up that made this possible with a simple patch like this.

I guess he is not happy with it because "!!" is quite unintuitive a construct. I know that *I* would have been puzzled by it, asking "What the heck does this do?".

Yep. And I wouldn't want to set a tradition for the next alias type '!!!'. There's no good choice to represent a new alias type with a leading symbol. This just occurred to me, however, what do you think about a new config group for it? With can have something like externalAlias.* (or some other name) that lives in parallel with alias.*. Then we don't need '!' (or '!!') at all.

Signature · 1 line
Duy
author
#5 lore raw
In reply to Matthieu Moy
Quoted 45 lines · Matthieu Moy
Quoted 36 lines · Duy Nguyen
Quoted 25 lines · Johannes Schindelin

Hi Junio,

Quoted 21 lines · Junio C Hamano
Quoted 18 lines · Nguyễn Thái Ngọc Duy

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make
handling path arguments hard because they are relative to the original
cwd. We set GIT_PREFIX to work around it, but I still think it's more
natural to keep cwd where it is.

We have a way to do that now after 441981b (git: simplify environment
save/restore logic - 2016-01-26). It's just a matter of choosing the
right syntax. I'm going with '!!'. I'm not very happy with it. But I
do like this type of alias.

Quoted 8 lines
Quoted 3 lines

I do not know why you are not happy with the syntax, but I personally think it brilliant, both the idea and the preliminary clean-up that made this possible with a simple patch like this.

I guess he is not happy with it because "!!" is quite unintuitive a construct. I know that *I* would have been puzzled by it, asking "What the
heck does this do?".

Quoted 6 lines

Yep. And I wouldn't want to set a tradition for the next alias type '!!!'. There's no good choice to represent a new alias type with a leading symbol. This just occurred to me, however, what do you think about a new config group for it? With can have something like externalAlias.* (or some other name) that lives in parallel with alias.*. Then we don't need '!' (or '!!') at all.

Quoted 3 lines

Another possibility: !(nocd), which leaves room
for !(keyword1,keyword2,...) if needed later. Also, it is consistent with the :(word) syntax of pathspecs.

This seems to solve my problem nicely.

Signature · 1 line
Duy
#4 lore raw
In reply to Duy Nguyen
Quoted 36 lines · Duy Nguyen
Quoted 25 lines · Johannes Schindelin

Hi Junio,

Quoted 21 lines · Junio C Hamano
Quoted 18 lines · Nguyễn Thái Ngọc Duy

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make
handling path arguments hard because they are relative to the original
cwd. We set GIT_PREFIX to work around it, but I still think it's more
natural to keep cwd where it is.

We have a way to do that now after 441981b (git: simplify environment
save/restore logic - 2016-01-26). It's just a matter of choosing the
right syntax. I'm going with '!!'. I'm not very happy with it. But I
do like this type of alias.

Quoted 8 lines
Quoted 3 lines

I do not know why you are not happy with the syntax, but I personally think it brilliant, both the idea and the preliminary clean-up that made this possible with a simple patch like this.

I guess he is not happy with it because "!!" is quite unintuitive a construct. I know that *I* would have been puzzled by it, asking "What the
heck does this do?".

Quoted 6 lines

Yep. And I wouldn't want to set a tradition for the next alias type '!!!'. There's no good choice to represent a new alias type with a leading symbol. This just occurred to me, however, what do you think about a new config group for it? With can have something like externalAlias.* (or some other name) that lives in parallel with alias.*. Then we don't need '!' (or '!!') at all.

Another possibility: !(nocd), which leaves room
for !(keyword1,keyword2,...) if needed later. Also, it is consistent with the :(word) syntax of pathspecs.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#26 lore raw
In reply to Johannes Schindelin

Hello, Johannes

W dniu 07.10.2016 o 13:20, Johannes Schindelin pisze:

Quoted 16 lines · Junio C Hamano
Quoted 15 lines
Quoted 12 lines · Nguyễn Thái Ngọc Duy

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make handling path arguments hard because they are relative to the original cwd. We set GIT_PREFIX to work around it, but I still think it's more natural to keep cwd where it is.

We have a way to do that now after 441981b (git: simplify environment save/restore logic - 2016-01-26). It's just a matter of choosing the right syntax. I'm going with '!!'. I'm not very happy with it. But I do like this type of alias.

Quoted 7 lines
Quoted 3 lines

I do not know why you are not happy with the syntax, but I personally think it brilliant, both the idea and the preliminary clean-up that made this possible with a simple patch like this.

I guess he is not happy with it because "!!" is quite unintuitive a construct. I know that *I* would have been puzzled by it, asking "What the heck does this do?".

Well, "!" as a prefix is not intuitive either.

Perhaps "!.", because "." is current directory, and the "." command (that is, alias to "source") doesn't make sense in git aliases.

Note that we would have to teach git completion about new syntax; or new configuration variable if we go that route.

Signature · 1 line
Jakub Narębski
#8 lore raw
In reply to Duy Nguyen

Hi Duy,

Quoted 28 lines · Duy Nguyen
Quoted 18 lines · Johannes Schindelin
Quoted 15 lines · Junio C Hamano
Quoted 12 lines · Nguyễn Thái Ngọc Duy

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make handling path arguments hard because they are relative to the original cwd. We set GIT_PREFIX to work around it, but I still think it's more natural to keep cwd where it is.

We have a way to do that now after 441981b (git: simplify environment save/restore logic - 2016-01-26). It's just a matter of choosing the right syntax. I'm going with '!!'. I'm not very happy with it. But I do like this type of alias.

Quoted 7 lines
Quoted 3 lines

I do not know why you are not happy with the syntax, but I personally think it brilliant, both the idea and the preliminary clean-up that made this possible with a simple patch like this.

I guess he is not happy with it because "!!" is quite unintuitive a construct. I know that *I* would have been puzzled by it, asking "What the heck does this do?".

Quoted 6 lines

Yep. And I wouldn't want to set a tradition for the next alias type '!!!'. There's no good choice to represent a new alias type with a leading symbol. This just occurred to me, however, what do you think about a new config group for it? With can have something like externalAlias.* (or some other name) that lives in parallel with alias.*. Then we don't need '!' (or '!!') at all.

But what would the precedence be? externalAlias.xyz wins over alias.xyz?

And we still would need '!' support: tons of people (including myself) rely on it.

Possibly a better idea would be to use *another* special symbol, one that makes intuitive sense as a modifier, such as:

[alias]
# This works as before
xyz = !pwd
# As does this
stat = -p status
# This, however, is different:
duy = (nocd)!pwd

This is backwards compatible as "(" is not a part of any Git command, nor of a valid alias, nor is it commonly used as part of a git-* executable/script.

It is also kind of a bit more intuitive, I'd wager, and it is also extensible to future options we may want to introduce.

Ciao,
Dscho

#6 lore raw
In reply to Matthieu Moy

Hi Matthieu,

Quoted 45 lines · Matthieu Moy
Quoted 36 lines · Duy Nguyen
Quoted 25 lines · Johannes Schindelin

Hi Junio,

Quoted 21 lines · Junio C Hamano
Quoted 18 lines · Nguyễn Thái Ngọc Duy

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make
handling path arguments hard because they are relative to the original
cwd. We set GIT_PREFIX to work around it, but I still think it's more
natural to keep cwd where it is.

We have a way to do that now after 441981b (git: simplify environment
save/restore logic - 2016-01-26). It's just a matter of choosing the
right syntax. I'm going with '!!'. I'm not very happy with it. But I
do like this type of alias.

Quoted 8 lines
Quoted 3 lines

I do not know why you are not happy with the syntax, but I personally think it brilliant, both the idea and the preliminary clean-up that made this possible with a simple patch like this.

I guess he is not happy with it because "!!" is quite unintuitive a construct. I know that *I* would have been puzzled by it, asking "What the
heck does this do?".

Quoted 6 lines

Yep. And I wouldn't want to set a tradition for the next alias type '!!!'. There's no good choice to represent a new alias type with a leading symbol. This just occurred to me, however, what do you think about a new config group for it? With can have something like externalAlias.* (or some other name) that lives in parallel with alias.*. Then we don't need '!' (or '!!') at all.

Quoted 3 lines

Another possibility: !(nocd), which leaves room
for !(keyword1,keyword2,...) if needed later. Also, it is consistent with the :(word) syntax of pathspecs.

But is this backwards-compatible? Don't we execute everything that comes after the exclamation mark as a command-line via shell, where the parentheses mean "open a subshell"?

Ciao,
Dscho

#27 lore raw
In reply to Jakub Narębski

Hi Kuba,

Quoted 21 lines · Jakub Narębski

W dniu 07.10.2016 o 13:20, Johannes Schindelin pisze:

Quoted 20 lines · Junio C Hamano
Quoted 18 lines
Quoted 8 lines · Nguyễn Thái Ngọc Duy

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make handling path arguments hard because they are relative to the original cwd. We set GIT_PREFIX to work around it, but I still think it's more natural to keep cwd where it is.

Quoted 4 lines

We have a way to do that now after 441981b (git: simplify environment save/restore logic - 2016-01-26). It's just a matter of choosing the right syntax. I'm going with '!!'. I'm not very happy with it. But I do like this type of alias.

I do not know why you are not happy with the syntax, but I personally think it brilliant, both the idea and the preliminary clean-up that made this possible with a simple patch like this.

Quoted 5 lines
Quoted 3 lines

I guess he is not happy with it because "!!" is quite unintuitive a construct. I know that *I* would have been puzzled by it, asking "What the heck does this do?".

Well, "!" as a prefix is not intuitive either.

You do not use vi, do you? :-P

In vi, if you enter command mode (typing a colon) and then want to execute, say, pwd, you type !pwd<Enter>

Quoted 2 lines

Perhaps "!.", because "." is current directory, and the "." command (that is, alias to "source") doesn't make sense in git aliases.

If you want to execute, say, pwd in the current directory, that would mean you want to write

	!.pwd

But that already means "execute .pwd"...

Quoted 2 lines

Note that we would have to teach git completion about new syntax; or new configuration variable if we go that route.

Why would we? Git's completion does not expand aliases, it only completes the aliases' names, not their values.

Ciao,
Dscho

#9 lore raw
In reply to Johannes Schindelin
Quoted 11 lines · Johannes Schindelin

Possibly a better idea would be to use *another* special symbol, one that makes intuitive sense as a modifier, such as:

[alias]
# This works as before
xyz = !pwd
# As does this
stat = -p status
# This, however, is different:
duy = (nocd)!pwd

Quoted 6 lines

This is backwards compatible as "(" is not a part of any Git command, nor of a valid alias, nor is it commonly used as part of a git-* executable/script.

It is also kind of a bit more intuitive, I'd wager, and it is also extensible to future options we may want to introduce.

I like this much better (like you, I am concerned about things like "!(foo)" as conflicting with the shell). And I think your "(nocd)!pwd" example is quite readable.

-Peff

#7 lore raw
In reply to Johannes Schindelin
Quoted 11 lines · Johannes Schindelin

Hi Matthieu,

Quoted 3 lines · Matthieu Moy

Another possibility: !(nocd), which leaves room
for !(keyword1,keyword2,...) if needed later. Also, it is consistent with the :(word) syntax of pathspecs.

But is this backwards-compatible? Don't we execute everything that comes after the exclamation mark as a command-line via shell, where the parentheses mean "open a subshell"?

Good point. I can imagine someone already having

[alias]

	foo = !(cd bar && $something) && $something_else

Your proposed (keyword)! is better.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#28 lore raw
In reply to Johannes Schindelin

W dniu 07.10.2016 o 16:19, Johannes Schindelin pisze:

Quoted 7 lines · Jakub Narębski
Quoted 3 lines

Note that we would have to teach git completion about new syntax; or new configuration variable if we go that route.

Why would we? Git's completion does not expand aliases, it only completes the aliases' names, not their values.

Because Git completion finds out which _options_ and _arguments_ to complete for an alias based on its expansion.

Yes, this is nice bit of trickery...

Signature · 1 line
Jakub Narębski
#10 lore raw
In reply to Duy Nguyen

Am 07.10.2016 um 14:27 schrieb Duy Nguyen:

Quoted 29 lines
Quoted 19 lines · Johannes Schindelin

Hi Junio,

Quoted 15 lines · Junio C Hamano
Quoted 12 lines · Nguyễn Thái Ngọc Duy

Throwing something at the mailing list to see if anybody is interested.

Current '!' aliases move cwd to $GIT_WORK_TREE first, which could make handling path arguments hard because they are relative to the original cwd. We set GIT_PREFIX to work around it, but I still think it's more natural to keep cwd where it is.

We have a way to do that now after 441981b (git: simplify environment save/restore logic - 2016-01-26). It's just a matter of choosing the right syntax. I'm going with '!!'. I'm not very happy with it. But I do like this type of alias.

Quoted 7 lines
Quoted 3 lines

I do not know why you are not happy with the syntax, but I personally think it brilliant, both the idea and the preliminary clean-up that made this possible with a simple patch like this.

I guess he is not happy with it because "!!" is quite unintuitive a construct. I know that *I* would have been puzzled by it, asking "What the heck does this do?".

Quoted 6 lines

Yep. And I wouldn't want to set a tradition for the next alias type '!!!'. There's no good choice to represent a new alias type with a leading symbol. This just occurred to me, however, what do you think about a new config group for it? With can have something like externalAlias.* (or some other name) that lives in parallel with alias.*. Then we don't need '!' (or '!!') at all.

Maybe it's time to aim for

  git config alias.d2u.shell \
       'f() { git ls-files "$@" | xargs dos2unix; }; f'

git config alias.d2u.cdup false
git d2u *.c # yada!

-- Hannes

#11 lore raw
Quoted 6 lines · Johannes Sixt

Maybe it's time to aim for

  git config alias.d2u.shell \
       'f() { git ls-files "$@" | xargs dos2unix; }; f'

git config alias.d2u.cdup false
git d2u *.c # yada!

That would be nice. It would also allow "alias.foo_bar.shell"; right now "alias.foo_bar" is forbidden because of the config syntax, which does not allow underscores outside of the "subsection" name.

-Peff

author
#29 lore raw
In reply to Jakub Narębski
Quoted 6 lines · Jakub Narębski

W dniu 07.10.2016 o 16:19, Johannes Schindelin pisze:

Quoted 5 lines · Jakub Narębski
Quoted 3 lines

Note that we would have to teach git completion about new syntax; or new configuration variable if we go that route.

Quoted 7 lines
Quoted 2 lines

Why would we? Git's completion does not expand aliases, it only completes the aliases' names, not their values.

Because Git completion finds out which _options_ and _arguments_ to complete for an alias based on its expansion.

Yes, this is nice bit of trickery...

It's c63437c (bash: improve aliased command recognition - 2010-02-23) isn't it? This may favor j6t's approach [1] because retrieving alias attributes is much easier.

[1] https://public-inbox.org/git/[email protected]/T/#mb1d7b8f31d595b05105b8ea2137756761e13dbf4

Signature · 1 line
Duy
#12 lore raw
In reply to Jeff King

Hi Peff & Hannes,

Quoted 4 lines · Jeff King
Quoted 2 lines · Johannes Sixt

Maybe it's time to aim for

Quoted 8 lines
Quoted 4 lines
  git config alias.d2u.shell \
       'f() { git ls-files "$@" | xargs dos2unix; }; f'

git config alias.d2u.cdup false
git d2u *.c # yada!

That would be nice. It would also allow "alias.foo_bar.shell"; right now "alias.foo_bar" is forbidden because of the config syntax, which does not allow underscores outside of the "subsection" name.

So what about this?

	[alias]
		d2u = !dos2unix
	[alias "d2u"]
		shell = 'f() { git ls-files "$@" | xargs dos2unix; }; f'
		exec = C:/cygwin64/bin/dos2unix.exe

You introduce all kinds of ambiguities here that did not exist before...

Ciao,
Dscho

#14 lore raw
In reply to Jeff King
Quoted 21 lines · Jeff King
Quoted 9 lines

So what about this?

	[alias]
		d2u = !dos2unix
	[alias "d2u"]
		shell = 'f() { git ls-files "$@" | xargs dos2unix; }; f'
		exec = C:/cygwin64/bin/dos2unix.exe

You introduce all kinds of ambiguities here that did not exist before...

If you mean ambiguity between the old "alias.X" and the new "alias.X.*", then yes, I think that's an unavoidable part of the transition. IMHO, the new should take precedence over the old, and people will gradually move from one to the other.

If you mean the ambiguity between alias.X.shell and alias.X.exec in your example, the problem is that you have keys with overlapping meanings. One solution is "don't do that" (so have a key like "cmd", and another to select "shell or git-cmd", etc). Another is to define some rule, like "last one wins" (so "exec" overrides "shell" in your example).

Quoted 4 lines

I'd prefer the "don't do that" path. The config you showed is nonsensical, and it doesn't really matter that much how we behave. But it is better still if we have a config scheme that makes it hard to write nonsensical things in the first place.

Just to be clear on my "don't do that", I don't mean "the user should not do that", but "do not design a config scheme with keys that have overlapping meanings".

-Peff

#13 lore raw
In reply to Johannes Schindelin
Quoted 13 lines · Johannes Schindelin
Quoted 10 lines
Quoted 6 lines

Maybe it's time to aim for

  git config alias.d2u.shell \
       'f() { git ls-files "$@" | xargs dos2unix; }; f'

git config alias.d2u.cdup false
git d2u *.c # yada!

That would be nice. It would also allow "alias.foo_bar.shell"; right now "alias.foo_bar" is forbidden because of the config syntax, which does not allow underscores outside of the "subsection" name.

So what about this?

Quoted 7 lines
	[alias]
		d2u = !dos2unix
	[alias "d2u"]
		shell = 'f() { git ls-files "$@" | xargs dos2unix; }; f'
		exec = C:/cygwin64/bin/dos2unix.exe

You introduce all kinds of ambiguities here that did not exist before...

If you mean ambiguity between the old "alias.X" and the new "alias.X.*", then yes, I think that's an unavoidable part of the transition. IMHO, the new should take precedence over the old, and people will gradually move from one to the other.

If you mean the ambiguity between alias.X.shell and alias.X.exec in your example, the problem is that you have keys with overlapping meanings. One solution is "don't do that" (so have a key like "cmd", and another to select "shell or git-cmd", etc). Another is to define some rule, like "last one wins" (so "exec" overrides "shell" in your example).

I'd prefer the "don't do that" path. The config you showed is nonsensical, and it doesn't really matter that much how we behave. But it is better still if we have a config scheme that makes it hard to write nonsensical things in the first place.

-Peff

author
#15 lore raw
Quoted 21 lines · Jeff King
Quoted 19 lines · Johannes Schindelin
Quoted 10 lines
Quoted 6 lines

Maybe it's time to aim for

  git config alias.d2u.shell \
       'f() { git ls-files "$@" | xargs dos2unix; }; f'

git config alias.d2u.cdup false
git d2u *.c # yada!

That would be nice. It would also allow "alias.foo_bar.shell"; right now "alias.foo_bar" is forbidden because of the config syntax, which does not allow underscores outside of the "subsection" name.

So what about this?

      [alias]
              d2u = !dos2unix
      [alias "d2u"]
              shell = 'f() { git ls-files "$@" | xargs dos2unix; }; f'
              exec = C:/cygwin64/bin/dos2unix.exe
Quoted 6 lines
Quoted 1 line

You introduce all kinds of ambiguities here that did not exist before...

If you mean ambiguity between the old "alias.X" and the new "alias.X.*", then yes, I think that's an unavoidable part of the transition. IMHO, the new should take precedence over the old, and people will gradually move from one to the other.

Do we really need to treat this differently than

[alias]
d2u = !dos2unix
d2u = C:/cygwin/bin/dos3unix.exe

?

Another similar case is one d2u (could be either old syntax or new) is defined in ~/.gitconfig and the other d2u in $GIT_DIR/config. In either case, the "latest" d2u definition wins.

Quoted 10 lines

If you mean the ambiguity between alias.X.shell and alias.X.exec in your example, the problem is that you have keys with overlapping meanings. One solution is "don't do that" (so have a key like "cmd", and another to select "shell or git-cmd", etc). Another is to define some rule, like "last one wins" (so "exec" overrides "shell" in your example).

I'd prefer the "don't do that" path. The config you showed is nonsensical, and it doesn't really matter that much how we behave. But it is better still if we have a config scheme that makes it hard to write nonsensical things in the first place.

Any suggestion? I suppose we can have _one_ key for the command. How to execute that command (exec, shell, nocd...) are boolean options. People can still write conflicting things. We have been nice so far, always dying when the user specify conflicting command line options. We could do the same here, I guess.

Signature · 1 line
Duy
#16 lore raw
Quoted 11 lines · Duy Nguyen
Quoted 4 lines

If you mean ambiguity between the old "alias.X" and the new "alias.X.*", then yes, I think that's an unavoidable part of the transition. IMHO, the new should take precedence over the old, and people will gradually move from one to the other.

Do we really need to treat this differently than

[alias]
d2u = !dos2unix
d2u = C:/cygwin/bin/dos3unix.exe

Quoted 5 lines

?

Another similar case is one d2u (could be either old syntax or new) is defined in ~/.gitconfig and the other d2u in $GIT_DIR/config. In either case, the "latest" d2u definition wins.

Yeah, that's reasonable, too. So:

[alias]

    d2u = "!dos2unix"

acts exactly as if:

[alias "d2u"]
command = dos2unix
type = shell

was specified at that point, which is easy to understand.

Quoted 5 lines
Quoted 5 lines

If you mean the ambiguity between alias.X.shell and alias.X.exec in your example, the problem is that you have keys with overlapping meanings. One solution is "don't do that" (so have a key like "cmd", and another to select "shell or git-cmd", etc). Another is to define some rule, like "last one wins" (so "exec" overrides "shell" in your example).

Quoted 7 lines

[...]

Any suggestion? I suppose we can have _one_ key for the command. How to execute that command (exec, shell, nocd...) are boolean options. People can still write conflicting things. We have been nice so far, always dying when the user specify conflicting command line options. We could do the same here, I guess.

Having separate exec/shell boolean options just punts the overlap from the command key to those keys. If you have two mutually exclusive options, I think the best thing is a single option, like:

type = <shell | exec | whatever>

and then it is obvious that a second appearance of "type" overrides an earlier one, by our usual "last one wins" convention. As opposed to:

shell = true
exec = true

where you have to understand the meaning of each option to know that "exec" overrides "shell".

-Peff

#17 lore raw
Quoted 6 lines · Jeff King

Having separate exec/shell boolean options just punts the overlap from the command key to those keys. If you have two mutually exclusive options, I think the best thing is a single option, like:

type = <shell | exec | whatever>

Quoted 8 lines

and then it is obvious that a second appearance of "type" overrides an earlier one, by our usual "last one wins" convention. As opposed to:

shell = true
exec = true

where you have to understand the meaning of each option to know that "exec" overrides "shell".

Good.

Duy's "do we want to chdir or stay?" would be an orthogonal axis to "what does the command line look like?" and "how is the command line run?" so it adds one member to the "alias.<string>.*" family of variables, I guess.

#18 lore raw
Quoted 17 lines · Junio C Hamano
Quoted 6 lines · Jeff King

Having separate exec/shell boolean options just punts the overlap from the command key to those keys. If you have two mutually exclusive options, I think the best thing is a single option, like:

type = <shell | exec | whatever>

Quoted 8 lines

and then it is obvious that a second appearance of "type" overrides an earlier one, by our usual "last one wins" convention. As opposed to:

shell = true
exec = true

where you have to understand the meaning of each option to know that "exec" overrides "shell".

Quoted 6 lines

Good.

Duy's "do we want to chdir or stay?" would be an orthogonal axis to "what does the command line look like?" and "how is the command line run?" so it adds one member to the "alias.<string>.*" family of variables, I guess.

Yeah, exactly. There may be other orthogonal axes to add, too, but I do not have any in mind myself. My main motive in switching to the "alias.$cmd.key" syntax is that it fixes the ancient mistake of putting arbitrary content into the key (just like pager.*, as we've discussed elsewhere).

-Peff

#19 lore raw
Quoted 4 lines · Jeff King

... My main motive in switching to the
"alias.$cmd.key" syntax is that it fixes the ancient mistake of putting arbitrary content into the key (just like pager.*, as we've discussed elsewhere).

Yup, we are on the same page. It's not too grave a mistake (we said "these are command names and do not have to be able to contain random letters" and deliberately did without the usual three-level hierarchy; I think the reasoning is even more valid for pager.*), but it does imply case insensitivity not to use three-level names, and I think it is a good move.

#20 lore raw
In reply to Jeff King

Hi,

Quoted 24 lines · Jeff King
Quoted 11 lines · Duy Nguyen
Quoted 4 lines

If you mean ambiguity between the old "alias.X" and the new "alias.X.*", then yes, I think that's an unavoidable part of the transition. IMHO, the new should take precedence over the old, and people will gradually move from one to the other.

Do we really need to treat this differently than

[alias]
d2u = !dos2unix
d2u = C:/cygwin/bin/dos3unix.exe

Quoted 5 lines

?

Another similar case is one d2u (could be either old syntax or new) is defined in ~/.gitconfig and the other d2u in $GIT_DIR/config. In either case, the "latest" d2u definition wins.

Yeah, that's reasonable, too. So:

[alias]

    d2u = "!dos2unix"
Quoted 7 lines

acts exactly as if:

[alias "d2u"]
command = dos2unix
type = shell

was specified at that point, which is easy to understand.

It is easy to understand, and even easier to get wrong or out of sync. I really liked the ease of *one* git config call to add new aliases. Not sure that I like the need for more such calls just to add *one* alias (one config call for "shell", one for "don't cd up", etc).

Ciao,
Dscho

author
#21 lore raw
Quoted 30 lines · Johannes Schindelin

Hi,

Quoted 26 lines · Jeff King
Quoted 11 lines · Duy Nguyen
Quoted 4 lines

If you mean ambiguity between the old "alias.X" and the new "alias.X.*", then yes, I think that's an unavoidable part of the transition. IMHO, the new should take precedence over the old, and people will gradually move from one to the other.

Do we really need to treat this differently than

[alias]
d2u = !dos2unix
d2u = C:/cygwin/bin/dos3unix.exe

Quoted 5 lines

?

Another similar case is one d2u (could be either old syntax or new) is defined in ~/.gitconfig and the other d2u in $GIT_DIR/config. In either case, the "latest" d2u definition wins.

Yeah, that's reasonable, too. So:

[alias]

    d2u = "!dos2unix"

acts exactly as if:

Quoted 8 lines
Quoted 5 lines

[alias "d2u"]
command = dos2unix
type = shell

was specified at that point, which is easy to understand.

It is easy to understand, and even easier to get wrong or out of sync. I really liked the ease of *one* git config call to add new aliases.

I was about to bring this up. Although to me, "git config --global alias.foo bar" is more convenient, but not using it is not exactly easy to get wrong or out of sync. For adding alias.$name.* I was thinking about "git config --global --edit", not executing "git config" multiple times.

Quoted 2 lines

Not sure that I like the need for more such calls just to add *one* alias (one config call for "shell", one for "don't cd up", etc).

We could add git-alias if more alias types pop up (and in my opinion git-alias is the right call, we've been abusing git-config for alias manipulation for a long time).

Signature · 1 line
Duy
#22 lore raw

Hi Duy,

Quoted 37 lines · Duy Nguyen
Quoted 35 lines · Johannes Schindelin
Quoted 31 lines · Jeff King
Quoted 11 lines · Duy Nguyen
Quoted 4 lines

If you mean ambiguity between the old "alias.X" and the new "alias.X.*", then yes, I think that's an unavoidable part of the transition. IMHO, the new should take precedence over the old, and people will gradually move from one to the other.

Do we really need to treat this differently than

[alias]
d2u = !dos2unix
d2u = C:/cygwin/bin/dos3unix.exe

Quoted 5 lines

?

Another similar case is one d2u (could be either old syntax or new) is defined in ~/.gitconfig and the other d2u in $GIT_DIR/config. In either case, the "latest" d2u definition wins.

Yeah, that's reasonable, too. So:

[alias]

    d2u = "!dos2unix"

acts exactly as if:

[alias "d2u"]
command = dos2unix
type = shell

was specified at that point, which is easy to understand.

Quoted 8 lines
Quoted 2 lines

It is easy to understand, and even easier to get wrong or out of sync. I really liked the ease of *one* git config call to add new aliases.

I was about to bring this up. Although to me, "git config --global alias.foo bar" is more convenient, but not using it is not exactly easy to get wrong or out of sync. For adding alias.$name.* I was thinking about "git config --global --edit", not executing "git config" multiple times.

Right, but many of my aliases get set by scripts, so your --edit idea won't work for me.

Quoted 6 lines
Quoted 2 lines

Not sure that I like the need for more such calls just to add *one* alias (one config call for "shell", one for "don't cd up", etc).

We could add git-alias if more alias types pop up (and in my opinion git-alias is the right call, we've been abusing git-config for alias manipulation for a long time).

Maybe.

It is also possible that this issue is a good indicator that we are complicating things [*1*] more than necessary...

Ciao,
Dscho

Footnote *1*:
http://thedailywtf.com/articles/The_Complicator_0x27_s_Gloves

#30 lore raw
In reply to Duy Nguyen

Quoting Duy Nguyen <[email protected]>:

Quoted 15 lines · Jakub Narębski
Quoted 6 lines

W dniu 07.10.2016 o 16:19, Johannes Schindelin pisze:

Quoted 5 lines · Jakub Narębski
Quoted 3 lines

Note that we would have to teach git completion about new syntax; or new configuration variable if we go that route.

Quoted 7 lines
Quoted 2 lines

Why would we? Git's completion does not expand aliases, it only completes the aliases' names, not their values.

Because Git completion finds out which _options_ and _arguments_ to complete for an alias based on its expansion.

Yes, this is nice bit of trickery...

Quoted 8 lines

It's c63437c (bash: improve aliased command recognition - 2010-02-23) isn't it? This may favor j6t's approach [1] because retrieving alias attributes is much easier.

[1]
https://public-inbox.org/git/[email protected]/T/#mb1d7b8f31d595b05105b8ea2137756761e13dbf4
--
Duy

The completion script is concerned in three ways:

1. it has to get the names of all aliases, to offer them along with git commands for 'git <TAB>' or 'git help <TAB>',

2. it has to get the command executed in place of the alias, and

3. strip everything that can't be a git command, so it can offer the right options for the aliased command.

The '!!' syntax is the easiest, I think it will just work even with the current completion code, no changes necessary.

The '(nocd)' form is still easy, we only have to add this '(nocd)' to that list of stripped words for (3), but no further changes necessary for (1) and (2).

'alias.d2u.command' is tricky. Both (1) and (2) require adjustments, preferably in a way that doesn't involve additional git processes, at least for (1), as it is executed often, for every 'git <TAB>', for the sake of users on platforms with not particularly stellar fork()+exec() performance. I think it would be possible to have only one 'git config --get-regexp' and a little bit of post processing in each case, but I didn't think too hard about possible pitfalls, especially when dealing with ambiguity when both 'alias.d2u' and 'alias.d2u.command' are set. And I won't think any more about it until a conclusion is reached that we'll go this route :)

#31 lore raw

W dniu 11.10.2016 o 13:51, SZEDER Gábor pisze:

Quoted 26 lines

Quoting Duy Nguyen <[email protected]>:

Quoted 13 lines · Jakub Narębski
Quoted 12 lines

W dniu 07.10.2016 o 16:19, Johannes Schindelin pisze:

Quoted 7 lines · Jakub Narębski
Quoted 3 lines

Note that we would have to teach git completion about new syntax; or new configuration variable if we go that route.

Why would we? Git's completion does not expand aliases, it only completes the aliases' names, not their values.

Because Git completion finds out which _options_ and _arguments_ to complete for an alias based on its expansion.

Quoted 9 lines
Quoted 1 line

Yes, this is nice bit of trickery...

It's c63437c (bash: improve aliased command recognition - 2010-02-23) isn't it? This may favor j6t's approach [1] because retrieving alias attributes is much easier.

[1] https://public-inbox.org/git/[email protected]/T/#mb1d7b8f31d595b05105b8ea2137756761e13dbf4

Signature · 1 line
Duy

The completion script is concerned in three ways:

Quoted 7 lines

1. it has to get the names of all aliases, to offer them along with git commands for 'git <TAB>' or 'git help <TAB>',

2. it has to get the command executed in place of the alias, and

3. strip everything that can't be a git command, so it can offer the right options for the aliased command.

There is also a possibility to tell the completion script which git command to use for option completion via some trickery, even if the first git command of many used in script is not right (e.g. when "$@" is passed somewhere in the middle).

I don't remember exact details, but let's look at source:

# If you use complex aliases of form '!f() { ... }; f', you can use the null

  # command ':' as the first command in the function body to declare the desired
  # completion style.  For example '!f() { : git commit ; ... }; f' will
  # tell the completion to use commit completion.  This also works with aliases
  # of form "!sh -c '...'".  For example, "!sh -c ': git commit ; ... '".

Very nice.

Quoted 7 lines

The '!!' syntax is the easiest, I think it will just work even with the current completion code, no changes necessary.

The '(nocd)' form is still easy, we only have to add this '(nocd)' to that list of stripped words for (3), but no further changes necessary for (1) and (2).

Shouldn't the '!' vs '!!' / '(nocd)!' affect pathname completion? Or do tab completion in subdir offer wrong completion of filenames for aliases?

Best,

Signature · 1 line
Jakub Narębski
#23 lore raw
In reply to Johannes Schindelin
Quoted 11 lines · Johannes Schindelin
Quoted 11 lines

Yeah, that's reasonable, too. So:

[alias]

    d2u = "!dos2unix"

acts exactly as if:

[alias "d2u"]
command = dos2unix
type = shell

Quoted 6 lines
Quoted 1 line

was specified at that point, which is easy to understand.

It is easy to understand, and even easier to get wrong or out of sync. I really liked the ease of *one* git config call to add new aliases. Not sure that I like the need for more such calls just to add *one* alias (one config call for "shell", one for "don't cd up", etc).

Could we simply support alias.d2u indefinitely, and you could use whichever format you felt like (the shorter, more limited one if you wanted, or the more verbose but flexible one)?

-Peff

author
#24 lore raw
Quoted 15 lines · Jeff King
Quoted 13 lines · Johannes Schindelin
Quoted 12 lines

Yeah, that's reasonable, too. So:

[alias]

    d2u = "!dos2unix"

acts exactly as if:

[alias "d2u"]
command = dos2unix
type = shell

was specified at that point, which is easy to understand.

Quoted 8 lines
Quoted 4 lines

It is easy to understand, and even easier to get wrong or out of sync. I really liked the ease of *one* git config call to add new aliases. Not sure that I like the need for more such calls just to add *one* alias (one config call for "shell", one for "don't cd up", etc).

Could we simply support alias.d2u indefinitely, and you could use whichever format you felt like (the shorter, more limited one if you wanted, or the more verbose but flexible one)?

Before this thread goes completely dead... Since there's a lot more work involved with the new alias.<name>.<property> approach (short term would be git completion support, longer term would be the ability to manipulate a config group more conveniently), I'm going with the "(properties)!command" approach. But even then a new series is not going to pop up, like, in the next two months.

I don't object the alias.<name>.<property> approach though. It's definitely a cleaner one in my opinion. It just needs people who can spend time to follow up until the end. But if someone decides to do that now, I'll drop the "(properties)!command" and try to support him/her.

Signature · 1 line
Duy
#25 lore raw
Quoted 5 lines · Duy Nguyen

I don't object the alias.<name>.<property> approach though. It's definitely a cleaner one in my opinion. It just needs people who can spend time to follow up until the end. But if someone decides to do that now, I'll drop the "(properties)!command" and try to support him/her.

I don't object to either approach, but what I would love to see people avoid is to end up with both.

Thanks.