Commit 7fce6e3c authored by Duy Nguyen's avatar Duy Nguyen Committed by Junio C Hamano

commit: correctly respect skip-worktree bit

Commit b4d1690d (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

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: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent 56cac48c
......@@ -164,11 +164,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)
if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
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);
......@@ -180,10 +184,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)
if (!lstat(p->string, &st)) {
......@@ -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
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment