Skip to content

Commit d2d2b68

Browse files
committed
Fix the prepare_branch function
Currently when checking if the destination branch already exists the command 'git branch' is used. This only returns local branches. What is actually required is the list of remote branches. This can be obtained by the command 'git branch -r' and filtering the result.
1 parent b5c53f4 commit d2d2b68

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tools/test/examples/update.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,19 @@ def prepare_branch(src, dst):
268268
update_log.debug("Preparing branch: %s", dst)
269269

270270
# Check if branch already exists or not.
271-
cmd = ['git', 'branch']
271+
# We can use the 'git branch -r' command. This returns all the remote branches for
272+
# the current repo.
273+
# The output consists of a list of lines of the form:
274+
# origin/<branch>
275+
# From these we need to extract just the branch names to a list and then check if
276+
# the specified dst exists in that list
277+
branches = []
278+
cmd = "git branch -r"
272279
_, output = run_cmd_with_output(cmd, exit_on_failure=True)
273280

274-
if not dst in output:
281+
branches = [line.split('/')[1] for line in output.split('\n') if 'origin' in line and not '->' in line]
282+
283+
if not dst in branches:
275284

276285
# OOB branch does not exist thus create it, first ensuring we are on
277286
# the src branch and then check it out

0 commit comments

Comments
 (0)