sbt-release icon indicating copy to clipboard operation
sbt-release copied to clipboard

Pushing to Git from Travis fails: fatal: ref HEAD is not a symbolic ref

Open alexflav23 opened this issue 7 years ago • 12 comments

  git branch --set-upstream ${TRAVIS_BRANCH} origin/${TRAVIS_BRANCH}

  git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
  git config branch.${TRAVIS_BRANCH}.remote origin
  git config branch.${TRAVIS_BRANCH}.merge refs/heads/${TRAVIS_BRANCH}

  git fetch --unshallow origin/${TRAVIS_BRANCH}

Have also tried:

install:
  - git fetch --unshallow --tags

Have tried all of the above, and yet to no avail.

Is there a way to do this properly? All the web trivia found is largely represented above but it doesn't seem to work.

alexflav23 avatar Aug 23 '17 23:08 alexflav23

Is this sbt-release plugin issue?

xuwei-k avatar Aug 24 '17 14:08 xuwei-k

@xuwei-k Pushing to git otherwise works perfectly in builds that do not use sbt-release it's only something in this plugin that seems to trigger the problem. I can successfully git push, however the pushCommit stage in this plugin fails.

alexflav23 avatar Aug 24 '17 14:08 alexflav23

Same here. I am running the build using a docker image on Gitlab CI Runner. $ sbt release with-defaults Does it has anything to do with credentials?

[info] Set current project to alderaan (in build file:/builds/juliano.vidal/alderaan/)
[info] Starting release process off commit: 3f65b88c05e625e4ee8193d8e0acc804f04d0982
fatal: ref HEAD is not a symbolic ref
java.lang.RuntimeException: Nonzero exit value: 128
	at scala.sys.package$.error(package.scala:27)
	at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.slurp(ProcessBuilderImpl.scala:131)
	at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang$bang(ProcessBuilderImpl.scala:101)
	at sbtrelease.Git.currentBranch(Vcs.scala:138)
	at sbtrelease.Git.trackingRemoteCmd$lzycompute(Vcs.scala:133)
	at sbtrelease.Git.trackingRemoteCmd(Vcs.scala:133)
	at sbtrelease.Git.hasUpstream(Vcs.scala:136)
	at sbtrelease.ReleaseStateTransformations$$anonfun$checkUpstream$1.apply(ReleaseExtra.scala:215)
	at sbtrelease.ReleaseStateTransformations$$anonfun$checkUpstream$1.apply(ReleaseExtra.scala:214)
	at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5$$anonfun$apply$4.apply(ReleasePlugin.scala:193)
	at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5$$anonfun$apply$4.apply(ReleasePlugin.scala:193)
	at scala.collection.immutable.List.foreach(List.scala:318)
	at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5.apply(ReleasePlugin.scala:193)
	at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5.apply(ReleasePlugin.scala:157)
	at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
	at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
	at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
	at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
	at sbt.Command$.process(Command.scala:93)
	at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
	at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
	at sbt.State$$anon$1.doX$1(State.scala:183)
	at sbt.State$$anon$1.process(State.scala:190)
	at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
	at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
	at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
	at sbt.MainLoop$.next(MainLoop.scala:96)
	at sbt.MainLoop$.run(MainLoop.scala:89)
	at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:68)
	at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:63)
	at sbt.Using.apply(Using.scala:24)
	at sbt.MainLoop$.runWithNewLog(MainLoop.scala:63)
	at sbt.MainLoop$.runAndClearLast(MainLoop.scala:46)
	at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:30)
	at sbt.MainLoop$.runLogged(MainLoop.scala:22)
	at sbt.StandardMain$.runManaged(Main.scala:109)
	at sbt.xMain.run(Main.scala:38)
	at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
	at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
	at xsbt.boot.Launch$.run(Launch.scala:109)
	at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
	at xsbt.boot.Launch$.launch(Launch.scala:117)
	at xsbt.boot.Launch$.apply(Launch.scala:18)
	at xsbt.boot.Boot$.runImpl(Boot.scala:41)
	at xsbt.boot.Boot$.main(Boot.scala:17)
	at xsbt.boot.Boot.main(Boot.scala)
[error] Nonzero exit value: 128
[error] Use 'last' for the full log.

julianovidal avatar Sep 18 '17 15:09 julianovidal

I am getting the same error while trying to use sbt-release in a Jenkins job. It works okay locally but when running "release with-defaults" in Jenkins I get:

fatal: ref HEAD is not a symbolic ref java.lang.RuntimeException: Nonzero exit value: 128 at scala.sys.package$.error(package.scala:27) at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.slurp(ProcessBuilderImpl.scala:131) at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang$bang(ProcessBuilderImpl.scala:101) at sbtrelease.Git.currentBranch(Vcs.scala:138) at sbtrelease.Git.trackingRemoteCmd$lzycompute(Vcs.scala:133) at sbtrelease.Git.trackingRemoteCmd(Vcs.scala:133) at sbtrelease.Git.hasUpstream(Vcs.scala:136) at sbtrelease.ReleaseStateTransformations$$anonfun$checkUpstream$1.apply(ReleaseExtra.scala:215) at sbtrelease.ReleaseStateTransformations$$anonfun$checkUpstream$1.apply(ReleaseExtra.scala:214) at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5$$anonfun$apply$4.apply(ReleasePlugin.scala:193) at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5$$anonfun$apply$4.apply(ReleasePlugin.scala:193) at scala.collection.immutable.List.foreach(List.scala:318) at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5.apply(ReleasePlugin.scala:193) at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5.apply(ReleasePlugin.scala:157) at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59) at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59) at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61) at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61) at sbt.Command$.process(Command.scala:93) at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96) at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96) at sbt.State$$anon$1.doX$1(State.scala:183) at sbt.State$$anon$1.process(State.scala:190) at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96) at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96) at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17) at sbt.MainLoop$.next(MainLoop.scala:96) at sbt.MainLoop$.run(MainLoop.scala:89) at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:68) at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:63) at sbt.Using.apply(Using.scala:24) at sbt.MainLoop$.runWithNewLog(MainLoop.scala:63) at sbt.MainLoop$.runAndClearLast(MainLoop.scala:46) at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:30) at sbt.MainLoop$.runLogged(MainLoop.scala:22) at sbt.StandardMain$.runManaged(Main.scala:109) at sbt.xMain.run(Main.scala:38) at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109) at xsbt.boot.Launch$.withContextLoader(Launch.scala:128) at xsbt.boot.Launch$.run(Launch.scala:109) at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35) at xsbt.boot.Launch$.launch(Launch.scala:117) at xsbt.boot.Launch$.apply(Launch.scala:18) at xsbt.boot.Boot$.runImpl(Boot.scala:41) at xsbt.boot.Boot$.main(Boot.scala:17) at xsbt.boot.Boot.main(Boot.scala) [error] Nonzero exit value: 128

shklarsky avatar Oct 10 '17 12:10 shklarsky

Same error while running "release with-defaults" in travis-ci. I'm using sbt 0.13.15, sbt-release 1.0.6. Anyone managed to find a fix?

[info] Starting release process off commit: 57d2b83083824621b4b7e95b51fe4449fbf132c5
fatal: ref HEAD is not a symbolic ref
java.lang.RuntimeException: Nonzero exit value: 128
	at scala.sys.package$.error(package.scala:27)
	at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.slurp(ProcessBuilderImpl.scala:131)
	at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang$bang(ProcessBuilderImpl.scala:101)
	at sbtrelease.Git.currentBranch(Vcs.scala:138)
	at sbtrelease.Git.trackingRemoteCmd$lzycompute(Vcs.scala:133)
	at sbtrelease.Git.trackingRemoteCmd(Vcs.scala:133)
	at sbtrelease.Git.hasUpstream(Vcs.scala:136)
	at sbtrelease.ReleaseStateTransformations$$anonfun$checkUpstream$1.apply(ReleaseExtra.scala:215)
	at sbtrelease.ReleaseStateTransformations$$anonfun$checkUpstream$1.apply(ReleaseExtra.scala:214)
	at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5$$anonfun$apply$4.apply(ReleasePlugin.scala:193)
	at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5$$anonfun$apply$4.apply(ReleasePlugin.scala:193)
	at scala.collection.immutable.List.foreach(List.scala:318)
	at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5.apply(ReleasePlugin.scala:193)
	at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$$anonfun$5.apply(ReleasePlugin.scala:157)
	at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
	at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
	at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
	at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
	at sbt.Command$.process(Command.scala:93)
	at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
	at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
	at sbt.State$$anon$1.doX$1(State.scala:183)
	at sbt.State$$anon$1.process(State.scala:190)
	at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
	at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
	at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
	at sbt.MainLoop$.next(MainLoop.scala:96)
	at sbt.MainLoop$.run(MainLoop.scala:89)
	at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:68)
	at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:63)
	at sbt.Using.apply(Using.scala:24)
	at sbt.MainLoop$.runWithNewLog(MainLoop.scala:63)
	at sbt.MainLoop$.runAndClearLast(MainLoop.scala:46)
	at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:30)
	at sbt.MainLoop$.runLogged(MainLoop.scala:22)
	at sbt.StandardMain$.runManaged(Main.scala:109)
	at sbt.xMain.run(Main.scala:38)
	at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
	at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
	at xsbt.boot.Launch$.run(Launch.scala:109)
	at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
	at xsbt.boot.Launch$.launch(Launch.scala:117)
	at xsbt.boot.Launch$.apply(Launch.scala:18)
	at xsbt.boot.Boot$.runImpl(Boot.scala:41)
	at xsbt.boot.Boot$.main(Boot.scala:17)
	at xsbt.boot.Boot.main(Boot.scala)
[error] Nonzero exit value: 128
[error] Use 'last' for the full log.

SrikanthTati avatar Oct 29 '17 16:10 SrikanthTati

I have managed to fix this issue. "release with-defaults" attempts to push changes to version.sbt to the current branch (in my case the master).
When Jenkins performs git clone of a repository it is detached from the head. I Just performed git checkout master before running "release with-defaults" and it fixed the issue

shklarsky avatar Oct 30 '17 07:10 shklarsky

@shklarsky @SrikanthTati @julianovidal

I have this in Travis and I call it as part of the setup, and it seems to work. I don't pretend to understand the fine print just yet, or why this doesn't work inspite of you forcing non shallow git cloning, but there you go.

#!/usr/bin/env bash
function fix_git {
    echo "Fixing git setup for $TRAVIS_BRANCH"
    git checkout ${TRAVIS_BRANCH}
    git branch -u origin/${TRAVIS_BRANCH}
    git config branch.${TRAVIS_BRANCH}.remote origin
    git config branch.${TRAVIS_BRANCH}.merge refs/heads/${TRAVIS_BRANCH}
}

alexflav23 avatar Nov 30 '17 14:11 alexflav23

Hi all, we have the same problem in latest Jenkins, due to the way it gets sources from git repos. FYI as a workaround we solved by forcing a checkout in a similar way shown here.

smartiniOnGitHub avatar Aug 08 '18 11:08 smartiniOnGitHub

I tried the same solution as above and from this issue https://github.com/sbt/sbt-release/issues/60 but now I'm getting:

[info] Starting release process off commit: 1a76e7d4c92ba30ac7a557c87336c22bb2494c96
[info] Checking remote [origin] ...
[info] ERROR: Repository not found.
[info] fatal: Could not read from remote repository.
[info] Please make sure you have the correct access rights
[info] and the repository exists.
Error while checking remote. Still continue (y/n)? [n] [error] java.lang.RuntimeException: Aborting the release!

any ideas?

lukaszlenart avatar Sep 11 '19 10:09 lukaszlenart

Earlier I was getting this error, fatal: ref HEAD is not a symbolic ref . After proceeding as per the mentioned solutions, I am getting error as [0m[[0m[0minfo[0m] [0m[0m fatal: unable to fork[0m [0m[[0m[31merror[0m] [0m[0mjava.lang.RuntimeException: Aborting the release![0m [0m[[0m[31merror[0m] [0m[0m at scala.sys.package$.error(package.scala:26)[0m [0m[[0m[31merror[0m] [0m[0m at sbtrelease.ReleaseStateTransformations$.$anonfun$checkUpstream$1(ReleaseExtra.scala:230)[0m [0m[[0m[31merror[0m] [0m[0m at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$.$anonfun$releaseCommand$10(ReleasePlugin.scala:199)[0m [0m[[0m[31merror[0m] [0m[0m at scala.collection.immutable.List.foreach(List.scala:388)[0m [0m[[0m[31merror[0m] [0m[0m at sbtrelease.ReleasePlugin$autoImport$ReleaseKeys$.$anonfun$releaseCommand$2(ReleasePlugin.scala:199)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.Command$.$anonfun$applyEffect$4(Command.scala:142)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.Command$.$anonfun$applyEffect$2(Command.scala:137)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.Command$.process(Command.scala:181)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.MainLoop$.processCommand(MainLoop.scala:151)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.MainLoop$.$anonfun$next$2(MainLoop.scala:139)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.State$$anon$1.runCmd$1(State.scala:246)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.State$$anon$1.process(State.scala:250)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.MainLoop$.$anonfun$next$1(MainLoop.scala:139)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.MainLoop$.next(MainLoop.scala:139)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.MainLoop$.run(MainLoop.scala:132)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.MainLoop$.$anonfun$runWithNewLog$1(MainLoop.scala:110)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.io.Using.apply(Using.scala:22)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.MainLoop$.runWithNewLog(MainLoop.scala:104)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.MainLoop$.runAndClearLast(MainLoop.scala:59)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:44)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.MainLoop$.runLogged(MainLoop.scala:35)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.StandardMain$.runManaged(Main.scala:138)[0m [0m[[0m[31merror[0m] [0m[0m at sbt.xMain.run(Main.scala:89)[0m [0m[[0m[31merror[0m] [0m[0m at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)[0m [0m[[0m[31merror[0m] [0m[0m at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)[0m [0m[[0m[31merror[0m] [0m[0m at xsbt.boot.Launch$.run(Launch.scala:109)[0m [0m[[0m[31merror[0m] [0m[0m at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)[0m [0m[[0m[31merror[0m] [0m[0m at xsbt.boot.Launch$.launch(Launch.scala:117)[0m [0m[[0m[31merror[0m] [0m[0m at xsbt.boot.Launch$.apply(Launch.scala:18)[0m [0m[[0m[31merror[0m] [0m[0m at xsbt.boot.Boot$.runImpl(Boot.scala:56)[0m [0m[[0m[31merror[0m] [0m[0m at xsbt.boot.Boot$.main(Boot.scala:18)[0m [0m[[0m[31merror[0m] [0m[0m at xsbt.boot.Boot.main(Boot.scala)[0m [0m[[0m[31merror[0m] [0m[0mAborting the release![0m [0m[[0m[31merror[0m] [0m[0mUse 'last' for the full log.[0m

Any Idea about how to resolve this?

abhijeet3112 avatar Feb 03 '20 17:02 abhijeet3112

Travis checks out the specific commit for some reason, rather than the branch name - so for example if you're using master branch to release, add git checkout master && in front of the SBT command.

ScalaWilliam avatar Aug 15 '20 07:08 ScalaWilliam

It would be great if this could be added as an option to the plugin, if it makes sense. (to force checkout of master)

ianpojman avatar Apr 18 '22 19:04 ianpojman