':type args: CommonConfig
:type git: Git'

def __init__(self, args, git):

    self.args = args
    try:
        self.branch = os.environ['BRANCH']
        self.is_pr = (os.environ['IS_PULL_REQUEST'] == 'true')
        self.is_tag = (os.environ['IS_GIT_TAG'] == 'true')
        self.commit = os.environ['COMMIT']
        self.project_id = os.environ['PROJECT_ID']
    except KeyError as ex:
        raise MissingEnvironmentVariable(name=ex.args[0])
    if self.is_tag:
        raise ChangeDetectionNotSupported('Change    detection    is    not    supported    for    tags.')
    if self.is_pr:
        self.paths = sorted(git.get_diff_names([('origin/%s' % self.branch), '--']))
        self.diff = git.get_diff([('origin/%s' % self.branch), '--'])
    else:
        merge_runs = self.get_merge_runs(self.project_id, self.branch)
        last_successful_commit = self.get_last_successful_commit(git, merge_runs)
        if last_successful_commit:
            self.paths = sorted(git.get_diff_names([last_successful_commit, self.commit]))
            self.diff = git.get_diff([last_successful_commit, self.commit])
        else:
            self.paths = sorted(git.get_file_names(['--cached']))
            self.diff = []
