(a_dir: str, b_dir: str, webdiff_config)
| 43 | |
| 44 | |
| 45 | def gitdiff(a_dir: str, b_dir: str, webdiff_config): |
| 46 | extra_args = webdiff_config['extraDirDiffArgs'] |
| 47 | cmd = 'git diff --raw -z --no-index --numstat' |
| 48 | if extra_args: |
| 49 | cmd += ' ' + extra_args |
| 50 | a_dir_nosym = a_dir |
| 51 | if contains_symlinks(a_dir): |
| 52 | a_dir_nosym = make_resolved_dir(a_dir, follow_symlinks=True) |
| 53 | logging.debug(f'Inlined symlinks in left directory {a_dir} -> {a_dir_nosym}') |
| 54 | b_dir_nosym = b_dir |
| 55 | if contains_symlinks(b_dir): |
| 56 | b_dir_nosym = make_resolved_dir(b_dir, follow_symlinks=True) |
| 57 | logging.debug(f'Inlined symlinks in right directory {b_dir} -> {b_dir_nosym}') |
| 58 | args = cmd.split(' ') + [a_dir_nosym, b_dir_nosym] |
| 59 | logging.debug('Running git command: %s', args) |
| 60 | diff_output = subprocess.run(args, capture_output=True) |
| 61 | # git diff has an exit code of 1 on either a diff _or_ an error. |
| 62 | # TODO: how to distinguish these cases? |
| 63 | diff_stdout = diff_output.stdout.decode('utf8') |
| 64 | # Make it look like the diff was between directories containing symlinks. |
| 65 | # After this point, the resolved directories are no longer needed. |
| 66 | if a_dir != a_dir_nosym: |
| 67 | diff_stdout = diff_stdout.replace(a_dir_nosym, a_dir) |
| 68 | shutil.rmtree(a_dir_nosym) |
| 69 | if b_dir != b_dir_nosym: |
| 70 | diff_stdout = diff_stdout.replace(b_dir_nosym, b_dir) |
| 71 | shutil.rmtree(b_dir_nosym) |
| 72 | lines = parse_raw_diff(diff_stdout) |
| 73 | return [LocalFileDiff.from_diff_raw_line(line, a_dir, b_dir) for line in lines] |
nothing calls this directly
no test coverage detected