mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 21:52:59 +00:00 
			
		
		
		
	Split git checks out into a separate command
`./go4it check-git' now verifies: - We're on the right branch. - We've no uncommited changes. - Each branch is up-to-date with the remote.
This commit is contained in:
		
							
								
								
									
										36
									
								
								go4it
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								go4it
									
									
									
									
									
								
							| @@ -79,30 +79,45 @@ def setup() -> None: | |||||||
|         pass |         pass | ||||||
|  |  | ||||||
|  |  | ||||||
| def build() -> None: | def check_git() -> None: | ||||||
|     """ |     """ | ||||||
|     Ensure the git repository is in a clean state. |     Check all worktrees are in a sensible state prior to merging. | ||||||
|     """ |     """ | ||||||
|     setup() |     setup() | ||||||
|  |  | ||||||
|     # Ensure every tree is clean. |     # Ensure every worktree is on the right branch, has no uncommited changes and is | ||||||
|  |     # up-to-date with the remote. | ||||||
|     ok = True |     ok = True | ||||||
|     for branch in BRANCHES: |     for branch in BRANCHES: | ||||||
|         status = git_in(branch, "status", "--porcelain", check=True, stdout=subprocess.PIPE).stdout |         status = git_in(branch, "status", "--porcelain", check=True, stdout=subprocess.PIPE).stdout | ||||||
|         if len(status.strip()) > 0: |         if len(status.strip()) > 0: | ||||||
|             log(f"{branch.name} has changes. Build will not continue.") |             log(f"{branch.name} has changes. Build will not continue.") | ||||||
|             ok = False |             ok = False | ||||||
|  |             continue | ||||||
|  |  | ||||||
|  |         actual_branch = git_in(branch, "rev-parse", "--abbrev-ref", "HEAD", check=True, stdout=subprocess.PIPE).stdout.decode("utf-8").strip() | ||||||
|  |         if actual_branch != branch.name: | ||||||
|  |             log(f"{branch.name} is actually on {actual_branch} right now") | ||||||
|  |             ok = False | ||||||
|  |             continue | ||||||
|  |  | ||||||
|  |         if git_in(branch, "merge-base", "--is-ancestor", f"origin/{branch.name}", branch.name).returncode != 0: | ||||||
|  |             log(f"{branch.name} is not up-to-date with remote.") | ||||||
|  |             ok = False | ||||||
|  |             continue | ||||||
|  |  | ||||||
|     if not ok: |     if not ok: | ||||||
|         sys.exit(1) |         sys.exit(1) | ||||||
|  |  | ||||||
|     # Ensure every tree is up-to-date. |  | ||||||
|     primary = BRANCHES[0] |  | ||||||
|     for branch in BRANCHES: |  | ||||||
|         if git_in(branch, "merge-base", "--is-ancestor", f"origin/{branch.name}", branch.name).returncode != 0: |  | ||||||
|             log(f"{branch.name} is not up-to-date with remote.") |  | ||||||
|             # TODO: We should possibly attempt to merge/rebase here instead of aborting. |  | ||||||
|             sys.exit(1) |  | ||||||
|  |  | ||||||
|  | def build() -> None: | ||||||
|  |     """ | ||||||
|  |     Merge in parent branches, then build all branches. | ||||||
|  |     """ | ||||||
|  |     check_git() | ||||||
|  |  | ||||||
|  |     # Merge each branch into the next one. | ||||||
|  |     for branch in BRANCHES: | ||||||
|         if ( |         if ( | ||||||
|             branch.parent is not None and |             branch.parent is not None and | ||||||
|             git_in(branch, "merge-base", "--is-ancestor", branch.parent, branch.name).returncode != 0 |             git_in(branch, "merge-base", "--is-ancestor", branch.parent, branch.name).returncode != 0 | ||||||
| @@ -151,6 +166,7 @@ def main() -> None: | |||||||
|         required=True, |         required=True, | ||||||
|     ) |     ) | ||||||
|     subparsers.add_parser("setup", help="Setup the git repository and build environment.").set_defaults(func=setup) |     subparsers.add_parser("setup", help="Setup the git repository and build environment.").set_defaults(func=setup) | ||||||
|  |     subparsers.add_parser("check-git", help="Check the git worktrees are in a state ready for merging.").set_defaults(func=check_git) | ||||||
|     subparsers.add_parser("build", help="Merge and build all branches.").set_defaults(func=build) |     subparsers.add_parser("build", help="Merge and build all branches.").set_defaults(func=build) | ||||||
|     subparsers.add_parser("release", help="Publish a release.").set_defaults(func=release) |     subparsers.add_parser("release", help="Publish a release.").set_defaults(func=release) | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates