From 0298eadb9e4d9abe1169714455402baca83ace10 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sat, 7 Jun 2025 19:08:12 +0200 Subject: [PATCH] ljsadlkjdsalkj --- justfile | 60 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/justfile b/justfile index ed7b368..f798999 100644 --- a/justfile +++ b/justfile @@ -638,7 +638,7 @@ pr $number=`just _a_pr`: # TODO: gitignore ./checkout-upstream-branch.sh printf "git checkout --autostash %q\n" "$(git rev-parse --abbrev-ref HEAD)" > checkout-upstream-branch.sh (set -x; - $GIT checkout -b pr-"$number"-rebased-"$remote"-"$branch" ||: + $GIT checkout -b pr-"$number"-rebased-"$remote"-"$branch-{{ epoch }}" ||: $GIT pull --rebase "$remote" "$branch" || $GIT rebase --abort ) || echo >&2 "retcode: $?" ||: } @@ -650,18 +650,19 @@ pr $number=`just _a_pr`: (set -x; gh pr checkout "$number" --force) [[ -z "$upstream_branch" ]] || do_rebase "$upstream_branch" fi - elif test -d prs/pr-"$number"-*; then - # TODO: remove this backward compat - cd prs/pr-"$number"-* else upstream_branch=$( just _a_upstream_release_branch "Rebase?" "" ) (cd master; $GIT worktree prune - (set -x; $GIT worktree add -b just-nixpkgs-pr-"$number"-tmp ../prs/pr-"$number") + # (set -x; $GIT worktree add -b just-nixpkgs-pr-"$number"-tmp ../prs/pr-"$number") + declare pull_json + pull_json="$(gh api repos/NixOS/nixpkgs/pulls/382957)" + git fetch upstream "$(jq <<<"$pull_json" '.base.ref' -r)" + (set -x; $GIT worktree add ../prs/pr-"$number" "$(jq <<<"$pull_json" '.base.sha' -r)") ) cd prs/pr-"$number" (set -x; gh pr checkout "$number") - git branch -D just-nixpkgs-pr-"$number"-tmp + # git branch -D just-nixpkgs-pr-"$number"-tmp [[ -z "$upstream_branch" ]] || do_rebase "$upstream_branch" fi exec just _enter_interactive_shell @@ -716,7 +717,7 @@ remote-branch $remote_ref=`just _a_remote_branch origin | cut -d/ -f2-`: cd "$(just _new_worktree "$@")"; exec just _enter_interactive_shell @_a_wt_type: - gum choose feat fix init bump doc migrate + gum choose feat fix init bump doc migrate drop tmp @_a_wt_name: gum input --placeholder="Branch name?" @@ -737,6 +738,7 @@ _mk_worktree $name $dir $base="upstream/master" $onto="": #!/usr/bin/env -S bash -euo pipefail -x [[ -n "$name" ]] [[ -n "$dir" ]] + [[ -n "$base" ]] remote="$(cut -d/ -f1 <<<"$base")" branch="$(cut -d/ -f2- <<<"$base")" cd master @@ -749,6 +751,21 @@ _mk_worktree $name $dir $base="upstream/master" $onto="": $GIT pull --rebase "$remote" "$branch" [[ -z "$onto" ]] || just rebase-onto HEAD "$onto" +cherry-pick-commits-into-new-worktree *commits: + #!/usr/bin/env -S bash -euo pipefail + declare -a commits=("$@") + [[ "${#commits[@]}" -gt 0 ]] || readarray -td $'\n' commits <<<"$( cd "$invokedir"; just _some_commits )" + [[ "${#commits[@]}" -gt 0 ]] + proposed_name="$( + git -C "$invokedir" show --oneline --no-patch "${commits[0]}" | + cut -d' ' -f2- | cut -d: -f1 | rev | cut -d. -f1 | rev + )" + cd "$( + just _new_worktree "$(just _a_wt_type)" "$(gum input --placeholder="Branch name?" --value="$proposed_name")" + )" + git cherry-pick "${commits[@]}" + exec just _enter_interactive_shell + pop-commits-to-new-worktree $commits=`cd "$invokedir"; just _some_commits`: #!/usr/bin/env -S bash -euo pipefail test -n "$commits" || { echo >&2 "no commits were selected!"; false;} @@ -1114,18 +1131,19 @@ format-files-touched-by-commit *commits: # === internal helpers === [no-cd] -mk-packages-json $fname="packages.json" $rootdir=`cd "$invokedir"; git rev-parse --show-toplevel` $outpaths=`gum confirm "Eval outpaths?" --default=no && echo true || echo false`: +mk-packages-json $fname="packages.json" $rootdir=`cd "$invokedir"; git rev-parse --show-toplevel` $outpaths=`just _gum_bool "Eval outpaths?" --default=no` $system=`just _a_system` $allow_aliases=`just _gum_bool --default=no "Allow aliases?"`: #!/usr/bin/env -S bash -euo pipefail extra_args=() if [[ -n "$outpaths" && "$outpaths" != false ]]; then extra_args+=(--drv-path --out-path) fi # keeping this in ram requires 220mb extra memory + # TODO: use a tmpdir instead? packages_json="$( set -x time nix-env "$fname" _packages_json: #!/usr/bin/env -S bash -euo pipefail - echo| { # don't swallow stdin, TODO: can i do this with exec? + { if [[ ! -s packages.json || $(( "$epoch" - "$(stat -c %Y packages.json )" )) -gt $(( 60*60*24*7 )) ]]; then @@ -1151,9 +1169,9 @@ _packages_json: false fi git -C upstream/master/ pull upstream master --rebase --autostash 1>&2 - just mk-packages-json "packages.json" "./upstream/master" false + just mk-packages-json "packages.json" "./upstream/master" false "$(just _this_system)" false fi - } + }