Handle gpg signing better (#1123)

Instead of checking whether it was set previously, setting it to false,
then setting it back to true if it was true before, just use the
command-line argument in git to override the config for that command.
Using a variable makes it pretty painless to do.
This commit is contained in:
Kyle Wood 2018-05-24 13:41:50 -05:00
parent efe156b1f7
commit fdc7459143
10 changed files with 87 additions and 102 deletions

11
paper
View file

@ -23,6 +23,7 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
done done
SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}") SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}")
basedir=$(dirname "$SOURCE") basedir=$(dirname "$SOURCE")
gitcmd="git -c commit.gpgsign=false"
source "$basedir/scripts/functions.sh" source "$basedir/scripts/functions.sh"
@ -104,7 +105,7 @@ case "$1" in
set -e set -e
paperstash paperstash
git rebase -i upstream/upstream $gitcmd rebase -i upstream/upstream
paperunstash paperunstash
) )
;; ;;
@ -115,7 +116,7 @@ case "$1" in
set -e set -e
paperstash paperstash
git rebase -i upstream/upstream $gitcmd rebase -i upstream/upstream
paperunstash paperunstash
) )
;; ;;
@ -125,9 +126,9 @@ case "$1" in
( (
set -e set -e
git add . $gitcmd add .
git commit --amend $gitcmd commit --amend
git rebase --continue $gitcmd rebase --continue
cd "$basedir" cd "$basedir"
scripts/rebuildPatches.sh "$basedir" scripts/rebuildPatches.sh "$basedir"

View file

@ -1,4 +1,7 @@
#!/bin/bash #!/bin/bash
gitcmd="git -c commit.gpgsign=false"
noapply=1 noapply=1
isreject=0 isreject=0
if [[ $1 == "--noapplied" ]]; then if [[ $1 == "--noapplied" ]]; then
@ -18,18 +21,18 @@ else
fi fi
applied=$(echo $file | sed 's/.patch$/-applied\.patch/g') applied=$(echo $file | sed 's/.patch$/-applied\.patch/g')
if [ "$1" == "--reset" ]; then if [ "$1" == "--reset" ]; then
git am --abort $gitcmd am --abort
git reset --hard $gitcmd reset --hard
git clean -f $gitcmd clean -f
exit 0 exit 0
fi fi
(test "$isreject" != "1" && git am -3 $file) || ( (test "$isreject" != "1" && $gitcmd am -3 $file) || (
echo "Failures - Wiggling" echo "Failures - Wiggling"
git reset --hard $gitcmd reset --hard
git clean -f $gitcmd clean -f
errors=$(git apply --rej $file 2>&1) errors=$($gitcmd apply --rej $file 2>&1)
echo "$errors" >> ~/patch.log echo "$errors" >> ~/patch.log
export missingfiles="" export missingfiles=""
export summaryfail="" export summaryfail=""
@ -44,12 +47,12 @@ fi
missingfiles="$missingfiles\n$base" missingfiles="$missingfiles\n$base"
fi fi
done done
for i in $(git status --porcelain | awk '{print $2}'); do for i in $($gitcmd status --porcelain | awk '{print $2}'); do
filedata=$(cat "$i") filedata=$(cat "$i")
if [ -f "$file" ] && [[ "$filedata" == *"<<<<<"* ]]; then if [ -f "$file" ] && [[ "$filedata" == *"<<<<<"* ]]; then
export summaryfail="$summaryfail\nFAILED TO APPLY: $i" export summaryfail="$summaryfail\nFAILED TO APPLY: $i"
else else
git add "$i" $gitcmd add "$i"
export summarygood="$summarygood\nAPPLIED CLEAN: $i" export summarygood="$summarygood\nAPPLIED CLEAN: $i"
fi fi
done done
@ -64,8 +67,8 @@ fi
echo " " echo " "
echo "==========================="; echo "===========================";
fi fi
git status $gitcmd status
git diff $gitcmd diff
) )
if [[ "$noapply" != "1" ]] && [[ "$file" != *-applied.patch ]]; then if [[ "$noapply" != "1" ]] && [[ "$file" != *-applied.patch ]]; then
mv "$file" "$applied" mv "$file" "$applied"

View file

@ -4,8 +4,8 @@
PS1="$" PS1="$"
basedir="$(cd "$1" && pwd -P)" basedir="$(cd "$1" && pwd -P)"
workdir="$basedir/work" workdir="$basedir/work"
gpgsign="$(git config commit.gpgsign || echo "false")" gitcmd="git -c commit.gpgsign=false"
applycmd="git am --3way --ignore-whitespace" applycmd="$gitcmd am --3way --ignore-whitespace"
# Windows detection to workaround ARG_MAX limitation # Windows detection to workaround ARG_MAX limitation
windows="$([[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" ]] && echo "true" || echo "false")" windows="$([[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" ]] && echo "true" || echo "false")"
@ -18,30 +18,25 @@ function applyPatch {
branch=$3 branch=$3
cd "$basedir/$what" cd "$basedir/$what"
git fetch $gitcmd fetch
git branch -f upstream "$branch" >/dev/null $gitcmd branch -f upstream "$branch" >/dev/null
cd "$basedir" cd "$basedir"
if [ ! -d "$basedir/$target" ]; then if [ ! -d "$basedir/$target" ]; then
git clone "$what" "$target" $gitcmd clone "$what" "$target"
fi fi
cd "$basedir/$target" cd "$basedir/$target"
# Disable GPG signing before AM, slows things down and doesn't play nicely.
# There is also zero rational or logical reason to do so for these sub-repo AMs.
# Calm down kids, it's re-enabled (if needed) immediately after, pass or fail.
git config commit.gpgsign false
echo "Resetting $target to $what_name..." echo "Resetting $target to $what_name..."
git remote rm upstream > /dev/null 2>&1 $gitcmd remote rm upstream > /dev/null 2>&1
git remote add upstream "$basedir/$what" >/dev/null 2>&1 $gitcmd remote add upstream "$basedir/$what" >/dev/null 2>&1
git checkout master 2>/dev/null || git checkout -b master $gitcmd checkout master 2>/dev/null || $gitcmd checkout -b master
git fetch upstream >/dev/null 2>&1 $gitcmd fetch upstream >/dev/null 2>&1
git reset --hard upstream/upstream $gitcmd reset --hard upstream/upstream
echo " Applying patches to $target..." echo " Applying patches to $target..."
git am --abort >/dev/null 2>&1 $gitcmd am --abort >/dev/null 2>&1
# Special case Windows handling because of ARG_MAX constraint # Special case Windows handling because of ARG_MAX constraint
if [[ $windows == "true" ]]; then if [[ $windows == "true" ]]; then
@ -72,23 +67,16 @@ function applyPatch {
fi fi
} }
function enableCommitSigningIfNeeded {
if [[ "$gpgsign" == "true" ]]; then
git config commit.gpgsign true
fi
}
# Move into spigot dir # Move into spigot dir
cd "$workdir/Spigot" cd "$workdir/Spigot"
basedir=$(pwd) basedir=$(pwd)
# Apply Spigot # Apply Spigot
( (
applyPatch ../Bukkit Spigot-API HEAD && applyPatch ../Bukkit Spigot-API HEAD &&
applyPatch ../CraftBukkit Spigot-Server patched applyPatch ../CraftBukkit Spigot-Server patched
) || ( ) || (
echo "Failed to apply Spigot Patches" echo "Failed to apply Spigot Patches"
enableCommitSigningIfNeeded exit 1
exit 1
) || exit 1 ) || exit 1
# Move out of Spigot # Move out of Spigot
basedir="$1" basedir="$1"
@ -101,12 +89,10 @@ echo "Importing MC Dev"
# Apply paper # Apply paper
cd "$basedir" cd "$basedir"
( (
applyPatch "work/Spigot/Spigot-API" Paper-API HEAD && applyPatch "work/Spigot/Spigot-API" Paper-API HEAD &&
applyPatch "work/Spigot/Spigot-Server" Paper-Server HEAD applyPatch "work/Spigot/Spigot-Server" Paper-Server HEAD
enableCommitSigningIfNeeded
) || ( ) || (
echo "Failed to apply Paper Patches" echo "Failed to apply Paper Patches"
enableCommitSigningIfNeeded exit 1
exit 1
) || exit 1 ) || exit 1
) )

View file

@ -3,12 +3,13 @@
( (
set -e set -e
basedir="$(cd "$1" && pwd -P)" basedir="$(cd "$1" && pwd -P)"
gitcmd="git -c commit.gpgsign=false"
(git submodule update --init && ./scripts/remap.sh "$basedir" && ./scripts/decompile.sh "$basedir" && ./scripts/init.sh "$basedir" && ./scripts/applyPatches.sh "$basedir") || ( ($gitcmd submodule update --init && ./scripts/remap.sh "$basedir" && ./scripts/decompile.sh "$basedir" && ./scripts/init.sh "$basedir" && ./scripts/applyPatches.sh "$basedir") || (
echo "Failed to build Paper" echo "Failed to build Paper"
exit 1 exit 1
) || exit 1 ) || exit 1
if [ "$2" == "--jar" ]; then if [ "$2" == "--jar" ]; then
mvn clean install && ./scripts/paperclip.sh "$basedir" mvn clean install && ./scripts/paperclip.sh "$basedir"
fi fi
) )

View file

@ -1,5 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
gitcmd="git -c commit.gpgsign=false"
color() { color() {
if [ $2 ]; then if [ $2 ]; then
echo -e "\e[$1;$2m" echo -e "\e[$1;$2m"
@ -12,11 +14,11 @@ colorend() {
} }
paperstash() { paperstash() {
STASHED=$(git stash 2>/dev/null|| return 0) # errors are ok STASHED=$($gitcmd stash 2>/dev/null|| return 0) # errors are ok
} }
paperunstash() { paperunstash() {
if [[ "$STASHED" != "No local changes to save" ]] ; then if [[ "$STASHED" != "No local changes to save" ]] ; then
git stash pop 2>/dev/null|| return 0 # errors are ok $gitcmd stash pop 2>/dev/null|| return 0 # errors are ok
fi fi
} }

View file

@ -6,6 +6,7 @@ nms="net/minecraft/server"
export MODLOG="" export MODLOG=""
PS1="$" PS1="$"
basedir="$(cd "$1" && pwd -P)" basedir="$(cd "$1" && pwd -P)"
gitcmd="git -c commit.gpgsign=false"
workdir="$basedir/work" workdir="$basedir/work"
minecraftversion=$(cat "$workdir/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4) minecraftversion=$(cat "$workdir/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4)
@ -13,26 +14,26 @@ decompiledir="$workdir/Minecraft/$minecraftversion"
export importedmcdev="" export importedmcdev=""
function import { function import {
export importedmcdev="$importedmcdev $1" export importedmcdev="$importedmcdev $1"
file="${1}.java" file="${1}.java"
target="$workdir/Spigot/Spigot-Server/src/main/java/$nms/$file" target="$workdir/Spigot/Spigot-Server/src/main/java/$nms/$file"
base="$decompiledir/$nms/$file" base="$decompiledir/$nms/$file"
if [[ ! -f "$target" ]]; then if [[ ! -f "$target" ]]; then
export MODLOG="$MODLOG Imported $file from mc-dev\n"; export MODLOG="$MODLOG Imported $file from mc-dev\n";
echo "Copying $base to $target" echo "Copying $base to $target"
cp "$base" "$target" cp "$base" "$target"
else else
echo "UN-NEEDED IMPORT: $file" echo "UN-NEEDED IMPORT: $file"
fi fi
} }
( (
cd "$workdir/Spigot/Spigot-Server/" cd "$workdir/Spigot/Spigot-Server/"
lastlog=$(git log -1 --oneline) lastlog=$($gitcmd log -1 --oneline)
if [[ "$lastlog" = *"mc-dev Imports"* ]]; then if [[ "$lastlog" = *"mc-dev Imports"* ]]; then
git reset --hard HEAD^ $gitcmd reset --hard HEAD^
fi fi
) )
import AxisAlignedBB import AxisAlignedBB
@ -110,6 +111,6 @@ import WorldProvider
cd "$workdir/Spigot/Spigot-Server/" cd "$workdir/Spigot/Spigot-Server/"
rm -rf nms-patches applyPatches.sh makePatches.sh >/dev/null 2>&1 rm -rf nms-patches applyPatches.sh makePatches.sh >/dev/null 2>&1
git add . -A >/dev/null 2>&1 $gitcmd add . -A >/dev/null 2>&1
echo -e "mc-dev Imports\n\n$MODLOG" | git commit . -F - echo -e "mc-dev Imports\n\n$MODLOG" | $gitcmd commit . -F -
) )

View file

@ -9,23 +9,16 @@ minecraftversion=$(cat "$workdir/BuildData/info.json" | grep minecraftVersion |
decompiledir="$workdir/Minecraft/$minecraftversion" decompiledir="$workdir/Minecraft/$minecraftversion"
nms="$decompiledir/net/minecraft/server" nms="$decompiledir/net/minecraft/server"
cb="src/main/java/net/minecraft/server" cb="src/main/java/net/minecraft/server"
gpgsign="$(git config commit.gpgsign || echo "false")" gitcmd="git -c commit.gpgsign=false"
patch=$(which patch 2>/dev/null) patch=$(which patch 2>/dev/null)
if [ "x$patch" == "x" ]; then if [ "x$patch" == "x" ]; then
patch="$basedir/hctap.exe" patch="$basedir/hctap.exe"
fi fi
function enableCommitSigningIfNeeded {
if [[ "$gpgsign" == "true" ]]; then
git config commit.gpgsign true
fi
}
echo "Applying CraftBukkit patches to NMS..." echo "Applying CraftBukkit patches to NMS..."
cd "$workdir/CraftBukkit" cd "$workdir/CraftBukkit"
git checkout -B patched HEAD >/dev/null 2>&1 $gitcmd checkout -B patched HEAD >/dev/null 2>&1
rm -rf "$cb" rm -rf "$cb"
mkdir -p "$cb" mkdir -p "$cb"
for file in $(ls nms-patches) for file in $(ls nms-patches)
@ -42,11 +35,7 @@ do
"$patch" -s -d src/main/java/ "net/minecraft/server/$file" < "$patchFile" "$patch" -s -d src/main/java/ "net/minecraft/server/$file" < "$patchFile"
done done
git add src $gitcmd add src
# We don't need to sign an automated commit $gitcmd commit -m "CraftBukkit $ $(date)" --author="Auto <auto@mated.null>"
# All it does is make you input your key passphrase mid-patch $gitcmd checkout -f HEAD^
git config commit.gpgsign false
git commit -m "CraftBukkit $ $(date)" --author="Auto <auto@mated.null>"
enableCommitSigningIfNeeded
git checkout -f HEAD^
) )

View file

@ -4,15 +4,16 @@
PS1="$" PS1="$"
basedir="$(cd "$1" && pwd -P)" basedir="$(cd "$1" && pwd -P)"
workdir="$basedir/work" workdir="$basedir/work"
gitcmd="git -c commit.gpgsign=false -c core.safecrlf=false"
echo "Rebuilding patch files from current fork state..." echo "Rebuilding patch files from current fork state..."
git config core.safecrlf false
function cleanupPatches { function cleanupPatches {
cd "$1" cd "$1"
for patch in *.patch; do for patch in *.patch; do
echo "$patch" echo "$patch"
gitver=$(tail -n 2 "$patch" | grep -ve "^$" | tail -n 1) gitver=$(tail -n 2 "$patch" | grep -ve "^$" | tail -n 1)
diffs=$(git diff --staged "$patch" | grep -E "^(\+|\-)" | grep -Ev "(From [a-z0-9]{32,}|\-\-\- a|\+\+\+ b|.index)") diffs=$($gitcmd diff --staged "$patch" | grep -E "^(\+|\-)" | grep -Ev "(From [a-z0-9]{32,}|\-\-\- a|\+\+\+ b|.index)")
testver=$(echo "$diffs" | tail -n 2 | grep -ve "^$" | tail -n 1 | grep "$gitver") testver=$(echo "$diffs" | tail -n 2 | grep -ve "^$" | tail -n 1 | grep "$gitver")
if [ "x$testver" != "x" ]; then if [ "x$testver" != "x" ]; then
@ -20,8 +21,8 @@ function cleanupPatches {
fi fi
if [ "x$diffs" == "x" ] ; then if [ "x$diffs" == "x" ] ; then
git reset HEAD "$patch" >/dev/null $gitcmd reset HEAD "$patch" >/dev/null
git checkout -- "$patch" >/dev/null $gitcmd checkout -- "$patch" >/dev/null
fi fi
done done
} }
@ -50,9 +51,9 @@ function savePatches {
cd "$basedir/$target" cd "$basedir/$target"
git format-patch --no-stat -N -o "$basedir/${what_name}-Patches/" upstream/upstream >/dev/null $gitcmd format-patch --no-stat -N -o "$basedir/${what_name}-Patches/" upstream/upstream >/dev/null
cd "$basedir" cd "$basedir"
git add -A "$basedir/${what_name}-Patches" $gitcmd add -A "$basedir/${what_name}-Patches"
cleanupPatches "$basedir/${what_name}-Patches" cleanupPatches "$basedir/${what_name}-Patches"
echo " Patches saved for $what to $what_name-Patches/" echo " Patches saved for $what to $what_name-Patches/"
} }

View file

@ -6,7 +6,7 @@ basedir="$(cd "$1" && pwd -P)"
workdir="$basedir/work" workdir="$basedir/work"
minecraftversion=$(cat "$workdir/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4) minecraftversion=$(cat "$workdir/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4)
decompiledir="$workdir/Minecraft/$minecraftversion" decompiledir="$workdir/Minecraft/$minecraftversion"
gitcmd="git -c commit.gpgsign=false"
# #
# FUNCTIONS # FUNCTIONS
@ -15,7 +15,7 @@ decompiledir="$workdir/Minecraft/$minecraftversion"
updateTest() { updateTest() {
paperstash paperstash
git reset --hard origin/master $gitcmd reset --hard origin/master
paperunstash paperunstash
} }
@ -29,9 +29,9 @@ cd "$papertestdir"
# #
if [ ! -d .git ]; then if [ ! -d .git ]; then
git init $gitcmd init
git remote add origin ${PAPER_TEST_SKELETON:-https://github.com/PaperMC/PaperTestServer} $gitcmd remote add origin ${PAPER_TEST_SKELETON:-https://github.com/PaperMC/PaperTestServer}
git fetch origin $gitcmd fetch origin
updateTest updateTest
elif [ "$2" == "update" ] || [ "$3" == "update" ]; then elif [ "$2" == "update" ] || [ "$3" == "update" ]; then
updateTest updateTest

View file

@ -5,12 +5,13 @@ set -e
PS1="$" PS1="$"
basedir="$(cd "$1" && pwd -P)" basedir="$(cd "$1" && pwd -P)"
workdir="$basedir/work" workdir="$basedir/work"
gitcmd="git -c commit.gpgsign=false"
function update { function update {
cd "$workdir/$1" cd "$workdir/$1"
git fetch && git reset --hard origin/master $gitcmd fetch && $gitcmd reset --hard origin/master
cd ../ cd ../
git add $1 $gitcmd add $1
} }
update Bukkit update Bukkit