diff options
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/sparse-checkout.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index fb85a1459c..3f828feb1f 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -684,6 +684,28 @@ static int modify_pattern_list(int argc, const char **argv, int use_stdin, return result; } +static void sanitize_paths(int argc, const char **argv, const char *prefix) +{ + if (!argc) + return; + + if (prefix && *prefix && core_sparse_checkout_cone) { + /* + * The args are not pathspecs, so unfortunately we + * cannot imitate how cmd_add() uses parse_pathspec(). + */ + int i; + int prefix_len = strlen(prefix); + + for (i = 0; i < argc; i++) + argv[i] = prefix_path(prefix, prefix_len, argv[i]); + } + + if (prefix && *prefix && !core_sparse_checkout_cone) + die(_("please run from the toplevel directory in non-cone mode")); + +} + static char const * const builtin_sparse_checkout_add_usage[] = { N_("git sparse-checkout add (--stdin | <patterns>)"), NULL @@ -711,6 +733,8 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix) builtin_sparse_checkout_add_usage, PARSE_OPT_KEEP_UNKNOWN); + sanitize_paths(argc, argv, prefix); + return modify_pattern_list(argc, argv, add_opts.use_stdin, ADD); } @@ -762,6 +786,8 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix) if (!core_sparse_checkout_cone && argc == 0) { argv = default_patterns; argc = default_patterns_nr; + } else { + sanitize_paths(argc, argv, prefix); } return modify_pattern_list(argc, argv, set_opts.use_stdin, REPLACE); |