multiple calls of mbed update fail for branches containing a "/" character
- Dominant language
- Python
- Stars
- 339
- Forks
- 187
- PR merge metrics
- No merged PRs in 30d
Description
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/`. This reference is correctly mapped to remote branch `origin/`.
What happens during the `checkout`, though, is that git also creates a reference with the identifier `refs/heads/`.
If you issue another command which triggers this procedure again, the code in [2] now finds two references `refs/remotes/origin/` and `refs/heads/`, cuts them to `origin/`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/ 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] https://github.com/ARMmbed/mbed-cli/blob/76c92d07f77c8571e734e4ea122d51e93489893b/mbed/mbed.py#L783
[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
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in mbed/mbed.py around lines 782-784 and 910, then reproduce the reported sequence with a branch whose name contains '/'. Verify how the revision-to-reference mapping behaves after a prior checkout; done means repeated mbed update or mbed deploy can reassociate the revision with the correct remote branch without the pathspec error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, python
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100