Skip to content

Commit 7fce6e3

Browse files
pcloudsgitster
authored andcommitted
commit: correctly respect skip-worktree bit
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 56cac48 commit 7fce6e3

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

builtin-commit.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ static int list_paths(struct string_list *list, const char *with_tree,
164164

165165
for (i = 0; i < active_nr; i++) {
166166
struct cache_entry *ce = active_cache[i];
167+
struct string_list_item *item;
168+
167169
if (ce->ce_flags & CE_UPDATE)
168170
continue;
169171
if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
170172
continue;
171-
string_list_insert(ce->name, list);
173+
item = string_list_insert(ce->name, list);
174+
if (ce_skip_worktree(ce))
175+
item->util = item; /* better a valid pointer than a fake one */
172176
}
173177

174178
return report_path_error(m, pattern, prefix ? strlen(prefix) : 0);
@@ -180,10 +184,9 @@ static void add_remove_files(struct string_list *list)
180184
for (i = 0; i < list->nr; i++) {
181185
struct stat st;
182186
struct string_list_item *p = &(list->items[i]);
183-
int pos = index_name_pos(&the_index, p->string, strlen(p->string));
184-
struct cache_entry *ce = pos < 0 ? NULL : active_cache[pos];
185187

186-
if (ce && ce_skip_worktree(ce))
188+
/* p->util is skip-worktree */
189+
if (p->util)
187190
continue;
188191

189192
if (!lstat(p->string, &st)) {

t/t7011-skip-worktree-reading.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ test_expect_success 'git-rm succeeds on skip-worktree absent entries' '
148148
git rm 1
149149
'
150150

151-
test_expect_failure 'commit on skip-worktree absent entries' '
151+
test_expect_success 'commit on skip-worktree absent entries' '
152152
git reset &&
153153
setup_absent &&
154154
test_must_fail git commit -m null 1
155155
'
156156

157-
test_expect_failure 'commit on skip-worktree dirty entries' '
157+
test_expect_success 'commit on skip-worktree dirty entries' '
158158
git reset &&
159159
setup_dirty &&
160160
test_must_fail git commit -m null 1

0 commit comments

Comments
 (0)