I'm trying to produce a patch from a git tag A and master and to then apply the patch as a single commit to a separate branch B (whose last commit is tagged A).
I believe git is missing something when generating the patch that causes it to not apply cleanly.
The file it/my/application/Something.kt in question contains code similar to:
package it.my.application
import io.micronaut.runtime.event.annotation.EventListener
import io.micronaut.transaction.annotation.TransactionalEventListener
import io.micronaut.transaction.annotation.TransactionalEventListener.TransactionPhase
import it.my.application.SomethingFacade
import org.slf4j.LoggerFactory
import javax.inject.Singleton
typealias Something = Int
in master the file was renamed to other/my/application/Something.kt and changed to:
package other.my.application
import io.micronaut.runtime.event.annotation.EventListener
import io.micronaut.transaction.annotation.TransactionalEventListener
import io.micronaut.transaction.annotation.TransactionalEventListener.TransactionPhase
import org.slf4j.LoggerFactory
import javax.inject.Singleton
import javax.transaction.Transactional
typealias SomethingId = Int
Note:
- the line
package it.my.applicationwas changed topackage other.my.application - the line
import it.my.application.SomethingFacadewas removed - the line
import javax.transaction.Transactionalwas added
Looking at the patch these is the hunk that git generates for this portion of the code:
diff --git a/src/main/kotlin/it/my/application/Something.kt b/src/main/kotlin/other/my/application/Something.kt
similarity index 91%
rename from src/main/kotlin/it/my/application/Something.kt
rename to src/main/kotlin/other/my/application/Something.kt
index ed24736..cb13606 100644
--- a/src/main/kotlin/it/my/application/Something.kt
+++ b/src/main/kotlin/other/my/application/Something.kt
@@ -1,10 +1,11 @@
-package it.my.application
+package other.my.application
import io.micronaut.runtime.event.annotation.EventListener
import io.micronaut.transaction.annotation.TransactionalEventListener
import io.micronaut.transaction.annotation.TransactionalEventListener.TransactionPhase
import org.slf4j.LoggerFactory
import javax.inject.Singleton
+import javax.transaction.Transactional
typealias SomethingId = Int
As you can see from this hunk:
- the change of the
packageline is properly reported - the addition of the
Transactionalimport is properly reported - no mention of the removal of the
SomethingFacadeline!
When trying to apply the patch git fails saying that "it does not match"..
I tried generating the patch with -C 2/1/0 and they all fail in some way or another (Note: I'm generating a single patch for the whole directory. With -C 0 I believe this file works but countless other files do not).
I can do git apply --3way and fix stuff manually, but doing this the problem does not get actually caught... the result is:
package other.my.application
import io.micronaut.runtime.event.annotation.EventListener
import io.micronaut.transaction.annotation.TransactionalEventListener
import io.micronaut.transaction.annotation.TransactionalEventListener.TransactionPhase
import it.my.application.SomethingFacade
import org.slf4j.LoggerFactory
import javax.inject.Singleton
import javax.transaction.Transactional
typealias SomethingId = Int
So the line about SomethingFacade is left behind. This is the output of the merge for this file:
Checking patch src/main/kotlin/it/my/application/Something.kt => src/main/kotlin/other/my/application/Something.kt...
error: while searching for:
package it.my.application
import io.micronaut.runtime.event.annotation.EventListener
import io.micronaut.transaction.annotation.TransactionalEventListener
import io.micronaut.transaction.annotation.TransactionalEventListener.TransactionPhase
import org.slf4j.LoggerFactory
import javax.inject.Singleton
typealias SomethingId = Int
error: patch failed: src/main/kotlin/it/my/application/Something.kt:1
Falling back to three-way merge...
Shouldn't git generate either:
--- a/src/main/kotlin/it/my/application/Something.kt
+++ b/src/main/kotlin/other/my/application/Something.kt
@@ -1,10 +1,11 @@
-package it.my.application
+package other.my.application
import io.micronaut.runtime.event.annotation.EventListener
import io.micronaut.transaction.annotation.TransactionalEventListener
import io.micronaut.transaction.annotation.TransactionalEventListener.TransactionPhase
-import it.my.application.SomethingFacade
import org.slf4j.LoggerFactory
import javax.inject.Singleton
+import javax.transaction.Transactional
typealias SomethingId = Int
or something like:
--- a/src/main/kotlin/it/my/application/Something.kt
+++ b/src/main/kotlin/other/my/application/Something.kt
@@ -1,3 +1,3 @@
-package it.my.application
+package other.my.application
import io.micronaut.runtime.event.annotation.EventListener
@@ -4,7 +4,8 @@
import io.micronaut.transaction.annotation.TransactionalEventListener
import io.micronaut.transaction.annotation.TransactionalEventListener.TransactionPhase
-import it.my.application.SomethingFacade
import org.slf4j.LoggerFactory
@@ -7,10 +8,11 @@
import javax.inject.Singleton
+import javax.transaction.Transactional
typealias SomethingId = Int
?
Why does it simply ignore the SomethingFacade line?
Additional information (not sure whether this is relevant):
The A tag is on a previous commit of the master branch whose contents are identical to the HEAD of the B branch. The B branch was created from a previous version of master where all the commits were squashed into a single commit.
The point of branch B is that it should hide the commit activity & authors of the original commits. We periodically sync master with B by squashing all new commits into a single commit in B. So branch B and master do not have a common history but for every commit of B there is a commit of master whose content is identical.
I'm not sure whether this creates an issue with git diff... I have successfully used this approach in other code bases without issues.