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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Dec 14, 2009 at 18:43 UTC
7fce6e3c9a3cf652099ee5f0e52b59c407692044
2 files changed
+9
-6
builtin-commit.c
+7
-4
@@ -164,11 +164,15 @@ static int list_paths(struct string_list *list, const char *with_tree,
164
165
for (i = 0; i < active_nr; i++) {
166
struct cache_entry *ce = active_cache[i];
167
+ struct string_list_item *item;
168
+
169
if (ce->ce_flags & CE_UPDATE)
170
continue;
171
if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
172
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 */
176
}
177
178
return report_path_error(m, pattern, prefix ? strlen(prefix) : 0);
@@ -180,10 +184,9 @@ static void add_remove_files(struct string_list *list)
184
for (i = 0; i < list->nr; i++) {
185
struct stat st;
186
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];
187
186
- if (ce && ce_skip_worktree(ce))
188
+ /* p->util is skip-worktree */
189
+ if (p->util)
190
continue;
191
192
if (!lstat(p->string, &st)) {
t/t7011-skip-worktree-reading.sh
+2
-2
@@ -148,13 +148,13 @@ test_expect_success 'git-rm succeeds on skip-worktree absent entries' '
148
git rm 1
149
'
150
151
-test_expect_failure 'commit on skip-worktree absent entries' '
151
+test_expect_success 'commit on skip-worktree absent entries' '
152
git reset &&
153
setup_absent &&
154
test_must_fail git commit -m null 1
155
'
156
157
-test_expect_failure 'commit on skip-worktree dirty entries' '
157
+test_expect_success 'commit on skip-worktree dirty entries' '
158
git reset &&
159
setup_dirty &&
160
test_must_fail git commit -m null 1