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

Support of repo checkouts created by GIT worktree command #107

Open
steerpike68 opened this issue Nov 30, 2023 · 4 comments
Open

Support of repo checkouts created by GIT worktree command #107

steerpike68 opened this issue Nov 30, 2023 · 4 comments

Comments

@steerpike68
Copy link

steerpike68 commented Nov 30, 2023

When I checkout a KAS/Yocto based GIT repo branch into a working folder using the GIT worktree feature, the build fails at an early stage:

$ kas/kas-container -v --ssh-dir ${HOME}/.ssh build kas/project-latest.yml

  • docker run -v /<worktreefolder>:/repo:ro -v /<worktreefolder>:/work:rw -e KAS_WORK_DIR=/work -v /<worktreefolder>/build:/build:rw --workdir=/repo -e KAS_BUILD_DIR=/build -e USER_ID=1000 -e GROUP_ID=1000 --rm --init -v /${HOME}/.ssh:/var/kas/userdata/.ssh:ro -t -i -e TERM=xterm-256color -e SHELL=/bin/bash --log-driver=none --user=root ghcr.io/siemens/kas/kas:4.0 -d build /repo/kas/project-latest.yml
    2023-11-30 10:40:40 - INFO - kas 4.0 started
    2023-11-30 10:40:40 - DEBUG - Using selector: EpollSelector
    2023-11-30 10:40:40 - INFO - /repo/kas$ git rev-parse --show-toplevel
    2023-11-30 10:40:40 - INFO - /repo/kas$ hg root
    2023-11-30 10:40:40 - INFO - /repo/kas$ git rev-parse --show-toplevel
    2023-11-30 10:40:40 - INFO - /repo/kas$ hg root
    2023-11-30 10:40:40 - DEBUG - execute setup_dir
    2023-11-30 10:40:40 - DEBUG - execute setup_home
    2023-11-30 10:40:40 - DEBUG - execute init_setup_repos
    2023-11-30 10:40:40 - ERROR - Configuration file not found: /repo/kas/kas/includes/default-config.yml

I've replaced the name of my local worktree folder with <worktreefolder> in the command above. This path/folder contains a .git file which is pointing to the main repo this worktree is based upon. I assume that the current kas version instead expects a .git folder.

When I instead create the local folder by cloning the repo and checkout the correct branch, the same command works fine.

@jan-kiszka
Copy link
Collaborator

Kas includes are always repo-relative, referring to the root of the repo they are in. Maybe that helps already? Otherwise, we may need some set of config files to reproduce.

@steerpike68
Copy link
Author

OK, I don't think its a problem of the config files or if includes are used.
To reproduce, just take a simple kas-container based project you already have as a git repo with at least 2 different branches which I here call A and B. First clone the repo to folder /some_path/A/.git and check out branch A into A. Then cd to the folder A and start the kas-container build by the command you normally would use to build the project. That should work.
Then from folder A use command "git worktree add ../B B" to create a second checkout folder B of branch B. "git worktree list" should show now:
/some_path/A c-id [A]
/some_path/B c-id [B]
Then do "cd ../B" and use the same build command as used for folder/branch A. This should fail - even if that project doesn't use any includes at all.

@jan-kiszka
Copy link
Collaborator

Cannot confirm, even when using a kas file that comes with includes.

@gmcn42
Copy link

gmcn42 commented Dec 7, 2023

I am having the same issue @steerpike68 describes.

I think I may have found the reason: The .git file, which is generated in using git worktree add <worktree-path> only contains a reference to the original repo as an absolute path like

gitdir: /home/myhome/original-git-repo/.git/worktrees/linked-worktree-name

which will not be available inside the kas container as it only mounts the linked worktree to /repo, not the original repo.

We're seeing the error message because then git rev-parse --show-toplevel fails (as it's not actually a working git repo inside the container) and Repo.get_root_path returns the PWD as a fallback path:

def get_root_path(path, fallback=True):

This will work fine in situations where kas is started from the toplevel of the repo but not when it is started from a subdirectory.

Not sure if we can work around this sensibly as we'd need some hacky additional mounts into the container to make that .git reference work.

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

3 participants