()
| 175 | |
| 176 | |
| 177 | def main(): |
| 178 | args = parse_args() |
| 179 | main_branch = args.main |
| 180 | release_branch = args.release |
| 181 | |
| 182 | global verbosity |
| 183 | verbosity = args.verbose |
| 184 | |
| 185 | # Returns a list of hashes that are on the main branch but not the release |
| 186 | # branch. Each hash is preceded by `+ ` if the commit has not been cherry |
| 187 | # picked onto the release branch, or `- ` if it has. |
| 188 | cherry_lines = run_git(["cherry", release_branch, main_branch]) |
| 189 | print_wrapped( |
| 190 | f"Commits on '{main_branch}' that have already been cherry-picked into '{release_branch}':" |
| 191 | ) |
| 192 | if not cherry_lines: |
| 193 | print("- <none>") |
| 194 | candidate_commits = [] |
| 195 | for line in cherry_lines: |
| 196 | commit = Commit.from_line(line[2:]) |
| 197 | if line.startswith("+ "): |
| 198 | candidate_commits.append(commit) |
| 199 | elif line.startswith("- "): |
| 200 | print(f"- {commit}") |
| 201 | print("") |
| 202 | |
| 203 | # Filter out and print the commits that touch non-documentation files. |
| 204 | print_wrapped( |
| 205 | f"Will not pick these commits on '{main_branch}' that touch non-documentation files:" |
| 206 | ) |
| 207 | if not candidate_commits: |
| 208 | print("- <none>") |
| 209 | doc_only_commits = [] |
| 210 | for commit in candidate_commits: |
| 211 | if is_doc_only_commit(commit): |
| 212 | doc_only_commits.append(commit) |
| 213 | else: |
| 214 | print(f"- {commit}") |
| 215 | print("") |
| 216 | |
| 217 | # Print the commits to cherry-pick. |
| 218 | print_wrapped( |
| 219 | f"Remaining '{main_branch}' commits that touch only documentation files; " |
| 220 | + f"will be cherry-picked into '{release_branch}':" |
| 221 | ) |
| 222 | if not doc_only_commits: |
| 223 | print("- <none>") |
| 224 | for commit in doc_only_commits: |
| 225 | print(f"- {commit}") |
| 226 | print("") |
| 227 | |
| 228 | # Print instructions for cherry-picking the commits. |
| 229 | if doc_only_commits: |
| 230 | # Recommend a unique branch name. |
| 231 | suffix = datetime.datetime.utcnow().strftime("%Y%m%d%H%M") |
| 232 | branch_name = "cherrypick-" + release_branch.replace("/", "-") + "-" + suffix |
| 233 | |
| 234 | print("Cherry pick by running the commands:") |
no test coverage detected