Skip to content

Commit

Permalink
"HEAD" -> "given revision" in comments and tests
Browse files Browse the repository at this point in the history
These were missed in #43. Fix them now in this MR even though they are
unrelated. Will get reviewed in the same go and fixed in time for the
1.1.0 release.
  • Loading branch information
akaihola committed Aug 13, 2020
1 parent b485b9c commit a7a1b94
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/darker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/darker/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 6 additions & 3 deletions src/darker/tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit a7a1b94

Please sign in to comment.