Get the list of changed or added files from git.
(base_branch=None)
| 137 | @status("Getting the list of files that have been added/changed", |
| 138 | info=lambda x: n_files_str(len(x))) |
| 139 | def changed_files(base_branch=None): |
| 140 | """Get the list of changed or added files from git.""" |
| 141 | if os.path.exists(os.path.join(SRCDIR, '.git')): |
| 142 | # We just use an existence check here as: |
| 143 | # directory = normal git checkout/clone |
| 144 | # file = git worktree directory |
| 145 | if base_branch: |
| 146 | cmd = 'git diff --name-status ' + base_branch |
| 147 | else: |
| 148 | cmd = 'git status --porcelain' |
| 149 | filenames = [] |
| 150 | with subprocess.Popen(cmd.split(), |
| 151 | stdout=subprocess.PIPE, |
| 152 | cwd=SRCDIR) as st: |
| 153 | git_file_status, _ = st.communicate() |
| 154 | if st.returncode != 0: |
| 155 | sys.exit(f'error running {cmd}') |
| 156 | for line in git_file_status.splitlines(): |
| 157 | line = line.decode().rstrip() |
| 158 | status_text, filename = line.split(maxsplit=1) |
| 159 | status = set(status_text) |
| 160 | # modified, added or unmerged files |
| 161 | if not status.intersection('MAU'): |
| 162 | continue |
| 163 | if ' -> ' in filename: |
| 164 | # file is renamed |
| 165 | filename = filename.split(' -> ', 2)[1].strip() |
| 166 | filenames.append(filename) |
| 167 | else: |
| 168 | sys.exit('need a git checkout to get modified files') |
| 169 | |
| 170 | return list(map(os.path.normpath, filenames)) |
| 171 | |
| 172 | |
| 173 | @status("Docs modified", modal=True) |
no test coverage detected
searching dependent graphs…