git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] git wrapper: execute git-shell when argv[1] is '-c'

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 25, 2008, 20:52 UTC
Message-ID
<alpine.DEB.1.00.0808252251450.24820@pacific.mpi-cbg.de.mpi-cbg.de>
In-Reply-To
<alpine.DEB.1.00.0808252248150.24820@pacific.mpi-cbg.de.mpi-cbg.de>

When a program is called via ssh's '-c' option, the login shell is called on the remote computer, with the given arguments. In the case that Git was specified as login shell in /etc/passwd, Git used to complain that it does not know the '-c' option and die.

This commit assumes that '-c' indicates that Git was specified as a login shell, and hands off to git-shell.

Noticed by Tommi Virtanen.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	This should be pretty uncontroversial, as it turns a former
	error into something useful.
	However, I would not know where in the documentation (in addition
	to git-shell.txt, I guess), this change should be described.
 git.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/git.c b/git.c
index 2fd74c4..b16736a 100644
--- a/git.c
+++ b/git.c
@@ -419,14 +419,23 @@ static void execv_dashed_external(const char **argv)
 int main(int argc, const char **argv)
 {
 	const char *cmd = argv[0] && *argv[0] ? argv[0] : "git-help";
-	char *slash = (char *)cmd + strlen(cmd);
+	char *slash;
 	int done_alias = 0;
 
 	/*
+	 * When Git is called with "-c", it is either an error, or Git
+	 * was specified as a login shell in /etc/passwd.  Assuming the
+	 * latter, we continue with git-shell.
+	 */
+	if (argc > 2 && !strcmp(argv[1], "-c"))
+		cmd = "git-shell";
+
+	/*
 	 * Take the basename of argv[0] as the command
 	 * name, and the dirname as the default exec_path
 	 * if we don't have anything better.
 	 */
+	slash = (char *)cmd + strlen(cmd);
 	while (cmd <= slash && !is_dir_sep(*slash))
 		slash--;
 	if (slash < cmd) {
-- 
1.6.0.211.ga840e.dirty
Previous: Johannes SchindelinNext: Tommi Virtanen
Message 13 of 28 in “"git shell" won't work, need "git-shell"”
  1. "git shell" won't work, need "git-shell"Tommi Virtanen, Aug 24, 2008
  2. Junio C HamanoAug 24, 2008
  3. Tommi VirtanenAug 24, 2008
  4. Junio C HamanoAug 24, 2008
  5. Tommi VirtanenAug 24, 2008
  6. Johannes SchindelinAug 25, 2008
  7. Paolo BonziniAug 25, 2008
  8. Johannes SchindelinAug 25, 2008
  9. Mikael MagnussonAug 25, 2008
  10. Johannes SchindelinAug 25, 2008
  11. Johannes SchindelinAug 25, 2008
  12. 1/2 git wrapper: Make while loop more reader-friendlyJohannes Schindelin, Aug 25, 2008
  13. 2/2 git wrapper: execute git-shell when argv[1] is '-c'Johannes Schindelin, Aug 25, 2008
  14. Tommi VirtanenAug 25, 2008
  15. Johannes SchindelinAug 25, 2008
  16. Tommi VirtanenAug 25, 2008
  17. Johannes SchindelinAug 26, 2008
  18. Matthieu MoyAug 26, 2008
  19. Junio C HamanoAug 26, 2008
  20. Mike RalphsonAug 26, 2008
  21. Petr BaudisAug 25, 2008
  22. Dmitry PotapovAug 25, 2008
  23. Tommi VirtanenAug 25, 2008
  24. Dmitry PotapovAug 25, 2008
  25. Johannes SchindelinAug 25, 2008
  26. Dmitry PotapovAug 25, 2008
  27. Mike HommeyAug 25, 2008
  28. Dmitry V. LevinOct 28, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.