Skip to content

Commit 87b6419

Browse files
committed
Enh: Always make sure that we also git pull main branch
1 parent bfbf598 commit 87b6419

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

codeclash/games/game.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,30 @@ def get_environment(self, branch_name: str | None = None) -> DockerEnvironment:
199199
run_args=run_args,
200200
)
201201

202-
# Manually set URL with github token and git pull
202+
branch_name = self.game_id if branch_name is None else branch_name
203+
204+
# Manually set URL with github token and git fetch/pull everything
205+
# We won't raise an error if the token is not set or the URL doesn't have the right format.
203206
if github_token := os.getenv("GITHUB_TOKEN"):
204207
result = assert_zero_exit_code(environment.execute("git remote get-url origin"))
205208
current_url = result["output"].strip()
206209
if current_url.startswith("https://") and "@" not in current_url:
207210
new_url = current_url.replace("https://", f"https://{github_token}@")
208-
assert_zero_exit_code(environment.execute(f"git remote set-url origin {new_url} && git fetch origin"))
211+
assert_zero_exit_code(
212+
environment.execute(
213+
f"git remote set-url origin {new_url} && "
214+
f"git fetch --all origin && "
215+
f"git checkout {branch_name} && "
216+
f"git pull origin"
217+
)
218+
)
209219
else:
210220
self.logger.warning("Remote origin URL is not https://, won't be able to set token and pull.")
211221
else:
212222
self.logger.warning("GITHUB_TOKEN environment variable is not set, won't be able to pull.")
213223

214224
# Logger setting will likely not take effect for initial container creation logs
215225
environment.logger = get_logger("environment", emoji="🪴")
216-
# Ensure all future branches occur against branch
217-
branch_name = self.game_id if branch_name is None else branch_name
218226
for cmd in [
219227
f"git branch {branch_name}",
220228
f"git checkout {branch_name}",

0 commit comments

Comments
 (0)