-
Notifications
You must be signed in to change notification settings - Fork 18
ADFA-2885: Handle merge conflicts #1167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stage
Are you sure you want to change the base?
Changes from all commits
8f9bdad
8d8d1c4
578dbea
d97106c
b096948
3aafb64
c44b4dc
988b42e
bf4a48c
0bcc3e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ import kotlinx.coroutines.Dispatchers | |||||||||||||||||||||||
| import kotlinx.coroutines.withContext | ||||||||||||||||||||||||
| import org.eclipse.jgit.api.Git | ||||||||||||||||||||||||
| import org.eclipse.jgit.api.ListBranchCommand.ListMode | ||||||||||||||||||||||||
| import org.eclipse.jgit.api.MergeResult | ||||||||||||||||||||||||
| import org.eclipse.jgit.diff.DiffFormatter | ||||||||||||||||||||||||
| import org.eclipse.jgit.dircache.DirCacheIterator | ||||||||||||||||||||||||
| import org.eclipse.jgit.lib.BranchConfig | ||||||||||||||||||||||||
|
|
@@ -22,6 +23,8 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder | |||||||||||||||||||||||
| import org.eclipse.jgit.transport.CredentialsProvider | ||||||||||||||||||||||||
| import org.eclipse.jgit.transport.PushResult | ||||||||||||||||||||||||
| import org.eclipse.jgit.api.PullResult | ||||||||||||||||||||||||
| import org.eclipse.jgit.api.ResetCommand.ResetType | ||||||||||||||||||||||||
| import org.eclipse.jgit.lib.RepositoryState | ||||||||||||||||||||||||
| import org.eclipse.jgit.treewalk.AbstractTreeIterator | ||||||||||||||||||||||||
| import org.eclipse.jgit.treewalk.CanonicalTreeParser | ||||||||||||||||||||||||
| import org.eclipse.jgit.treewalk.EmptyTreeIterator | ||||||||||||||||||||||||
|
|
@@ -76,11 +79,12 @@ class JGitRepository(override val rootDir: File) : GitRepository { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| jgitStatus.conflicting.forEach { conflicted.add(FileChange(it, ChangeType.CONFLICTED)) } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| val isMerging = repository.repositoryState == RepositoryState.MERGING | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| GitStatus( | ||||||||||||||||||||||||
| isClean = jgitStatus.isClean, | ||||||||||||||||||||||||
| hasConflicts = jgitStatus.conflicting.isNotEmpty(), | ||||||||||||||||||||||||
| isMerging = isMerging, | ||||||||||||||||||||||||
dara-abijo-adfa marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| staged = staged, | ||||||||||||||||||||||||
| unstaged = unstaged, | ||||||||||||||||||||||||
| untracked = untracked, | ||||||||||||||||||||||||
|
|
@@ -272,6 +276,25 @@ class JGitRepository(override val rootDir: File) : GitRepository { | |||||||||||||||||||||||
| pullCommand.call() | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| override suspend fun merge(branchName: String): MergeResult = withContext(Dispatchers.IO) { | ||||||||||||||||||||||||
| val branchRef = repository.findRef(branchName) ?: throw IllegalArgumentException("Branch $branchName not found") | ||||||||||||||||||||||||
| git.merge().include(branchRef).call() | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| override suspend fun abortMerge(): Unit = withContext(Dispatchers.IO) { | ||||||||||||||||||||||||
| // Reset working tree and index to HEAD | ||||||||||||||||||||||||
| git.reset().setMode(ResetType.HARD).setRef(Constants.ORIG_HEAD).call() | ||||||||||||||||||||||||
|
Comment on lines
+284
to
+286
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard This hard-resets to Suggested fix override suspend fun abortMerge(): Unit = withContext(Dispatchers.IO) {
+ if (repository.repositoryState != RepositoryState.MERGING) {
+ return@withContext
+ }
+
// Reset working tree and index to HEAD
git.reset().setMode(ResetType.HARD).setRef(Constants.ORIG_HEAD).call()
// Explicitly clear merge-related files to exit the MERGING state
repository.apply {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Explicitly clear merge-related files to exit the MERGING state | ||||||||||||||||||||||||
| repository.apply { | ||||||||||||||||||||||||
| writeMergeHeads(null) | ||||||||||||||||||||||||
| writeMergeCommitMsg(null) | ||||||||||||||||||||||||
| writeCherryPickHead(null) | ||||||||||||||||||||||||
| writeRevertHead(null) | ||||||||||||||||||||||||
| writeSquashCommitMsg(null) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| override fun close() { | ||||||||||||||||||||||||
| repository.close() | ||||||||||||||||||||||||
| git.close() | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.