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

[PATCH 2/2] commit: correctly respect skip-worktree bit

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Dec 14, 2009, 11:43 UTC
Message-ID
<1260791039-12316-2-git-send-email-pclouds@gmail.com>
In-Reply-To
<1260791039-12316-1-git-send-email-pclouds@gmail.com>

Commit b4d1690 (Teach Git to respect skip-worktree bit (reading part)) fails to make "git commit -- a b c" respect skip-worktree (i.e. not committing paths that are skip-worktree). This is because when the index is reset back to HEAD, all skip-worktree information is gone.

This patch saves skip-worktree information in the string list of committed paths, then reuse it later on to skip skip-worktree paths.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-commit.c                 |   11 +++++++----
 t/t7011-skip-worktree-reading.sh |    4 ++--
 2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index a11e585..6e368f0 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -180,11 +180,15 @@ static int list_paths(struct string_list *list, const char *with_tree,
 
 	for (i = 0; i < active_nr; i++) {
 		struct cache_entry *ce = active_cache[i];
+		struct string_list_item *item;
+
 		if (ce->ce_flags & CE_UPDATE)
 			continue;
 		if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
 			continue;
-		string_list_insert(ce->name, list);
+		item = string_list_insert(ce->name, list);
+		if (ce_skip_worktree(ce))
+			item->util = item; /* better a valid pointer than a fake one */
 	}
 
 	return report_path_error(m, pattern, prefix ? strlen(prefix) : 0);
@@ -196,10 +200,9 @@ static void add_remove_files(struct string_list *list)
 	for (i = 0; i < list->nr; i++) {
 		struct stat st;
 		struct string_list_item *p = &(list->items[i]);
-		int pos = index_name_pos(&the_index, p->string, strlen(p->string));
-		struct cache_entry *ce = pos < 0 ? NULL : active_cache[pos];
 
-		if (ce && ce_skip_worktree(ce))
+		/* p->util is skip-worktree */
+		if (p->util)
 			continue;
 
 		if (!lstat(p->string, &st)) {
diff --git a/t/t7011-skip-worktree-reading.sh b/t/t7011-skip-worktree-reading.sh
index e996928..bb4066f 100755
--- a/t/t7011-skip-worktree-reading.sh
+++ b/t/t7011-skip-worktree-reading.sh
@@ -148,13 +148,13 @@ test_expect_success 'git-rm succeeds on skip-worktree absent entries' '
 	git rm 1
 '
 
-test_expect_failure 'commit on skip-worktree absent entries' '
+test_expect_success 'commit on skip-worktree absent entries' '
 	git reset &&
 	setup_absent &&
 	test_must_fail git commit -m null 1
 '
 
-test_expect_failure 'commit on skip-worktree dirty entries' '
+test_expect_success 'commit on skip-worktree dirty entries' '
 	git reset &&
 	setup_dirty &&
 	test_must_fail git commit -m null 1
-- 
1.6.5.2.216.g9c1ec
Previous: Nguyễn Thái Ngọc Duy
Message 2 of 2 in “ie_match_stat(): do not ignore skip-worktree bit with CE_MATCH_IGNORE_VALID”
  1. 1/2 ie_match_stat(): do not ignore skip-worktree bit with CE_MATCH_IGNORE_VALIDNguyễn Thái Ngọc Duy, Dec 14, 2009
  2. 2/2 commit: correctly respect skip-worktree bitNguyễn Thái Ngọc Duy, Dec 14, 2009

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.