From 1b9fb7041d1c4099d4be1b61fcc0abe2402df057 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Fri, 16 Sep 2022 23:43:16 +0200 Subject: [PATCH] Ports: Unify the git "origin" and the working copy I've lost more changes to "you forgot to push the changed commits to the remote" than I'd like to admit, so let's just unify both and only ever use the actual working repository for detemining whether any patches have changed. --- Ports/.port_include.sh | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/Ports/.port_include.sh b/Ports/.port_include.sh index 0dc51db52b..4828139e4c 100755 --- a/Ports/.port_include.sh +++ b/Ports/.port_include.sh @@ -95,13 +95,10 @@ cleanup_git() { run git clean -xffd >/dev/null 2>&1 } -# Use the local git target repo as the workdir -# Make sure to clean it up afterwards +# Make sure to clean up the git repository of the port afterwards. if [ -n "${IN_SERENITY_PORT_DEV:-}" ]; then echo "WARNING: All changes to the workdir in the current state (inside ./package.sh dev) are temporary!" echo " They will be reverted once the command exits!" - nongit_workdir="$workdir" - workdir=".$workdir-git" trap "run cleanup_git" EXIT fi @@ -713,18 +710,16 @@ do_dev() { exit 1 fi - git_repo=".${workdir////_}-git" - [ -d "$git_repo" ] || ( - mv "$workdir" "$git_repo" - pushd "$git_repo" - if [ ! -d "$git_repo/.git" ]; then + [ -d "$workdir" ] || ( + do_fetch + pushd "$workdir" + if [ ! -d ".git" ]; then git init . git config core.autocrlf false git add --all --force git commit -a -m 'Initial import' fi - # Make it allow pushes from other local checkouts - git config receive.denyCurrentBranch ignore + # Import patches as commits, or ask the user to commit them # if they're not git patches already. if [ -d "${PORT_META_DIR}/patches" ] && [ -n "$(find -L "${PORT_META_DIR}/patches" -maxdepth 1 -name '*.patch' -print -quit)" ]; then @@ -800,33 +795,25 @@ do_dev() { popd ) - [ -d "$git_repo" ] && [ ! -d "$workdir" ] && { - git clone --config core.autocrlf=false "$git_repo" "$workdir" - } - [ -d "$workdir/.git" ] || { - >&2 echo "$workdir does not appear to be a git repository, if you did this manually, you're on your own" - if prompt_yes_no "Otherwise, press 'y' to remove that directory and clone it again"; then - rm -fr "$workdir" - git clone --config core.autocrlf=false "$git_repo" "$workdir" - else - exit 1 - fi + >&2 echo "$workdir does not appear to be a git repository." + >&2 echo "If you want to use './package.sh dev', please run './package.sh clean' first." + exit 1 } - local first_hash="$(git -C "$git_repo" rev-list --max-parents=0 HEAD)" + local first_hash="$(git -C "$workdir" rev-list --max-parents=0 HEAD)" pushd "$workdir" launch_user_shell popd >/dev/null 2>&1 - local current_hash="$(git -C "$git_repo" rev-parse HEAD)" + local current_hash="$(git -C "$workdir" rev-parse HEAD)" # If the hashes are the same, we have no patches, otherwise generate patches if [ "$first_hash" != "$current_hash" ]; then >&2 echo "Note: Regenerating patches as there are some commits in the port repo (started at $first_hash, now is $current_hash)" rm -fr "${PORT_META_DIR}"/patches/*.patch - git -C "$git_repo" format-patch --no-numbered --zero-commit --no-signature --full-index "$first_hash" -o "$(realpath "${PORT_META_DIR}/patches")" + git -C "$workdir" format-patch --no-numbered --zero-commit --no-signature --full-index "$first_hash" -o "$(realpath "${PORT_META_DIR}/patches")" do_generate_patch_readme fi } @@ -865,7 +852,6 @@ parse_arguments() { do_clean fi fi - do_fetch do_dev ;; *)