Managed snapping of craft applications from a `git worktree` will fail
Metadata
Current evaluation
Rejected. The craft team decided not to support git worktrees in managed environments due to container path resolution issues. The issue was closed without a fix.
Suggested action: —
No scores available.
Issue body
### Bug Description
When a branch exists in a `git worktree`, rather than a `.git` directory it will have a file called `.git`. This file contains text like so: `gitdir: /home/mrc/dev/main/foocraft/.git/worktrees/name-of-this-branch`.
So when the project directory is mounted inside the managed environment, this file (a "fake symlink") no longer points to a valid path, making any tools which need to operate on this as a git repo fail - in this case, `setuptools_scm`.
Mounting happens in `craft_application/services/provider.py:123`.
Possible solutions:
- Mount the main repo dir at the path pointed at by the fake symlink.
- Mount the main repo dir elsewhere, and rewrite the path in the fake symlink.
- Replace the fake symlink with the dir it points at.
It's possible that the solution could be more in `craft-providers` than `craft-application`.
### To Reproduce
```
$ cd ~/code
$ git clone foocraft
$ cd foocraft
$ git worktree add ~/code/new-branch
$ cd ~/code/new-branch
$ snapcraft
```
### part yaml
_No response_
### Relevant log output
```shell
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:36.926 :: Successfully installed Deprecated-1.2.14 PyYAML-6.0.2 annotated-types-0.7.0 boolean.py-4.0 certifi-2023.11.17 cffi-1.17.1 chardet-5.2.0 charset-normalizer-3.1.0 craft-application-4.3.0 craft-archives-2.0.1 craft-cli-2.8.0 craft-grammar-2.0.1 craft-parts-2.1.2 craft-platforms-0.3.1 craft-providers-2.0.4 distro-1.9.0 frozendict-2.4.6 httplib2-0.22.0 idna-3.4 importlib-metadata-6.6.0 launchpadlib-2.0.0 lazr.restfulclient-0.14.6 lazr.uri-1.0.6 license-expression-30.4.0 mergedeep-1.3.4 oauthlib-3.2.2 overrides-7.7.0 packaging-24.2 pefile-2023.2.7 platformdirs-4.2.2 pycparser-2.22 pydantic-2.9.2 pydantic-core-2.23.4 pydantic-yaml-1.4.0 pygit2-1.14.1 pyparsing-3.2.0 python-apt-2.7.0 python-debian-0.1.49 pyxdg-0.28 requests-2.32.3 requests-unixsocket2-0.4.2 ruamel.yaml-0.18.6 ruamel.yaml.clib-0.2.12 sh-2.0.4 shyaml-0.6.2 six-1.16.0 snap-helpers-0.4.2 types-Deprecated-1.2.9.20240311 types-PyYAML-6.0.12.20240917 typing-extensions-4.11.0 urllib3-2.2.3 wadllib-2.0.0 wrapt-1.15.0 zipp-3.15.0
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:37.314 :: + '[' -f setup.py ']'
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:37.314 :: + '[' -f pyproject.toml ']'
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:37.314 :: + /root/parts/foocraft/install/bin/pip install -U .
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:37.548 :: Processing /root/parts/foocraft/build
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:37.551 :: Installing build dependencies: started
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:38.950 :: Installing build dependencies: finished with status 'done'
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:38.951 :: Getting requirements to build wheel: started
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:39.057 :: Getting requirements to build wheel: finished with status 'error'
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:39.063 :: error: subprocess-exited-with-error
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:39.063 ::
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:39.063 :: × Getting requirements to build wheel did not run successfully.
2024-11-15 10:07:40.734 :: 2024-11-15 10:07:39.063 :: │ exit code: 1
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: ╰─> [35 lines of output]
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: Traceback (most recent call last):
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: File "/root/parts/foocraft/install/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: main()
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: File "/root/parts/foocraft/install/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: json_out['return_val'] = hook(**hook_input['kwargs'])
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: File "/root/parts/foocraft/install/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: return hook(config_settings)
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: File "/tmp/pip-build-env-t5177_aw/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_wheel
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: return self._get_build_requires(config_settings, requirements=[])
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: File "/tmp/pip-build-env-t5177_aw/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: self.run_setup()
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: File "/tmp/pip-build-env-t5177_aw/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 320, in run_setup
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: exec(code, locals())
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: File "<string>", line 1, in <module>
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.063 :: File "/tmp/pip-build-env-t5177_aw/overlay/lib/python3.10/site-packages/setuptools/__init__.py", line 117, in setup
2024-11-15 10:07:40.735 :: 2024-11-15 10:07:39.064 :: return distutils.core.setup(**attrs)
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: File "/tmp/pip-build-env-t5177_aw/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 145, in setup
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: _setup_distribution = dist = klass(attrs)
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: File "/tmp/pip-build-env-t5177_aw/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 319, in __init__
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: _Distribution.__init__(self, dist_attrs)
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: File "/tmp/pip-build-env-t5177_aw/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 279, in __init__
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: self.finalize_options()
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: File "/tmp/pip-build-env-t5177_aw/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 677, in finalize_options
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: ep(self)
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: File "/tmp/pip-build-env-t5177_aw/overlay/lib/python3.10/site-packages/setuptools_scm/_integration/setuptools.py", line 123, in infer_version
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: _assign_version(dist, config)
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: File "/tmp/pip-build-env-t5177_aw/overlay/lib/python3.10/site-packages/setuptools_scm/_integration/setuptools.py", line 58, in _assign_version
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: _version_missing(config)
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: File "/tmp/pip-build-env-t5177_aw/overlay/lib/python3.10/site-packages/setuptools_scm/_get_version_impl.py", line 117, in _version_missing
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: raise LookupError(
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: LookupError: setuptools-scm was unable to detect version for /root/parts/foocraft/build.
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 ::
2024-11-15 10:07:40.736 :: 2024-11-15 10:07:39.064 :: Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work.
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.064 ::
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.064 :: For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.064 :: [end of output]
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.064 ::
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.064 :: note: This error originates from a subprocess, and is likely not a problem with pip.
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.108 :: error: subprocess-exited-with-error
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.108 ::
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.108 :: × Getting requirements to build wheel did not run successfully.
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.108 :: │ exit code: 1
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.108 :: ╰─> See above for output.
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.108 ::
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.108 :: note: This error originates from a subprocess, and is likely not a problem with pip.
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.156 :: error:
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.156 :: Traceback (most recent call last):
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.156 :: File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/ctl.py", line 110, in main
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.156 :: ret = CraftCtl.run(cmd, args)
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.156 :: File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/ctl.py", line 44, in run
2024-11-15 10:07:40.737 :: 2024-11-15 10:07:39.156 :: _client(cmd, args)
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.156 :: File "/snap/snapcraft/current/lib/python3.10/site-packages/craft_parts/ctl.py", line 97, in _client
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.156 :: raise RuntimeError(message)
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.156 :: RuntimeError: Failed to run the build script for part 'foocraft'.
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.357 'override-build' in part 'foocraft' failed with code 1.
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.357 Review the scriptlet and make sure it's correct.
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 Traceback (most recent call last):
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/snapcraft/application.py", line 495, in main
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 return app.run()
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_application/application.py", line 568, in run
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 return_code = self._run_inner()
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/snapcraft/application.py", line 215, in _run_inner
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 return_code = super()._run_inner()
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_application/application.py", line 515, in _run_inner
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 dispatcher = self._get_dispatcher()
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/snapcraft/application.py", line 443, in _get_dispatcher
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 self._check_for_classic_fallback()
2024-11-15 10:07:40.738 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/snapcraft/application.py", line 355, in _check_for_classic_fallback
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 raise errors.ClassicFallback()
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 snapcraft.errors.ClassicFallback
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 During handling of the above exception, another exception occurred:
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 Traceback (most recent call last):
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/snapcraft/parts/parts.py", line 219, in run
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 aex.execute(action, stdout=stream, stderr=stream)
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_parts/executor/executor.py", line 324, in execute
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 self._executor.execute(actions, stdout=stdout, stderr=stderr)
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_parts/executor/executor.py", line 136, in execute
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 self._run_action(act, stdout=stdout, stderr=stderr)
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_parts/executor/executor.py", line 211, in _run_action
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 handler.run_action(action, stdout=stdout, stderr=stderr)
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_parts/executor/part_handler.py", line 171, in run_action
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 state = handler(step_info, stdout=stdout, stderr=stderr)
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.360 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_parts/executor/part_handler.py", line 310, in _run_build
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.361 self._run_step(
2024-11-15 10:07:40.739 :: 2024-11-15 10:07:39.361 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_parts/executor/part_handler.py", line 485, in _run_step
2024-11-15 10:07:40.740 :: 2024-11-15 10:07:39.361 step_handler.run_scriptlet(
2024-11-15 10:07:40.740 :: 2024-11-15 10:07:39.361 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_parts/executor/step_handler.py", line 330, in run_scriptlet
2024-11-15 10:07:40.740 :: 2024-11-15 10:07:39.361 raise errors.ScriptletRunError(
2024-11-15 10:07:40.740 :: 2024-11-15 10:07:39.361 craft_parts.errors.ScriptletRunError: 'override-build' in part 'foocraft' failed with code 1.
2024-11-15 10:07:40.740 :: 2024-11-15 10:07:39.361 Review the scriptlet and make sure it's correct.
2024-11-15 10:07:40.740 Executing on host: lxc --project snapcraft config device show local:snapcraft-foocraft-on-amd64-for-amd64-59665059
2024-11-15 10:07:40.786 Executing on host: lxc --project snapcraft config device remove local:snapcraft-foocraft-on-amd64-for-amd64-59665059 disk-/root/project
2024-11-15 10:07:40.891 Executing on host: lxc --project snapcraft stop local:snapcraft-foocraft-on-amd64-for-amd64-59665059
2024-11-15 10:07:44.803 Failed to execute pack in instance.
2024-11-15 10:07:44.808 Traceback (most recent call last):
2024-11-15 10:07:44.808 File "/snap/snapcraft/12961/lib/python3.10/site-packages/snapcraft/application.py", line 495, in main
2024-11-15 10:07:44.808 return app.run()
2024-11-15 10:07:44.808 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_application/application.py", line 568, in run
2024-11-15 10:07:44.808 return_code = self._run_inner()
2024-11-15 10:07:44.808 File "/snap/snapcraft/12961/lib/python3.10/site-packages/snapcraft/application.py", line 215, in _run_inner
2024-11-15 10:07:44.808 return_code = super()._run_inner()
2024-11-15 10:07:44.808 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_application/application.py", line 515, in _run_inner
2024-11-15 10:07:44.808 dispatcher = self._get_dispatcher()
2024-11-15 10:07:44.808 File "/snap/snapcraft/12961/lib/python3.10/site-packages/snapcraft/application.py", line 443, in _get_dispatcher
2024-11-15 10:07:44.808 self._check_for_classic_fallback()
2024-11-15 10:07:44.808 File "/snap/snapcraft/12961/lib/python3.10/site-packages/snapcraft/application.py", line 355, in _check_for_classic_fallback
2024-11-15 10:07:44.808 raise errors.ClassicFallback()
2024-11-15 10:07:44.808 snapcraft.errors.ClassicFallback
2024-11-15 10:07:44.808
2024-11-15 10:07:44.808 During handling of the above exception, another exception occurred:
2024-11-15 10:07:44.808 Traceback (most recent call last):
2024-11-15 10:07:44.808 File "/snap/snapcraft/12961/lib/python3.10/site-packages/snapcraft/parts/lifecycle.py", line 538, in _run_in_provider
2024-11-15 10:07:44.808 instance.execute_run(cmd, check=True, cwd=output_dir)
2024-11-15 10:07:44.808 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_providers/lxd/lxd_instance.py", line 293, in execute_run
2024-11-15 10:07:44.808 return self.lxc.exec(
2024-11-15 10:07:44.808 File "/snap/snapcraft/12961/lib/python3.10/site-packages/craft_providers/lxd/lxc.py", line 387, in exec
2024-11-15 10:07:44.808 return runner(final_cmd, timeout=timeout, check=check, **kwargs)
2024-11-15 10:07:44.808 File "/snap/snapcraft/12961/usr/lib/python3.10/subprocess.py", line 526, in run
2024-11-15 10:07:44.808 raise CalledProcessError(retcode, process.args,
2024-11-15 10:07:44.808 subprocess.CalledProcessError: Command '['lxc', '--project', 'snapcraft', 'exec', 'local:snapcraft-foocraft-on-amd64-for-amd64-59665059', '--cwd', '/root/project', '--', 'env', 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin', 'CRAFT_MANAGED_MODE=1', 'DEBIAN_FRONTEND=noninteractive', 'DEBCONF_NONINTERACTIVE_SEEN=true', 'DEBIAN_PRIORITY=critical', 'snapcraft', 'pack', '--verbosity=trace', '--build-for', 'amd64']' returned non-zero exit status 1.
2024-11-15 10:07:44.808 Recommended resolution: Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
2024-11-15 10:07:44.808 Full execution log: '/home/mrc/.local/state/snapcraft/log/snapcraft-20241115-100626.147103.log'
```
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen/qwen3.6-35b-a3b | — | — | Rejected. The craft team decided not to support git worktrees in managed environments due to container path resolution issues. The issue was closed without a fix. | |
| qwen/qwen3.6-35b-a3b | — | — | The craft team rejected support for git worktrees. The issue was closed after planning determined the feature would not be implemented, leaving the managed environment path resolution bug unresolved. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Rejected during planning. The craft team decided not to support git worktrees in managed environments, closing the issue without a fix. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1889535 Error is shown when git version is determined in a git worktree | snapcraft (launchpad) | closed | Closed without resolution. Reported a snapcraft git version detection failure in worktrees caused by the build VM lacking access to the parent repository. No fix was implemented. |