Skip to content

Commit 030c2d1

Browse files
committed
test branch switch for fetch_and_merge
1 parent e21c4ea commit 030c2d1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

scripts/shared.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,23 @@ def log_paths(logger, paths):
6060
logger.info(f"PATHS:{paths_list}")
6161

6262

63-
def fetch_and_merge(repo_path, branch="gsoc2024-dev-1"):
63+
def fetch_and_merge(repo_path, branch=None):
6464
try:
6565
repo = Repo(repo_path)
6666
origin = repo.remote(name="origin")
6767
origin.fetch()
68+
69+
# Determine the branch to use
70+
if branch is None:
71+
# Use the current branch if no branch is provided
72+
branch = repo.active_branch.name if repo.active_branch else "main"
73+
74+
# Ensure that the branch exists in the remote
75+
if f"origin/{branch}" not in [ref.name for ref in repo.refs]:
76+
raise ValueError(
77+
f"Branch '{branch}' does not exist in remote 'origin'"
78+
)
79+
6880
repo.git.merge(f"origin/{branch}", allow_unrelated_histories=True)
6981
logging.info(f"Fetched and merged latest changes from {branch}")
7082
except InvalidGitRepositoryError:

0 commit comments

Comments
 (0)