git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Respun patches for git aliases enhancement
@ 2007-02-11  0:33 Theodore Ts'o
  2007-02-11  0:33 ` [PATCH 1/2] Print a sane error message if an alias expands to an invalid git command Theodore Ts'o
  2007-02-11 16:32 ` [PATCH 0/2] Respun patches for git aliases enhancement Johannes Schindelin
  0 siblings, 2 replies; 4+ messages in thread
From: Theodore Ts'o @ 2007-02-11  0:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

These patches have been respun to fix a spelling typo and in response
to comments from Johannes.

						- Ted

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

* [PATCH 1/2] Print a sane error message if an alias expands to an invalid git command
  2007-02-11  0:33 [PATCH 0/2] Respun patches for git aliases enhancement Theodore Ts'o
@ 2007-02-11  0:33 ` Theodore Ts'o
  2007-02-11  0:33   ` [PATCH 2/2] Allow aliases to expand to shell commands Theodore Ts'o
  2007-02-11 16:32 ` [PATCH 0/2] Respun patches for git aliases enhancement Johannes Schindelin
  1 sibling, 1 reply; 4+ messages in thread
From: Theodore Ts'o @ 2007-02-11  0:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Theodore Ts'o

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
 git.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/git.c b/git.c
index 82a8357..c43d4ff 100644
--- a/git.c
+++ b/git.c
@@ -387,8 +387,15 @@ int main(int argc, const char **argv, char **envp)
 		done_alias = 1;
 	}
 
-	if (errno == ENOENT)
+	if (errno == ENOENT) {
+		if (done_alias) {
+			fprintf(stderr, "Expansion of alias '%s' failed; "
+				"'%s' is not a git-command\n",
+				cmd, argv[0]);
+			exit(1);
+		}
 		help_unknown_cmd(cmd);
+	}
 
 	fprintf(stderr, "Failed to run command '%s': %s\n",
 		cmd, strerror(errno));
-- 
1.5.0.rc4.2.g4249

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

* [PATCH 2/2] Allow aliases to expand to shell commands
  2007-02-11  0:33 ` [PATCH 1/2] Print a sane error message if an alias expands to an invalid git command Theodore Ts'o
@ 2007-02-11  0:33   ` Theodore Ts'o
  0 siblings, 0 replies; 4+ messages in thread
From: Theodore Ts'o @ 2007-02-11  0:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Theodore Ts'o

If the alias expansion is prefixed with an exclamation point, treat
it as a shell command which is run using system(3).

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
 Documentation/config.txt |    6 ++++++
 git.c                    |   10 ++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4e650af..e6e9409 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -222,6 +222,12 @@ alias.*::
 	spaces, the usual shell quoting and escaping is supported.
 	quote pair and a backslash can be used to quote them.
 
+	If the alias expansion is prefixed with an exclamation point,
+	it will be treated as a shell command.  For example, defining
+	"alias.new = !gitk --all --not ORIG_HEAD", the invocation 
+	"git new" is equivalent to running the shell command 
+	"gitk --all --not ORIG_HEAD".
+
 apply.whitespace::
 	Tells `git-apply` how to handle whitespaces, in the same way
 	as the '--whitespace' option. See gitlink:git-apply[1].
diff --git a/git.c b/git.c
index c43d4ff..2f10d50 100644
--- a/git.c
+++ b/git.c
@@ -159,6 +159,16 @@ static int handle_alias(int *argcp, const char ***argv)
 	alias_command = (*argv)[0];
 	git_config(git_alias_config);
 	if (alias_string) {
+		if (alias_string[0] == '!') {
+			trace_printf("trace: alias to shell cmd: %s => %s\n",
+				     alias_command, alias_string + 1);
+			ret = system(alias_string + 1);
+			if (ret >= 0 && WIFEXITED(ret) && 
+			    WEXITSTATUS(ret) != 127)
+				exit(WEXITSTATUS(ret));
+			die("Failed to run '%s' when expanding alias '%s'\n", 
+			    alias_string + 1, alias_command);
+		}
 		count = split_cmdline(alias_string, &new_argv);
 		option_count = handle_options(&new_argv, &count);
 		memmove(new_argv - option_count, new_argv,
-- 
1.5.0.rc4.2.g4249

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

* Re: [PATCH 0/2] Respun patches for git aliases enhancement
  2007-02-11  0:33 [PATCH 0/2] Respun patches for git aliases enhancement Theodore Ts'o
  2007-02-11  0:33 ` [PATCH 1/2] Print a sane error message if an alias expands to an invalid git command Theodore Ts'o
@ 2007-02-11 16:32 ` Johannes Schindelin
  1 sibling, 0 replies; 4+ messages in thread
From: Johannes Schindelin @ 2007-02-11 16:32 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: Junio C Hamano, git

Hi,

On Sat, 10 Feb 2007, Theodore Ts'o wrote:

> These patches have been respun to fix a spelling typo and in response
> to comments from Johannes.

Sorry to have apply-checked only now: Ted, could you run the second commit 
through "git show --check"? It has 4 whitespaces at end. But I am sure 
that Junio can fix them.

Apart from that:
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>

Ciao,
Dscho

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

end of thread, other threads:[~2007-02-11 16:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-11  0:33 [PATCH 0/2] Respun patches for git aliases enhancement Theodore Ts'o
2007-02-11  0:33 ` [PATCH 1/2] Print a sane error message if an alias expands to an invalid git command Theodore Ts'o
2007-02-11  0:33   ` [PATCH 2/2] Allow aliases to expand to shell commands Theodore Ts'o
2007-02-11 16:32 ` [PATCH 0/2] Respun patches for git aliases enhancement Johannes Schindelin

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).