forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dvc check-ignore
command (iterative#4282)
* Update some tests first fix iterative#3736 * first edition * solve failure in Windows * For Windows ci * Some help ducuments issue. * Update dvc/ignore.py abspath Co-authored-by: Ruslan Kuprieiev <[email protected]> * Refactor with OutOfWorkSpaceError * Solve a bug * Update dvc/command/check_ignore.py Co-authored-by: Jorge Orpinel <[email protected]> * Update dvc/command/check_ignore.py Co-authored-by: Jorge Orpinel <[email protected]> * Update dvc/command/check_ignore.py * Revert "Refactor with OutOfWorkSpaceError" This reverts commit 27eec49. * Two change request 1. Argument `targets`'s description. 2. Error handling of `_get_normalize_path` * Update dvc/main.py Co-authored-by: Ruslan Kuprieiev <[email protected]> * `check_ignore` now only accept one path a time 1. Add a new test for the out side repo cases 2. check ignore now only check one file not file lists Co-authored-by: Ruslan Kuprieiev <[email protected]> Co-authored-by: karajan1001 <[email protected]> Co-authored-by: Jorge Orpinel <[email protected]>
- Loading branch information
1 parent
b823ce4
commit 11d906e
Showing
7 changed files
with
293 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import argparse | ||
import logging | ||
|
||
from dvc.command import completion | ||
from dvc.command.base import CmdBase, append_doc_link | ||
from dvc.exceptions import DvcException | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class CmdCheckIgnore(CmdBase): | ||
def __init__(self, args): | ||
super().__init__(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) | ||
|
||
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.quiet and self.args.details: | ||
raise DvcException("cannot both --details and --quiet") | ||
|
||
ret = 1 | ||
for target in self.args.targets: | ||
result = self.ignore_filter.check_ignore(target) | ||
self._show_results(result) | ||
if result.match: | ||
ret = 0 | ||
return ret | ||
|
||
|
||
def add_parser(subparsers, parent_parser): | ||
ADD_HELP = "Debug DVC ignore/exclude files" | ||
|
||
parser = subparsers.add_parser( | ||
"check-ignore", | ||
parents=[parent_parser], | ||
description=append_doc_link(ADD_HELP, "check-ignore"), | ||
help=ADD_HELP, | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
) | ||
parser.add_argument( | ||
"-d", | ||
"--details", | ||
action="store_true", | ||
default=False, | ||
help="Show the exclude pattern together with each target path.", | ||
) | ||
parser.add_argument( | ||
"-n", | ||
"--non-matching", | ||
action="store_true", | ||
default=False, | ||
help="Show the target paths which don’t match any pattern. " | ||
"Only usable when `--details` is also employed", | ||
) | ||
parser.add_argument( | ||
"targets", | ||
nargs="+", | ||
help="Exact or wildcard paths of files or directories to check " | ||
"ignore patterns.", | ||
).complete = completion.FILE | ||
parser.set_defaults(func=CmdCheckIgnore) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.