8
#include "strbuf.h"
9
10
static char const * const builtin_sparse_checkout_usage[] = {
11
- N_("git sparse-checkout (init|list)"),
11
+ N_("git sparse-checkout (init|list|set) <options>"),
12
NULL
13
};
14
66
argv_array_pushl(&argv, "read-tree", "-m", "-u", "HEAD", NULL);
67
68
if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) {
69
- error(_("failed to update index with new sparse-checkout paths"));
69
+ error(_("failed to update index with new sparse-checkout patterns"));
70
result = 1;
71
}
72
136
return update_working_directory();
137
}
138
139
+static int write_patterns_and_update(struct pattern_list *pl)
140
+{
141
+ char *sparse_filename;
142
+ FILE *fp;
143
+
144
+ sparse_filename = get_sparse_checkout_filename();
145
+ fp = fopen(sparse_filename, "w");
146
+ write_patterns_to_file(fp, pl);
147
+ fclose(fp);
148
+ free(sparse_filename);
149
+
150
+ return update_working_directory();
151
+}
152
+
153
+static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
154
+{
155
+ static const char *empty_base = "";
156
+ int i;
157
+ struct pattern_list pl;
158
+ int result;
159
+ int changed_config = 0;
160
+ memset(&pl, 0, sizeof(pl));
161
+
162
+ for (i = 1; i < argc; i++)
163
+ add_pattern(argv[i], empty_base, 0, &pl, 0);
164
+
165
+ if (!core_apply_sparse_checkout) {
166
+ set_config(MODE_ALL_PATTERNS);
167
+ core_apply_sparse_checkout = 1;
168
+ changed_config = 1;
169
+ }
170
+
171
+ result = write_patterns_and_update(&pl);
172
+
173
+ if (result && changed_config)
174
+ set_config(MODE_NO_PATTERNS);
175
+
176
+ clear_pattern_list(&pl);
177
+ return result;
178
+}
179
+
180
int cmd_sparse_checkout(int argc, const char **argv, const char *prefix)
181
{
182
static struct option builtin_sparse_checkout_options[] = {
199
return sparse_checkout_list(argc, argv);
200
if (!strcmp(argv[0], "init"))
201
return sparse_checkout_init(argc, argv);
202
+ if (!strcmp(argv[0], "set"))
203
+ return sparse_checkout_set(argc, argv, prefix);
204
}
205
206
usage_with_options(builtin_sparse_checkout_usage,