-
Couldn't load subscription status.
- Fork 1.3k
Two new modes --all and --stdin for check-ignore
#4323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
aa27920
fc40747
489dd16
83d043e
dbad2c6
e1eec42
5bc66a4
f10cfed
b51f6d0
edba25b
002d942
a5bb82d
a504fa3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| from dvc.command import completion | ||
| from dvc.command.base import CmdBase, append_doc_link | ||
| from dvc.exceptions import DvcException | ||
| from dvc.prompt import ask | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -14,27 +15,71 @@ def __init__(self, args): | |
| self.ignore_filter = self.repo.tree.dvcignore | ||
|
|
||
| def _show_results(self, result): | ||
| if result.match or self.args.non_matching: | ||
| if self.args.details: | ||
| logger.info("{}\t{}".format(result.patterns[-1], result.file)) | ||
| else: | ||
| logger.info(result.file) | ||
| if not result.match and not self.args.non_matching: | ||
| return | ||
|
|
||
| def run(self): | ||
| if self.args.non_matching and not self.args.details: | ||
| raise DvcException("--non-matching is only valid with --details") | ||
| if self.args.details: | ||
| patterns = result.patterns | ||
| if not self.args.all: | ||
| patterns = patterns[-1:] | ||
|
|
||
| if self.args.quiet and self.args.details: | ||
| raise DvcException("cannot both --details and --quiet") | ||
| for pattern in patterns: | ||
| logger.info("{}\t{}".format(pattern, result.file)) | ||
| else: | ||
| logger.info(result.file) | ||
|
|
||
| def _check_one_file(self, target): | ||
| result = self.ignore_filter.check_ignore(target) | ||
| self._show_results(result) | ||
| if result.match: | ||
| return 0 | ||
| return 1 | ||
|
|
||
| def _interactive_mode(self): | ||
| ret = 1 | ||
| while True: | ||
| target = ask("") | ||
| if target == "": | ||
| logger.info( | ||
| "Empty string is not a valid pathspec. Please use . " | ||
| "instead if you meant to match all paths." | ||
| ) | ||
| break | ||
| if not self._check_one_file(target): | ||
| ret = 0 | ||
| return ret | ||
|
|
||
| def _normal_mode(self): | ||
| ret = 1 | ||
| for target in self.args.targets: | ||
| result = self.ignore_filter.check_ignore(target) | ||
| self._show_results(result) | ||
| if result.match: | ||
| if not self._check_one_file(target): | ||
| ret = 0 | ||
| return ret | ||
|
|
||
| def _check_args(self): | ||
| if not self.args.stdin and not self.args.targets: | ||
| raise DvcException("`targets` or `--stdin` needed") | ||
|
|
||
| if self.args.stdin and self.args.targets: | ||
| raise DvcException("cannot have both `targets` and `--stdin`") | ||
|
|
||
| if self.args.non_matching and not self.args.details: | ||
| raise DvcException( | ||
| "`--non-matching` is only valid with `--details`" | ||
| ) | ||
|
|
||
| if self.args.all and not self.args.details: | ||
| raise DvcException("`--all` is only valid with `--details`") | ||
|
|
||
| if self.args.quiet and self.args.details: | ||
| raise DvcException("cannot use both `--details` and `--quiet`") | ||
|
Comment on lines
+74
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe --quiet should just win here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it used to be |
||
|
|
||
| def run(self): | ||
| self._check_args() | ||
| if self.args.stdin: | ||
| return self._interactive_mode() | ||
| return self._normal_mode() | ||
|
|
||
|
|
||
| def add_parser(subparsers, parent_parser): | ||
| ADD_HELP = "Debug DVC ignore/exclude files" | ||
|
|
@@ -61,9 +106,24 @@ def add_parser(subparsers, parent_parser): | |
| help="Show the target paths which donβt match any pattern. " | ||
| "Only usable when `--details` is also employed", | ||
| ) | ||
| parser.add_argument( | ||
| "--stdin", | ||
| action="store_true", | ||
| default=False, | ||
| help="Read pathnames from the standard input, one per line, " | ||
| "instead of from the command-line.", | ||
jorgeorpinel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
karajan1001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| parser.add_argument( | ||
| "-a", | ||
| "--all", | ||
| action="store_true", | ||
| default=False, | ||
| help="Show all of the patterns match the target paths. " | ||
| "Only usable when `--details` is also employed", | ||
jorgeorpinel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| parser.add_argument( | ||
| "targets", | ||
| nargs="+", | ||
| nargs="*", | ||
| help="Exact or wildcard paths of files or directories to check " | ||
| "ignore patterns.", | ||
| ).complete = completion.FILE | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a pathspec?
Can users actually send an empty string (e.g.
'')? Or does this happen when you don't send any args?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jorgeorpinel
pathspecmeans the target to be checkedUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe don't say anything and just go to the next
>? Seems intuitive enough that way. I just tried it and noticed it crashes after this error msg (i.e. it stops the interactive mode).UPDATE: On Windows at least, there's no
>chars in interactive mode, see iterative/dvc.org#1675 (review)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p.s. when I send an empty string as target i.e.
dvc check-ignore ''it just checks it (never matches even if*is a pattern in.dvcignore) and this error isn't presented. Seems slightly inconsistent. I vote to just remove it altogether πThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted to #4361