Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fix Jenkins error due to bad remote git repo

After trying to run Jenkins tests on a GitHub Pull Request, I'm running into the following error:

error: some local refs could not be updated; try running
00:07:44  'git remote prune [email protected]:myrepo/myrepo.git' to remove any old, conflicting branches

Running any or all of the following does not fix it:

  • git remote prune [email protected]:myrepo/myrepo.git
  • git remote prune origin
  • git fetch origin -t --prune
  • git gc --prune=now

Jenkins is running this command in its workspace:

git fetch --tags --progress origin  +refs/pull/*:refs/remotes/origin/pr/*

Which shows me that there is a bad ref on the remote:

git fetch --tags --progress origin  +refs/pul
l/*:refs/remotes/origin/pr/*
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
error: 'refs/remotes/origin/pr/2730' exists; cannot create 'refs/remotes/origin/pr/2730/head'
From github.com:myrepo/myrepo
 ! [new branch]      refs/pull/2730/head -> origin/pr/2730/head  (unable to update local ref)
error: some local refs could not be updated; try running
 'git remote prune origin' to remove any old, conflicting branches

There is a ticket closed as Won't Fix on Jenkins about a similar error: JENKINS-19591

I've tried deleting the remote ref:

git push origin :refs/origin/pr/2730/head
Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.
remote: warning: Deleting a non-existent ref.
To [email protected]:myrepo/myrepo.git
- [deleted]        refs/origin/pr/2730/head

I still run into the same error afterwards :-(

How can I fix the remote Pull Request ref?

After checking in .git/logs/refs/remotes/origin/pr/ I found that the branch it is complaining about is the only one which is a normal file:

$ ls -ld .git/logs/refs/remotes/origin/pr/273*
drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/273
-rw-rw-r-- 1 jenkins jenkins  248 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2730
drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2731
drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2732
drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2733
drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2734
drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2735


$ file .git/logs/refs/remotes/origin/pr/273*
.git/logs/refs/remotes/origin/pr/273:  directory
.git/logs/refs/remotes/origin/pr/2730: ASCII text
.git/logs/refs/remotes/origin/pr/2731: directory
.git/logs/refs/remotes/origin/pr/2732: directory
.git/logs/refs/remotes/origin/pr/2733: directory
.git/logs/refs/remotes/origin/pr/2734: directory
.git/logs/refs/remotes/origin/pr/2735: directory
.git/logs/refs/remotes/origin/pr/2736: directory
.git/logs/refs/remotes/origin/pr/2737: directory
.git/logs/refs/remotes/origin/pr/2738: directory
.git/logs/refs/remotes/origin/pr/2739: directory

$ find .git/logs/refs/remotes/origin/pr/ -maxdepth 1 -type f
.git/logs/refs/remotes/origin/pr/2730

$ cat .git/logs/refs/remotes/origin/pr/2730
0000000000000000000000000000000000000000 0c960f4b8bf30109536ec1b7a1d54a636e21fd87 Jenkins <[email protected]> 1395389111 +0000 fetch --tags --progress [email protected]:TangoGroup/program_creator.git +refs/heads/*:refs/remotes/origin/*: storing head

The contents look a bit strange... not sure whether that's how it is supposed to be...

like image 801
TrinitronX Avatar asked Oct 20 '25 16:10

TrinitronX


2 Answers

Try running

git push origin :refs/remotes/origin/pr/2730/merge 
git push origin :refs/remotes/origin/pr/2730/head 

to remove the remote PR branches and rerun your Jenkins job.

like image 127
iamnotpretending Avatar answered Oct 23 '25 07:10

iamnotpretending


Judging by this part:

error: 'refs/remotes/origin/pr/2730' exists; cannot create 'refs/remotes/origin/pr/2730/head'

It seems your Jenkins job has a dirty workspace: it's as if the .git/logs/refs/remotes/origin/pr/2730/head file exists but it cannot replace it. Not to mention, it's strange that it's trying to create it even though it doesn't exist in your remote.

Do you mind wiping out your workspace? Jenkins has a menu option for that. After you do that, make sure the workspace directory is really deleted. Confirm that by looking directly in the filesystem, if you can.

UPDATE

As you can reproduce the problem by running git fetch --tags --progress origin +refs/pull/*:refs/remotes/origin/pr/* on another PC, it's evidently not a workspace problem. I think this other question explains well what's going on.

like image 20
janos Avatar answered Oct 23 '25 07:10

janos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!