From e6b6b4938e4c61e295dd64515ec2f3e9c83147b1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 26 Sep 2026 13:38:50 +0200 Subject: [PATCH 1/3] please.sh create-sdk-artifacts: allow reusing an existing worktree It is often necessary to update a, say, `build-installers` worktree with a newer tip commit. So far, I have done this via `--force`, which deletes and then recreates the worktree. However, I often try to replicate locally what CI runs do, e.g. checking out `build-extra` into `/usr/src/`. And that would be gone with `--force`. Also, it is highly inefficient to throw away so many files only to rewrite most of them in the identical way. So let's introduce a `--reuse` option that will allow to do exactly that: It expects an already-initialized directory, update it as desired, with a `git reset --hard` to finish the update. This option implies `--keep-worktree`. Signed-off-by: Johannes Schindelin --- please.sh | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/please.sh b/please.sh index 5eec3042de..2aceca5e4d 100755 --- a/please.sh +++ b/please.sh @@ -399,6 +399,7 @@ create_sdk_artifact () { # [--out=] [--git-sdk=] [--archit git_sdk_path=/ output_path= force= + reuse= architecture=auto bitness= keep_worktree= @@ -444,6 +445,10 @@ create_sdk_artifact () { # [--out=] [--git-sdk=] [--archit --force|-f) force=t ;; + --reuse) + reuse=t + keep_worktree=t + ;; --keep-worktree) keep_worktree=t ;; @@ -530,8 +535,14 @@ create_sdk_artifact () { # [--out=] [--git-sdk=] [--archit *) die "Unhandled artifact: '%s'\n" "$1";; esac - test ! -d "$output_path" || - if test -z "$force" + if test ! -d "$output_path" + then + test -z "$reuse" || + die "Cannot reuse non-existing directory '%s'\n" "$output_path" + elif test -n "$reuse" + then + echo "Trying to reuse $output_path" >&2 + elif test -z "$force" then die "Directory exists already: '%s'\n" "$output_path" elif test -f "$output_path/.git" @@ -570,7 +581,32 @@ create_sdk_artifact () { # [--out=] [--git-sdk=] [--archit git -C "$git_sdk_path" config core.repositoryFormatVersion 1 && git -C "$git_sdk_path" config extensions.worktreeConfig true && - git -C "$git_sdk_path" worktree add --detach --no-checkout "$output_path" HEAD && + if test -n "$reuse" + then + if test ! -e "$output_path"/.git + then + wgd="$git_sdk_path/worktrees/${output_path##*/}" && + if test -d "$wgd" + then + n=1 && + while test -d "$wgd-$n" + do + n=$(($n+1)) + done && + wgd="$wgd-$n" + fi && + mkdir -p "$wgd/refs" && + git -C "$git_sdk_path" rev-parse HEAD >"$wgd/HEAD" && + echo '../..' >"$wgd/commondir" && + cygpath -am "$output_path/.git" >"$wgd/gitdir" && + echo "gitdir: $wgd" >"$output_path/.git" + fi && + git -C "$output_path" ls-files -z | + xargs -0r git -C "$output_path" rm --sparse && + git -C "$output_path" update-ref HEAD "$(git -C "$git_sdk_path" rev-parse HEAD)" + else + git -C "$git_sdk_path" worktree add --detach --no-checkout "$output_path" HEAD + fi && sparse_checkout_file="$(git -C "$output_path" rev-parse --git-path info/sparse-checkout)" && git -C "$output_path" config --worktree core.sparseCheckout true && git -C "$output_path" config --worktree core.bare false && From 77ce3d0752a39b08eedc77d46591da05b51de585 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 26 Sep 2026 13:43:06 +0200 Subject: [PATCH 2/3] please.sh create-sdk-artifact: allow deviating from HEAD Sometimes I am operating from a checkout that can not easily be updated, e.g. because pulling `main` from git-for-windows/git-sdk-64 would update the MSYS2 runtime or Git or any other executable, really, that I am still using. In those cases I still might need to create an SDK artifact from the most recent commit. The new `--head=` option allows that. Signed-off-by: Johannes Schindelin --- please.sh | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/please.sh b/please.sh index 2aceca5e4d..7deea87cf9 100755 --- a/please.sh +++ b/please.sh @@ -403,6 +403,7 @@ create_sdk_artifact () { # [--out=] [--git-sdk=] [--archit architecture=auto bitness= keep_worktree= + head=HEAD while case "$1" in --out|-o) shift @@ -449,6 +450,9 @@ create_sdk_artifact () { # [--out=] [--git-sdk=] [--archit reuse=t keep_worktree=t ;; + --head=*) + head=${1#*=} + ;; --keep-worktree) keep_worktree=t ;; @@ -477,19 +481,19 @@ create_sdk_artifact () { # [--out=] [--git-sdk=] [--archit esac elif test auto = "$architecture" then - if git -C "$git_sdk_path" rev-parse --quiet --verify HEAD:clangarm64 2>/dev/null + if git -C "$git_sdk_path" rev-parse --quiet --verify "$head":clangarm64 2>/dev/null then architecture=aarch64 - elif git -C "$git_sdk_path" rev-parse --quiet --verify HEAD:usr/i686-pc-cygwin 2>/dev/null + elif git -C "$git_sdk_path" rev-parse --quiet --verify "$head":usr/i686-pc-cygwin 2>/dev/null then architecture=i686 - elif git -C "$git_sdk_path" rev-parse --quiet --verify HEAD:usr/i686-pc-msys 2>/dev/null + elif git -C "$git_sdk_path" rev-parse --quiet --verify "$head":usr/i686-pc-msys 2>/dev/null then architecture=i686 - elif git -C "$git_sdk_path" rev-parse --quiet --verify HEAD:usr/x86_64-pc-cygwin 2>/dev/null + elif git -C "$git_sdk_path" rev-parse --quiet --verify "$head":usr/x86_64-pc-cygwin 2>/dev/null then architecture=x86_64 - elif git -C "$git_sdk_path" rev-parse --quiet --verify HEAD:usr/x86_64-pc-msys 2>/dev/null + elif git -C "$git_sdk_path" rev-parse --quiet --verify "$head":usr/x86_64-pc-msys 2>/dev/null then architecture=x86_64 else @@ -572,7 +576,7 @@ create_sdk_artifact () { # [--out=] [--git-sdk=] [--archit test full-sdk != "$mode" || { mkdir -p "$output_path" && - git -C "$git_sdk_path" archive --format=tar HEAD -- ':(exclude)ssl' | + git -C "$git_sdk_path" archive --format=tar "$head" -- ':(exclude)ssl' | xz -9 >"$output_path"/$SDK_REPO.tar.xz && echo "$SDK_REPO.tar.xz written to '$output_path'" >&2 || die "Could not write $SDK_REPO.tar.xz to '%s'\n" "$output_path" @@ -596,16 +600,16 @@ create_sdk_artifact () { # [--out=] [--git-sdk=] [--archit wgd="$wgd-$n" fi && mkdir -p "$wgd/refs" && - git -C "$git_sdk_path" rev-parse HEAD >"$wgd/HEAD" && + git -C "$git_sdk_path" rev-parse "$head" >"$wgd/HEAD" && echo '../..' >"$wgd/commondir" && cygpath -am "$output_path/.git" >"$wgd/gitdir" && echo "gitdir: $wgd" >"$output_path/.git" fi && git -C "$output_path" ls-files -z | xargs -0r git -C "$output_path" rm --sparse && - git -C "$output_path" update-ref HEAD "$(git -C "$git_sdk_path" rev-parse HEAD)" + git -C "$output_path" update-ref HEAD "$(git -C "$git_sdk_path" rev-parse "$head")" else - git -C "$git_sdk_path" worktree add --detach --no-checkout "$output_path" HEAD + git -C "$git_sdk_path" worktree add --detach --no-checkout "$output_path" "$head" fi && sparse_checkout_file="$(git -C "$output_path" rev-parse --git-path info/sparse-checkout)" && git -C "$output_path" config --worktree core.sparseCheckout true && From c079075945a87eea3446cebb51a2f73735b6eb05 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 26 Sep 2026 13:44:50 +0200 Subject: [PATCH 3/3] please.sh create-sdk-artifact: allow operating from a worktree The script so far assumes that the provided `--sdk=` refers to the main worktree. However, that is not always the case; I might even have a bare, partial clone lying around that I need to use to initialize -- quickly! -- an SDK artifact. Let's allow for that. Signed-off-by: Johannes Schindelin --- please.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/please.sh b/please.sh index 7deea87cf9..bc9cafcf8c 100755 --- a/please.sh +++ b/please.sh @@ -557,13 +557,16 @@ create_sdk_artifact () { # [--out=] [--git-sdk=] [--archit fi || die "Could not remove '%s'\n" "$output_path" - if test -d "$git_sdk_path" + if test -e "$git_sdk_path" then + test ! -f "$git_sdk_path" || + git_sdk_path="$(git --git-dir="$git_sdk_path" rev-parse --git-dir)" test ! -f "${git_sdk_path%/}/.git" || - git_sdk_path="$(git -C "${git_sdk_path%/}" rev-parse --git-dir)" + git_sdk_path="$(git --git-dir="${git_sdk_path%/}" rev-parse --git-dir)" test ! -d "${git_sdk_path%/}/.git" || git_sdk_path="${git_sdk_path%/}/.git" - test true = "$(git -C "$git_sdk_path" rev-parse --is-inside-git-dir)" || + test true = "$(git -c safe.bareDirectory=all -C "$git_sdk_path" \ + rev-parse --is-inside-git-dir)" || die "Not a Git repository: '%s'\n" "$git_sdk_path" else test -z "$architecture" ||