Skip to content

[Bug]: CLI: TypeError: HEAD is a detached symbolic reference when repo is checked out with a tag #3722

@un-def

Description

@un-def

Steps to reproduce

  1. Clone dstack repo
  2. git checkout 0.20.15
  3. dstack apply -f examples/.dstack.yml

Actual behaviour

Traceback (most recent call last):
  File "dstack/.venv/bin/dstack", line 10, in <module>
    sys.exit(main())
             ~~~~^^
  File "dstack/src/dstack/_internal/cli/main.py", line 97, in main
    args.func(args)
    ~~~~~~~~~^^^^^^
  File "dstack/src/dstack/_internal/cli/commands/apply.py", line 98, in _command
    configurator.apply_configuration(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        conf=configuration,
        ^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        configurator_args=configurator_args,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "dstack/src/dstack/_internal/cli/services/configurators/run.py", line 101, in apply_configuration
    repo = self.get_repo(conf, configuration_path, configurator_args)
  File "dstack/src/dstack/_internal/cli/services/configurators/run.py", line 550, in get_repo
    repo = get_repo_from_dir(local_path)
  File "dstack/src/dstack/_internal/cli/services/repos.py", line 44, in get_repo_from_dir
    return RemoteRepo.from_dir(repo_dir)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "dstack/src/dstack/_internal/core/models/repos/remote.py", line 117, in from_dir
    return RemoteRepo(local_repo_dir=repo_dir)
  File "dstack/src/dstack/_internal/core/models/repos/remote.py", line 155, in __init__
    tracking_branch = repo.active_branch.tracking_branch()
                      ^^^^^^^^^^^^^^^^^^
  File "dstack/.venv/lib/python3.13/site-packages/git/repo/base.py", line 1054, in active_branch
    return self.head.reference
           ^^^^^^^^^^^^^^^^^^^
  File "dstack/.venv/lib/python3.13/site-packages/git/refs/symbolic.py", line 506, in reference
    return self._get_reference()
           ~~~~~~~~~~~~~~~~~~~^^
  File "dstack/.venv/lib/python3.13/site-packages/git/refs/symbolic.py", line 418, 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 '6f1f1f41848735c3a1c0d16a9efc8fdf291caca0'

Expected behaviour

No response

dstack version

0.20.15

Server logs

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions