Skip to content

Commit

Permalink
work on patch script
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Huber <[email protected]>
  • Loading branch information
maxhbr committed Mar 16, 2024
1 parent 24820a7 commit e5e6cef
Showing 1 changed file with 55 additions and 23 deletions.
78 changes: 55 additions & 23 deletions update-and-apply-patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

set -euo pipefail

declare -a patches=(
"sevz17:vanitygaps"
# "sevz17:autostart"
"NikitaIvanovV:centeredmaster"
"korei999:rotatetags"
"dm1tz:04-cyclelayouts"
# "wochap:regexrules"
"madcowog:ipc-v2"
"PalanixYT:float_border_color"
)

addRemoteIfMissing() {
local remote="$1"
local url="${2:-"https://github.com/$remote/dwl"}"
Expand All @@ -21,30 +10,73 @@ addRemoteIfMissing() {
fi
}

applyPatchfile() {
local patchfile="$1"
echo "applyPatchfile patchfile=$patchfile ..."

# Check if the patch can be applied cleanly
if git apply --check "$patchfile" >/dev/null 2>&1; then
echo "apply ..."
# Apply the patch
if git apply "$patchfile"; then
echo "... successfully."
else
echo "Failed to apply the patch."
exit 1
fi
else
echo "... Patch cannot be applied cleanly or is already applied. Skipping."
fi
}

applyPatch() {
local remote="$1"
local branch="$2"
echo "applyPatch remote=$remote and branch=$branch ..."
addRemoteIfMissing "$remote"
git fetch "$remote" "$branch"

# check if patch is already applied
if git branch --contains "$remote/$branch" | grep -q '^\*'; then
echo "patch $branch from $remote already applied"
echo "... already applied"
else
echo "apply $branch from $remote"
echo "apply ..."
git merge --no-edit "$remote/$branch"
nix build .#dwl
nix build ".#dwl"
fi
}

cd "$(dirname "$0")"
addRemoteIfMissing "upstream" "https://github.com/djpohly/dwl"
applyPatch "upstream" "main"
applyUpstream() {
addRemoteIfMissing "upstream" "https://github.com/djpohly/dwl"
applyPatch "upstream" "main"
}

# read patches into pairs of remote and branch
while IFS=':' read -r remote branch; do
applyPatch "$remote" "$branch"
done < <(printf '%s\n' "${patches[@]}")
applyPatches() {
declare -a patches=(
./dwl-patches/vanitygaps/vanitygaps.patch
# "sevz17:vanitygaps"
# # "sevz17:autostart"
# "NikitaIvanovV:centeredmaster"
# "korei999:rotatetags"
# "dm1tz:04-cyclelayouts"
# # "wochap:regexrules"
# "madcowog:ipc-v2"
# "PalanixYT:float_border_color"
)

# read patches into pairs of remote and branch
while IFS=':' read -r remote branch; do
if [[ -z "$branch" ]]; then
applyPatchfile "$remote"
else
echo applyPatch "$remote" "$branch"
fi
done < <(printf '%s\n' "${patches[@]}")
}

cd "$(dirname "$0")"
echo applyUpstream
applyPatches

nix build .#dwl
nix build .#mydwl
echo nix build .#dwl
echo nix build .#mydwl

0 comments on commit e5e6cef

Please sign in to comment.