Trent
Trent

Reputation: 3103

git submodule "you need to resolve your current index first" but there are no merge conflicts

I have this weird issue that I just can't solve. Jenkins is doing the building from a repository.

It checks out the app's current commit (this is correct), and it then initialises submodules (also correct, and finds the correct commit).

But when it tries to do git submodule update --init --recursive repo, it bails with:

app/views/license/edit.html: needs merge

The problem is there are no conflicts, and that file in the current committed source is perfectly fine...

I just have no idea where to go from here.

 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url [email protected]:TEAM/api-backend.git # timeout=10
Fetching upstream changes from [email protected]:TEAM/api-backend.git
 > git --version # timeout=10
using GIT_SSH to set credentials
 > git fetch --tags --progress [email protected]:TEAM/api-backend.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/dev^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/refs/heads/dev^{commit} # timeout=10
Checking out Revision 99ab7742966fd82f21044e7bf5f405eaf3bd085b (refs/remotes/origin/dev)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 99ab7742966fd82f21044e7bf5f405eaf3bd085b
Commit message: "Front-end update"
 > git rev-list --no-walk 99ab7742966fd82f21044e7bf5f405eaf3bd085b # timeout=10
 > git remote # timeout=10
 > git submodule init # timeout=10
 > git submodule sync # timeout=10
 > git config --get remote.origin.url # timeout=10
 > git submodule init # timeout=10
 > git config -f .gitmodules --get-regexp ^submodule\.(.+)\.url # timeout=10
 > git config --get submodule.compose/web.url # timeout=10
 > git config -f .gitmodules --get submodule.compose/web.path # timeout=10
 > git submodule update --init --recursive compose/web
hudson.plugins.git.GitException: Command "git submodule update --init --recursive compose/web" returned status code 1:
stdout: app/views/license/edit.html: needs merge

stderr: error: you need to resolve your current index first
Unable to checkout '71e9f5f5d30ec8b2bcd7d341e4b607ab123a4ece' in submodule path 'compose/web'

I tried a dummy commit with some changes to the file in question and merged to dev to branch, but that didn't solve it...

What confuses me, is why isn't it telling me there are conflicts when I merge?

Further tests

I did a fresh clone of the parent repository and ran git submodule --init --recursive compose/web. And it cloned and checked out the right branch successfully...

So I can't even replicate this locally.

How can I fix it?

Upvotes: 4

Views: 10946

Answers (5)

pancakesmaplesyrup
pancakesmaplesyrup

Reputation: 101

I had the same issue in Jenkins. I had cloned a pipeline and was receiving the same error. Try deleting the workspaces related to the pipeline in C:\Program Files (x86)\Jenkins\workspace and build the project again in Jenkins.

Upvotes: 0

Tejsingh
Tejsingh

Reputation: 297

Regarding the error,

error: you need to resolve your current index first

git reset --merge or git merge --abort will not work if you already accepted a current or incoming change into your file. Just follow these steps:

  1. git add "fileName" - the file on which you accepted changes
  2. git commit -m "your commit msg"

Now you can checkout to or merge other branches.

Upvotes: 0

ephemerr
ephemerr

Reputation: 1983

It looks like you have merge conflict. Try:

git mergetool app/views/license/edit.html

Upvotes: -1

Joshua
Joshua

Reputation: 43300

I got to this location from a completely different pathway. I tried to bail out of a bad merge and broke the local tree. I can't tell if this is due to a bug in git or some other pathway, but I ran git merge --quit followed by git switch master (the current workspace was a detached head so it doesn't need to be put back in a sane state). The tree became broken as it had a merge conflicted file but no merge in progress.

Krishnamoorthy Acharya's deleted answer contains the base form of how to salvage it, updated here:

git reset
git restore .
git switch master

After git reset, the merge-conflicted file changed to edited, then git restore . abandoned all pending changes so git switch was happy.

Upvotes: 7

VonC
VonC

Reputation: 1325315

As commented, the issue was at the Jenkins workspace level.

If the job is rebuilt from scratch (empty workspace), the problem goes away.

Upvotes: 2

Related Questions