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

[PATCH 1/2] reset: handle submodule with trailing slash

From
John Keeping <john@keeping.me.uk>
Date
Sep 10, 2013, 19:13 UTC
Message-ID
<c7e026f44f9ccbf5736b72e728a360b31887a50f.1378840318.git.john@keeping.me.uk>
In-Reply-To
<cover.1378840318.git.john@keeping.me.uk>

When using tab-completion, a directory path will often end with a trailing slash which currently confuses "git rm" when dealing with submodules. Now that we have parse_pathspec we can easily handle this by simply adding the PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP flag.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
 builtin/reset.c            | 5 +++++
 t/t7400-submodule-basic.sh | 6 ++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/builtin/reset.c b/builtin/reset.c
index 5e4c551..9efac0f 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -220,8 +220,13 @@ static void parse_args(struct pathspec *pathspec,
 		}
 	}
 	*rev_ret = rev;
+
+	if (read_cache() < 0)
+		die(_("index file corrupt"));
+
 	parse_pathspec(pathspec, 0,
 		       PATHSPEC_PREFER_FULL |
+		       PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP |
 		       (patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0),
 		       prefix, argv);
 }
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 4192fe0..c268d3c 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -481,7 +481,7 @@ test_expect_success 'do not add files from a submodule' '
 
 '
 
-test_expect_success 'gracefully add submodule with a trailing slash' '
+test_expect_success 'gracefully add/reset submodule with a trailing slash' '
 
 	git reset --hard &&
 	git commit -m "commit subproject" init &&
@@ -495,7 +495,9 @@ test_expect_success 'gracefully add submodule with a trailing slash' '
 	git add init/ &&
 	test_must_fail git diff --exit-code --cached init &&
 	test $commit = $(git ls-files --stage |
-		sed -n "s/^160000 \([^ ]*\).*/\1/p")
+		sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
+	git reset init/ &&
+	git diff --exit-code --cached init
 
 '
 
-- 
1.8.2
Previous: John KeepingNext: Jens Lehmann
Message 2 of 27 in “reset: handle submodule with trailing slash”
  1. 0/2 reset: handle submodule with trailing slashJohn Keeping, Sep 10, 2013
  2. 1/2 reset: handle submodule with trailing slashJohn Keeping, Sep 10, 2013
  3. Jens LehmannSep 10, 2013
  4. John KeepingSep 10, 2013
  5. Johannes SixtSep 11, 2013
  6. John KeepingSep 11, 2013
  7. Duy NguyenSep 11, 2013
  8. John KeepingSep 11, 2013
  9. Duy NguyenSep 11, 2013
  10. Junio C HamanoSep 11, 2013
  11. John KeepingSep 11, 2013
  12. Junio C HamanoSep 11, 2013
  13. John KeepingSep 11, 2013
  14. Junio C HamanoSep 11, 2013
  15. 2/2 rm: re-use parse_pathspec's trailing-slash removalJohn Keeping, Sep 10, 2013
  16. Duy NguyenSep 11, 2013
  17. John KeepingSep 11, 2013
  18. 0/4 submodule trailing slash improvementsJohn Keeping, Sep 12, 2013
  19. 1/4 pathspec: use is_dir_sep() to check for trailing slashesJohn Keeping, Sep 12, 2013
  20. Johannes SixtSep 12, 2013
  21. 2/4 pathspec: strip multiple trailing slashes from submodulesJohn Keeping, Sep 12, 2013
  22. Junio C HamanoSep 12, 2013
  23. John KeepingSep 12, 2013
  24. Duy NguyenSep 13, 2013
  25. John KeepingSep 13, 2013
  26. 3/4 rm: re-use parse_pathspec's trailing-slash removalJohn Keeping, Sep 12, 2013
  27. 4/4 reset: handle submodule with trailing slashJohn Keeping, Sep 12, 2013

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.