Skip to content

multiple calls of mbed update fail for branches containing a "/" character #995

@zimjjan

Description

@zimjjan

We are using a local fork of mbed-os for our projects as we rely on an older version but have to backport some changes from time to time.

If we reference a certain commit in mbed-os.lib which also happens to be the HEAD of a certain branch, if the branch contains a / char in its name, mbed update fails if mbed-os has been checked out once before (see log at the end).

This is caused by mbed-cli trying to map revisions to refs and from there to branches.

If you issue a command (e.g., mbed update; mbed deploy, which triggers the checkout of a certain revision that also is the HEAD of a branch, this mapping normally results in one reference refs/remotes/origin/<branch>. This reference is correctly mapped to remote branch origin/<branch>.

What happens during the checkout, though, is that git also creates a reference with the identifier refs/heads/<branch>.

If you issue another command which triggers this procedure again, the code in [2] now finds two references refs/remotes/origin/<branch> and refs/heads/<branch>, cuts them to origin/<branch>and `´ (see [3]) and returns them with the latter one being the first in the returned list.

If now the branch contained a /, regex [3] will match for it and only the part after the slash will falsely be considered the branch name.
The comment for the match in [1] says: # matches origin/<branch> and isn't HEAD ref
however, this time - as origin is omitted - this is not true, so a none-existing branch will be checkout and this obviously fails.

Fix: Regex in [3] should check for origin/ instead of /. Then [4] can correctly identify and filter it.

[1]

if m and m.group(2) != "HEAD": # matches origin/<branch> and isn't HEAD ref

[2} https://github.com/ARMmbed/mbed-cli/blob/76c92d07f77c8571e734e4ea122d51e93489893b/mbed/mbed.py#L910
[3] https://github.com/ARMmbed/mbed-cli/blob/76c92d07f77c8571e734e4ea122d51e93489893b/mbed/mbed.py#L782
[4] https://github.com/ARMmbed/mbed-cli/blob/76c92d07f77c8571e734e4ea122d51e93489893b/mbed/mbed.py#L784

Error log:

mbed update -vvvvv
[mbed] Working path "/home/xxx/git/xxx" (program)
[mbed] Updating program "xxx" to latest revision in the current branch
[mbed] Fetching revisions from remote repository to "xxx"
[mbed] Exec "git fetch --all --tags --force" in "/home/xxx/git/xxx"
Fetching origin
[mbed] Merging "xxx" with "origin/hotfix/set-lsedrv"
[mbed] Exec "git merge origin/hotfix/set-lsedrv" in "/home/xxx/git/LoRaTLSv2"
Already up to date.
[mbed] Updating library "mbed-os" to rev #e75915e866fb
[mbed] Fetching revisions from remote repository to "mbed-os"
[mbed] Exec "git fetch --all --tags --force" in "/home/xxx/git/xxx/mbed-os"
Fetching origin
[mbed] Checkout "e75915e866fbe17151a5e50048d4794805d42d04" in mbed-os
[mbed] Revision "e75915e866fbe17151a5e50048d4794805d42d04" matches a branch "set-lsedrv" reference. Re-associating with branch
[mbed] Exec "git checkout set-lsedrv -q" in "/home/xxx/git/xxx/mbed-os"
error: pathspec 'set-lsedrv' did not match any file(s) known to git
[mbed] ERROR: Unable to update "mbed-os" to rev #e75915e866fb

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions