re-write applyPatches in kotlin

This commit is contained in:
Simon Gardling 2021-05-01 00:42:57 -04:00
parent 822fa2adae
commit 3a5423ad96
2 changed files with 49 additions and 48 deletions

View File

@ -60,6 +60,53 @@ internal fun Project.createApplyPatchesTask(
return false;
}
fun applyPatchesYarn(): Boolean {
val projectDir = Paths.get("$rootDir/Yatopia-Server_yarn").toFile()
val importDir = Paths.get("$rootDir/mappings/work/Yatopia-Server_yarn_unpatched").toFile()
logger.lifecycle(">>> Resetting subproject $name")
if (projectDir.exists()) {
ensureSuccess(gitCmd("fetch", "origin", dir = projectDir))
ensureSuccess(gitCmd("reset", "--hard", "origin/master", dir = projectDir))
} else {
ensureSuccess(gitCmd("clone", importDir.toString(), projectDir.toString(), printOut = true))
}
logger.lifecycle(">>> Done resetting subproject $name")
projectDir.mkdirs()
val applyName = "mappedPatches"
val name = "Yatopia-Server_yarn"
val patchDir: Path = Paths.get("$rootDir/mappedPatches")
if (Files.notExists(patchDir)) return true
val patchPaths = Files.newDirectoryStream(patchDir)
.map { it.toFile() }
.filter { it.name.endsWith(".patch") }
.sorted()
.takeIf { it.isNotEmpty() } ?: return true
val patches = patchPaths.map { it.absolutePath }.toTypedArray()
logger.lifecycle(">>> Applying $applyName patches to $name")
gitCmd("am", "--abort")
//Cursed Apply Mode that makes fixing stuff a lot easier
if (checkCursed(project)) {
for (patch in patches) {
val gitCommand = arrayListOf("am", "--3way", "--ignore-whitespace",
"--rerere-autoupdate", "--whitespace=fix", "--reject", "-C0", patch)
if (gitCmd(*gitCommand.toTypedArray(), dir = projectDir, printOut = true).exitCode != 0) {
gitCmd("add", ".", dir = projectDir, printOut = true)
gitCmd("am", "--continue", dir = projectDir, printOut = true)
}
}
} else {
val gitCommand = arrayListOf("am", "--3way", "--ignore-whitespace",
"--rerere-autoupdate", "--whitespace=fix", *patches)
}
return false;
}
doLast {
for ((name, subproject) in toothpick.subprojects) {
val (sourceRepo, projectDir, patchesDir) = subproject
@ -102,6 +149,7 @@ internal fun Project.createApplyPatchesTask(
bashCmd("rm -fr patches/server/*-Mapped-Patches.patch")
bashCmd("bash mappings/scripts/init.sh", printOut = true)
bashCmd("bash mappings/scripts/apply.sh", printOut = true)
if (applyPatchesYarn()) {}
}
}

View File

@ -1,47 +0,0 @@
#!/bin/bash
# set -e
cd "$(dirname "$0")"
cd ..
basedir="$(cd .. && pwd -P)"
gitcmd="git -c commit.gpgsign=false"
applyPatch(){
local what="$1"
local what_name="$(basename "$what")"
local target="$2"
local branch="$3"
local patch_folder="$4"
cd "$basedir/$what"
$gitcmd branch -f upstream "$branch" >/dev/null
cd "$basedir"
if [ ! -d "$basedir/$target" ]; then
echo "doing clone"
$gitcmd clone "$what" "$target"
fi
cd "$basedir/$target"
echo "Resetting $target to $what_name..."
$gitcmd remote rm upstream > /dev/null 2>&1
$gitcmd remote add upstream "$basedir/$what" >/dev/null 2>&1
$gitcmd checkout master 2>/dev/null || $gitcmd checkout -b master
$gitcmd fetch upstream >/dev/null 2>&1
$gitcmd reset --hard upstream/upstream
echo " Applying patches to $target..."
$gitcmd am --abort >/dev/null 2>&1
if [ -z "$(ls "$basedir/$patch_folder/"*.patch||true)" ];then
echo " no patches for $target"
elif $gitcmd am --3way --ignore-whitespace "$basedir/$patch_folder/"*.patch; then
echo " Patches applied cleanly to $target"
else
echo " Something did not apply cleanly to $target."
echo " Please review above details and finish the apply then"
echo " save the changes with rebuildPatches.sh"
return 1
fi
}
(applyPatch mappings/work/Yatopia-Server_yarn_unpatched Yatopia-Server_yarn HEAD mappedPatches)