Skip to content

Commit

Permalink
Merge pull request #2580 from m-rsha/diff-filter
Browse files Browse the repository at this point in the history
Change `intent_to_add_files` from using `git status` to `git diff`
  • Loading branch information
asottile committed Nov 3, 2022
2 parents 5840635 + 4bca29e commit 3ca9ea7
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions pre_commit/git.py
Expand Up @@ -150,18 +150,10 @@ def get_staged_files(cwd: str | None = None) -> list[str]:

def intent_to_add_files() -> list[str]:
_, stdout, _ = cmd_output(
'git', 'status', '--ignore-submodules', '--porcelain', '-z',
'git', 'diff', '--ignore-submodules', '--diff-filter=A',
'--name-only', '-z',
)
parts = list(reversed(zsplit(stdout)))
intent_to_add = []
while parts:
line = parts.pop()
status, filename = line[:3], line[3:]
if status[0] in {'C', 'R'}: # renames / moves have an additional arg
parts.pop()
if status[1] == 'A':
intent_to_add.append(filename)
return intent_to_add
return zsplit(stdout)


def get_all_files() -> list[str]:
Expand Down

0 comments on commit 3ca9ea7

Please sign in to comment.