diff --git a/src/darker/__main__.py b/src/darker/__main__.py index ba65e93fb..8fba15a38 100644 --- a/src/darker/__main__.py +++ b/src/darker/__main__.py @@ -29,8 +29,8 @@ def format_edited_parts( """Black (and optional isort) formatting for chunks with edits since the last commit 1. run isort on each edited file (optional) - 2. diff HEAD and worktree (optionally with isort modifications) for all file & dir - paths on the command line + 2. diff the given revision and worktree (optionally with isort modifications) for + all file & dir paths on the command line 3. extract line numbers in each edited to-file for changed lines 4. run black on the contents of each edited to-file 5. get a diff between the edited to-file and the reformatted content @@ -44,8 +44,8 @@ def format_edited_parts( the original edited to-file 10. write the reformatted source back to the original file 11. run linter subprocesses for all edited files (11.-14. optional) - 12. diff HEAD and worktree (after isort and Black reformatting) for each file - reported by a linter + 12. diff the given revision and worktree (after isort and Black reformatting) for + each file reported by a linter 13. extract line numbers in each file reported by a linter for changed lines 14. print only linter error lines which fall on changed lines @@ -80,7 +80,7 @@ def format_edited_parts( edited_lines = edited_content.splitlines() max_context_lines = len(edited_lines) for context_lines in range(max_context_lines + 1): - # 2. diff HEAD and worktree for the file + # 2. diff the given revision and worktree for the file # 3. extract line numbers in the edited to-file for changed lines edited_linenums = edited_linenums_differ.revision_vs_lines( path_in_repo, edited_lines, context_lines @@ -145,8 +145,8 @@ def format_edited_parts( yield src, worktree_content, result_str, chosen_lines break # 11. run linter subprocesses for all edited files (11.-14. optional) - # 12. diff HEAD and worktree (after isort and Black reformatting) for each file - # reported by a linter + # 12. diff the given revision and worktree (after isort and Black reformatting) for + # each file reported by a linter # 13. extract line numbers in each file reported by a linter for changed lines # 14. print only linter error lines which fall on changed lines for linter_cmdline in linter_cmdlines: diff --git a/src/darker/git.py b/src/darker/git.py index fa9dbaef8..0381a280a 100644 --- a/src/darker/git.py +++ b/src/darker/git.py @@ -102,7 +102,7 @@ class EditedLinenumsDiffer: @lru_cache(maxsize=1) def revision_vs_worktree(self, path_in_repo: Path, context_lines: int) -> List[int]: - """Return numbers of lines changed between HEAD and the working tree""" + """Return numbers of lines changed between a given revision and the worktree""" lines = (self.git_root / path_in_repo).read_text("utf-8").splitlines() return self.revision_vs_lines(path_in_repo, lines, context_lines) diff --git a/src/darker/tests/test_git.py b/src/darker/tests/test_git.py index 787d771b7..9ec0feb73 100644 --- a/src/darker/tests/test_git.py +++ b/src/darker/tests/test_git.py @@ -101,8 +101,8 @@ def test_git_get_modified_files(git_repo, modify_paths, paths, expect): @edited_linenums_differ_cases -def test_edited_linenums_differ_head_vs_worktree(git_repo, context_lines, expect): - """Tests for EditedLinenumsDiffer.head_vs_worktree()""" +def test_edited_linenums_differ_revision_vs_worktree(git_repo, context_lines, expect): + """Tests for EditedLinenumsDiffer.revision_vs_worktree()""" paths = git_repo.add({"a.py": "1\n2\n3\n4\n5\n6\n7\n8\n"}, commit="Initial commit") paths["a.py"].write("1\n2\nthree\n4\n5\n6\nseven\n8\n") differ = EditedLinenumsDiffer(git_repo.root) @@ -113,9 +113,12 @@ def test_edited_linenums_differ_head_vs_worktree(git_repo, context_lines, expect @edited_linenums_differ_cases -def test_edited_linenums_differ_head_vs_lines(git_repo, context_lines, expect): +def test_edited_linenums_differ_revision_vs_lines(git_repo, context_lines, expect): + """Tests for EditedLinenumsDiffer.revision_vs_lines()""" git_repo.add({'a.py': '1\n2\n3\n4\n5\n6\n7\n8\n'}, commit='Initial commit') lines = ['1', '2', 'three', '4', '5', '6', 'seven', '8'] differ = EditedLinenumsDiffer(git_repo.root) + result = differ.revision_vs_lines(Path("a.py"), lines, context_lines) + assert result == expect