Last active
June 26, 2019 11:14
-
-
Save jbruchanov/d1ffd395792344bceb66926c69400536 to your computer and use it in GitHub Desktop.
Git History
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package git | |
import java.io.File | |
/* | |
How to use it | |
- https://raw.githubusercontent.com/erikmd/git-scripts/master/bin/git-format-patch-follow save into your | |
`/usr/local/bin/git-format-patch-follow` (not .sh suffix) & make it executable | |
- take following code | |
- update `patchesFolder`, `libNetworkSource`, `target` accordingly to your case | |
- have new branch selected in your target git repo (preferably very empty, to avoid any potential conflicts with your actual files) | |
- create new file $target/patches.sh with content `git am --3way ~/tmp/patches/\*.patch` or update the `runCommand` script to unwrap *.patch | |
- if result != 0, you have to manually fix the conflict and continue, so put BP there, fix it when hit and just continue | |
- this script is EVERYTHING BUT NOT GOOD, always run it with DEBUGGER attached and understand what it's doing, | |
blind run will most likely format your hard drive, destroy your mac and kill some kittens! | |
*/ | |
//Copy this script into `/usr/local/bin/` | |
//https://raw.githubusercontent.com/erikmd/git-scripts/master/bin/git-format-patch-follow | |
val patchesFolder = File("/Users/a9508890/tmp/patches") | |
val libNetworkSource = File("/Users/a9508890/work/nga-mobile-3-android/business/src/") | |
val target = File("/Users/a9508890/work/nga-mobile-network-android") | |
fun main(args: Array<String>) { | |
patchesFolder.deleteRecursively() | |
"git am --abort".runCommand(target) | |
val files = libNetworkSource | |
.walk() | |
.toList() | |
.filter { it.isFile && !it.isHidden } | |
// .filter { it.absolutePath.contains("/src/qa/java/com/cryptomathic/securecore/") } | |
files.forEachIndexed { i, file -> | |
println("${i + 1}/${files.size} ${file.absolutePath}") | |
val createPath = "git format-patch-follow -B -M -o $patchesFolder --root --follow -- ${file.absolutePath}" | |
createPath.runCommand(libNetworkSource) | |
val applyPatch = "$target/patches.sh"//content is just => git am --3way ~/tmp/patches/*.patch | |
// if (i <= 10) { | |
// return@forEachIndexed | |
// } | |
val result = applyPatch.runCommand(target) | |
val x = true | |
if(x) { | |
if (result != 0) { | |
"git am --skip".runCommand(target) | |
} | |
patchesFolder.deleteRecursively() | |
} | |
println("-----------------------------------------------") | |
} | |
} | |
fun String.runCommand(workingDir: File): Int { | |
val process = ProcessBuilder(*split(" ").toTypedArray()) | |
.directory(workingDir) | |
.redirectOutput(ProcessBuilder.Redirect.INHERIT) | |
.redirectError(ProcessBuilder.Redirect.INHERIT) | |
.start() | |
// val output = process.inputStream.bufferedReader().readText() | |
// val err = process.errorStream.bufferedReader().readText() | |
process.waitFor() | |
process.destroy() | |
return process.exitValue() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment