1

I am using JGit (v4.10.0.201712302008-r) to automate tasks that interact with our git repository.

Some of the tasks leave the repo in a REBASING_MERGE state for some reason. Now the next time I process a task, I need to try to "repair" the repository. I have already removed potential conflicted/modified/added but the repo is still in REBASING_MERGE state.

I've tried what is mention there (aborting a merge), but to no avail - the repository status is still the same and I can't do a pull:

org.eclipse.jgit.api.errors.WrongRepositoryStateException: Cannot pull into a repository with state: REBASING_MERGE

Any idea of how to fix this with JGit?

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
Vincent F
  • 6,523
  • 7
  • 37
  • 79

2 Answers2

1

Some commands check the repository state returned from Repository::getRepositoryState before proceeding.

The REBASING_MRGE state is returned if there is a file or directory rebase-merge in the .git directory. If you are sure that it's safe to return to the normal state, you can just delete the fire/directory.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • yeah, I thought about it, but I wanted to avoid it, so that I don't have to checkout again the whole repo. – Vincent F Mar 07 '18 at 15:56
  • I don't understand your comment. Why would you have to checkout again? For the PullCommand to work you would need a repository already. – Rüdiger Herrmann Mar 07 '18 at 18:54
  • sorry, I wasn't clear - I tried cleaning the local repository by doing git.status().call() and resetting the conflicted/added files, and reverting the modified ones. Maybe I was missing something, but the overall status was still REBASING_MERGE. So I thought that worst case, I would be able to delete the local repository and check out a fresh copy. – Vincent F Mar 08 '18 at 09:51
  • Thanks for clarifying. – Rüdiger Herrmann Mar 08 '18 at 10:00
0

Actually I found the answer here : https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/RebaseToOriginMaster.java#L78 (I adapted the code) :

 if(!result.getStatus().isSuccessful()) {
 // if rebasing stopped or failed, you can get back to the original state by running it with setOperation(RebaseCommand.Operation.ABORT)
    result = git.rebase().setUpstream("origin/master").setOperation(RebaseCommand.Operation.ABORT).call();
    System.out.println("Aborted rebase with state: " + result.getStatus() + ": " + result.getConflicts());
 }

I still need to understand why rebase failed, because there were no conflicts initially.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
Vincent F
  • 6,523
  • 7
  • 37
  • 79