charm-build --write-lock-file fails to pick up master branch for interface:ceph-mds
Checklist
- [X] Confirmed this is an issue with charm-tools, not charmstore-client
- [X] Provide versions of tools used
- [X] Described the feature or ways to replicate the issue
What version am I running?
~I ran the following command: snap info charm and got the following ouput:~
charm-tools 2.8.3 from PyPi
I am using: Ubuntu 20.04
Issue/Feature
Adding a build.lock file is done with charm-build --log-level DEBUG --write-lock-file …
This creates the build.lock file and records the branch against the git hash for the repository for the layer/interface. However, it's doesn't seem to record a branch for interface:ceph-mds which results in bug #603 if the build.lock is attempted to be build using branches.
I expect/expected the following
I expected the branch refs/heads/master to be recorded against interface:ceph-mds
What I got
{
"type": "layer",
"item": "interface:ceph-mds",
"url": "https://opendev.org/openstack/charm-interface-ceph-client.git",
"vcs": null,
"branch": null,
"commit": "72245e1d002fb9c65c9574d65b5952275b3411fb"
},
Contrast with:
{
"type": "layer",
"item": "layer:ceph",
"url": "https://github.com/openstack/charm-layer-ceph.git",
"vcs": null,
"branch": "refs/heads/master",
"commit": "17d40abd8d9ec3b8c32756ca981c80c4733c016f"
},
The reason is fails to pick up the branch is due to interface:ceph-mds being a sub-directory-of-a-git-repository interface/layer which means that when it is copied the .git directory is not copied and so the branch can't be found. A bit of debug gives:
get_branch_for_revision: /home/alex/.cache/charm/2429380/interface/ceph-mds
... got error: fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
where get_branch_for_revision is (with some added debug):
def get_branch_for_revision(self, dir_, revision=None):
"""Returns None if the revision doesn't match the actual branch name"""
print("get_branch_for_revision:", dir_)
if revision is None:
revision = self.revision
if not revision:
print("... no revision?", revision)
return None
for cmd in ("git branch --contains {} --format=\"%(refname)\""
.format(revision), ):
try:
branch = check_output(cmd, cwd=dir_).decode('UTF-8').strip()
return branch
except FetchError as e:
print("... got error: ", e)
continue
return None
The fix will have to be to call get_branch_for_revision on the uncopied repository rather than the copied interface/layer. Might be tricky to organise that in the code.