Skip to content

Commit

Permalink
chore: add branch checkout before pretasks
Browse files Browse the repository at this point in the history
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
  • Loading branch information
jpower432 committed Aug 11, 2023
1 parent 604e501 commit bafffec
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions trestlebot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ def run(
commit_sha: str = ""
pr_number: int = 0

# Create Git Repo
repo = Repo(working_dir)

branch_names: List[str] = [b.name for b in repo.branches] # type: ignore
if branch in branch_names:
logger.debug(f"Local branch {branch} found")
repo.git.checkout(branch)
else:
logger.debug(f"Local branch {branch} created")
repo.git.checkout("-b", branch)

# Execute bot pre-tasks before committing repository updates
if pre_tasks is not None:
for task in pre_tasks:
Expand All @@ -128,9 +139,6 @@ def run(
except TaskException as e:
raise RepoException(f"Bot pre-tasks failed: {e}")

# Create Git Repo
repo = Repo(working_dir)

# Check if there are any unstaged files
if repo.is_dirty(untracked_files=True):
if check_only:
Expand Down

0 comments on commit bafffec

Please sign in to comment.