Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run build_related_scripts/get_modified_packs.py from detached HEAD #28

Open
tlium opened this issue Jan 18, 2024 · 1 comment
Open

Comments

@tlium
Copy link

tlium commented Jan 18, 2024

The script build_related_scripts/get_modified_packs.py doesn't support detached HEAD states in the Git repository. Easily reproduced by doing

git checkout -d <SHA hash of some commit>
python build_relates_scripts/get_modified_packs.py

You'll see something like this error message:

Traceback (most recent call last):
  File "/path/to/repo/build_related_scripts/get_modified_packs.py", line 75, in <module>
    main()
  File "/path/to/repo/build_related_scripts/get_modified_packs.py", line 66, in main
    changed_files = get_changed_files(repo_path, prev_ver)
  File "/path/to/repo/build_related_scripts/get_modified_packs.py", line 47, in get_changed_files
    if str(repo.active_branch) == prev_ver:
  File "/path/to/repo/venv/lib/python3.10/site-packages/git/repo/base.py", line 897, in active_branch
    return self.head.reference
  File "/path/to/repo/venv/lib/python3.10/site-packages/git/refs/symbolic.py", line 357, in _get_reference
    raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha))
TypeError: HEAD is a detached symbolic reference as it points to '38f6f91734837fe79b80ecef68c96678daa67bef'

Tried to wrap the offending if-clause with a try/except, and it works for me. Unsure if it's the best way to fix the problem

    try:
        if str(repo.active_branch) == prev_ver:
            # Get the latest commit in master, prior the merge.
            commits_list = list(repo.iter_commits())
            prev_ver = str(commits_list[1])
    except TypeError:
        pass
@mmhw
Copy link
Contributor

mmhw commented Feb 19, 2024

Hi @tlium I have now added a patch to the get_modified_packs.py file that should solve your issue, I would appreciate it if you could check and confirm that it is indeed solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants