Skip to content

Commit

Permalink
env: Fix a few places that add and remove git worktrees with systemd-…
Browse files Browse the repository at this point in the history
…nspawn

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
  • Loading branch information
nathanchance committed Dec 31, 2024
1 parent 675bde7 commit 6b024f2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
8 changes: 7 additions & 1 deletion fish/functions/cbl_upd_stbl_wrktrs.fish
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ function cbl_upd_stbl_wrktrs -d "Update the worktrees for linux-stable"
set stable_version (string split -f 3 '-' $basename)
if not contains $stable_version $stable_versions
header "Removing $worktree"
git -C $folder worktree remove --force $worktree
# Non-temporal git worktrees need to use the host path, as the
# have been converted to the host path below.
git -C $folder worktree remove --force (nspawn_path -H $worktree)
git -C $folder bd linux-$stable_version.y

if test $dirname = $CBL_SRC_P
Expand All @@ -48,5 +50,9 @@ function cbl_upd_stbl_wrktrs -d "Update the worktrees for linux-stable"
git -C $folder worktree add --track -b $branch $worktree origin/$branch
end
end

# We need to ensure the git worktree links are valid for both
# host and systemd-nspawn
fix_wrktrs_for_nspawn $folder
end
end
11 changes: 11 additions & 0 deletions fish/functions/fix_wrktrs_for_nspawn.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env fish
# SPDX-License-Identifier: MIT
# Copyright (C) 2024 Nathan Chancellor

function fix_wrktrs_for_nspawn -d 'Fix worktree paths in gitdir files created within systemd-nspawn'
PYTHONPATH=$PYTHON_FOLDER python3 -c 'import lib.utils, sys
from pathlib import Path
for arg in sys.argv[1:]:
lib.utils.'(status function)'(Path(arg))' $argv
end
9 changes: 9 additions & 0 deletions python/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ def detect_virt(*args):
return chronic(['systemd-detect-virt', *args], check=False).stdout.strip()


def fix_wrktrs_for_nspawn(git_repo):
if not git_repo.joinpath('.git').is_dir():
raise RuntimeError(f"{git_repo} does not appear to be a git repository?")
for gitdir in git_repo.glob('.git/worktrees/*/gitdir'):
# Transform '/run/host/home/...' into '/home/...'
if (gitdir_txt := gitdir.read_text(encoding='utf-8')).startswith('/run/host/'):
gitdir.write_text(gitdir_txt[len('/run/host'):], encoding='utf-8')


def fzf(header, fzf_input, fzf_args=None):
fzf_cmd = ['fzf', '--header', header, '--multi']
if fzf_args:
Expand Down
8 changes: 6 additions & 2 deletions python/scripts/cbl_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_report_repo():


def get_report_worktree():
return Path(os.environ['CBL'], 'current-report')
return Path(os.environ['CBL'].removeprefix('/run/host'), 'current-report')


def parse_parameters():
Expand Down Expand Up @@ -724,7 +724,10 @@ def finalize_report(args):

# Remove worktree ('--force' due to submodules)
if args.remove_worktree or args.all:
lib.utils.call_git(repo, ['worktree', 'remove', '--force', worktree], show_cmd=True)
lib.utils.call_git(repo,
['worktree', 'remove', '--force',
worktree.removeprefix('/run/host')],
show_cmd=True)

# Delete branch locally and remotely if necessary
if args.delete_branch or args.all:
Expand Down Expand Up @@ -770,6 +773,7 @@ def new_report(args):

# Create worktree
lib.utils.call_git(repo, worktree_add, show_cmd=True)
lib.utils.fix_wrktrs_for_nspawn(repo)

# Push new branch if needed
if (args.push or args.all) and push_to_remote:
Expand Down

0 comments on commit 6b024f2

Please sign in to comment.