def changed_files()

in pantri/scripts/lib/utils.py [0:0]


def changed_files():
    """
  changed_files()

  Returns (added, modified, deleted) files between git pulls.
  Code copied from: fbcode/scm/lib/gitrepo.py and changed to use GitPython
  """
    added = []
    modified = []
    deleted = []
    repo_path = get_paths()["repo_root"]
    previous_commit_id, current_commit_id = get_git_commits()

    # Commit id of all zeros indicates repo was just cloned, therefore don't dont
    # need to check what files changed.
    if previous_commit_id == "0000000000000000000000000000000000000000":
        return (added, modified, deleted)

    # Parse diff tree to determine which files where changed between git pulls
    parts = (
        git.Git(repo_path)
        .diff_tree(
            [
                "--name-status",
                "-z",
                "--root",
                "-m",
                "-r",
                previous_commit_id,
                current_commit_id,
            ]
        )
        .split("\0")
    )

    # Loop though changes files and determine changed/added/deleted files.
    # Logic copied from fbcode.
    offset = 0
    while offset < len(parts) - 1:
        kind = parts[offset]
        path = parts[offset + 1]

        if len(kind) == 40:
            # It's a merge commit and diff-tree prints the diff between
            # both parents (separated by the commit hash). Just skip the
            # hash return a list of all the files that have changed.
            offset += 1
            continue

        offset += 2

        if kind == "M" or kind == "T":
            modified.append(path)
        elif kind == "A":
            added.append(path)
        elif kind == "D":
            deleted.append(path)
    return (added, modified, deleted)