1
#include "builtin.h"
2
+#include "cache.h"
3
#include "config.h"
4
#include "dir.h"
5
#include "parse-options.h"
685
return result;
686
}
687
687
-static void sanitize_paths(int argc, const char **argv, const char *prefix)
688
+static void sanitize_paths(int argc, const char **argv,
689
+ const char *prefix, int skip_checks)
690
{
691
+ int i;
692
+
693
if (!argc)
694
return;
695
698
* The args are not pathspecs, so unfortunately we
699
* cannot imitate how cmd_add() uses parse_pathspec().
700
*/
697
- int i;
701
int prefix_len = strlen(prefix);
702
703
for (i = 0; i < argc; i++)
704
argv[i] = prefix_path(prefix, prefix_len, argv[i]);
705
}
706
707
+ if (skip_checks)
708
+ return;
709
+
710
if (prefix && *prefix && !core_sparse_checkout_cone)
711
die(_("please run from the toplevel directory in non-cone mode"));
712
713
+ for (i = 0; i < argc; i++) {
714
+ struct cache_entry *ce;
715
+ struct index_state *index = the_repository->index;
716
+ int pos = index_name_pos(index, argv[i], strlen(argv[i]));
717
+
718
+ if (pos < 0)
719
+ continue;
720
+ ce = index->cache[pos];
721
+ if (S_ISSPARSEDIR(ce->ce_mode))
722
+ continue;
723
+
724
+ if (core_sparse_checkout_cone)
725
+ die(_("'%s' is not a directory; to treat it as a directory anyway, rerun with --skip-checks"), argv[i]);
726
+ else
727
+ warning(_("pass a leading slash before paths such as '%s' if you want a single file (see NON-CONE PROBLEMS in the git-sparse-checkout manual)."), argv[i]);
728
+ }
729
}
730
731
static char const * const builtin_sparse_checkout_add_usage[] = {
710
- N_("git sparse-checkout add (--stdin | <patterns>)"),
732
+ N_("git sparse-checkout add [--skip-checks] (--stdin | <patterns>)"),
733
NULL
734
};
735
736
static struct sparse_checkout_add_opts {
737
+ int skip_checks;
738
int use_stdin;
739
} add_opts;
740
741
static int sparse_checkout_add(int argc, const char **argv, const char *prefix)
742
{
743
static struct option builtin_sparse_checkout_add_options[] = {
744
+ OPT_BOOL_F(0, "skip-checks", &add_opts.skip_checks,
745
+ N_("skip some sanity checks on the given paths that might give false positives"),
746
+ PARSE_OPT_NONEG),
747
OPT_BOOL(0, "stdin", &add_opts.use_stdin,
748
N_("read patterns from standard in")),
749
OPT_END(),
759
builtin_sparse_checkout_add_usage,
760
PARSE_OPT_KEEP_UNKNOWN);
761
736
- sanitize_paths(argc, argv, prefix);
762
+ sanitize_paths(argc, argv, prefix, add_opts.skip_checks);
763
764
return modify_pattern_list(argc, argv, add_opts.use_stdin, ADD);
765
}
766
767
static char const * const builtin_sparse_checkout_set_usage[] = {
742
- N_("git sparse-checkout set [--[no-]cone] [--[no-]sparse-index] (--stdin | <patterns>)"),
768
+ N_("git sparse-checkout set [--[no-]cone] [--[no-]sparse-index] [--skip-checks] (--stdin | <patterns>)"),
769
NULL
770
};
771
772
static struct sparse_checkout_set_opts {
773
int cone_mode;
774
int sparse_index;
775
+ int skip_checks;
776
int use_stdin;
777
} set_opts;
778
786
N_("initialize the sparse-checkout in cone mode")),
787
OPT_BOOL(0, "sparse-index", &set_opts.sparse_index,
788
N_("toggle the use of a sparse index")),
789
+ OPT_BOOL_F(0, "skip-checks", &set_opts.skip_checks,
790
+ N_("skip some sanity checks on the given paths that might give false positives"),
791
+ PARSE_OPT_NONEG),
792
OPT_BOOL_F(0, "stdin", &set_opts.use_stdin,
793
N_("read patterns from standard in"),
794
PARSE_OPT_NONEG),
817
argv = default_patterns;
818
argc = default_patterns_nr;
819
} else {
790
- sanitize_paths(argc, argv, prefix);
820
+ sanitize_paths(argc, argv, prefix, set_opts.skip_checks);
821
}
822
823
return modify_pattern_list(argc, argv, set_opts.use_stdin, REPLACE);