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

not working on project with multiple git repos

Open wpc009 opened this issue 9 years ago • 5 comments

considering a sbt multi project Root (project created using repo):

root/
     build.sbt
     a/
         .git/
          some_a_file
     b/
         .git/
         some_b_file

Since, gitReader is defined under ThisBuild. All the projects share the same gitReader , which's baseDirectory is root/. And it can not find the valid git repo for project a, neither for b.

The same for a project constructed with multiple sub project using git submodule add <sub_project_repo_url> sub_project_name

wpc009 avatar Sep 08 '15 12:09 wpc009

Indeed for a project with a git submodule, I am getting:

java.lang.RuntimeException: Setting value cannot be null: {file:/......}/*:gitCurrentBranch
    at scala.sys.package$.error(package.scala:27)
    at sbt.EvaluateSettings$INode.setValue(INode.scala:143)
    at sbt.EvaluateSettings$MixedNode.evaluate0(INode.scala:175)
    at sbt.EvaluateSettings$INode.evaluate(INode.scala:135)
    at sbt.EvaluateSettings$$anonfun$sbt$EvaluateSettings$$submitEvaluate$1.apply$mcV$sp(INode.scala:69)
    at sbt.EvaluateSettings.sbt$EvaluateSettings$$run0(INode.scala:78)
    at sbt.EvaluateSettings$$anon$3.run(INode.scala:74)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
[error] Setting value cannot be null: {file:/......./*:gitCurrentBranch

matanox avatar Jan 04 '16 15:01 matanox

Using sbt inspect looks like this is coming from SbtGit.scala:87

>inspect gitCurrentBranch
[info] Setting: java.lang.String = master
[info] Description:
[info]  The current branch for this project.
[info] Provided by:
[info]  {file:/.......}/*:gitCurrentBranch
[info] Defined at:
[info]  (com.typesafe.sbt.SbtGit) SbtGit.scala:87
[info] Delegates:
[info]  pipeline/*:gitCurrentBranch
[info]  {.}/*:gitCurrentBranch
[info]  */*:gitCurrentBranch
[info] Related:
[info]  {.}/*:gitCurrentBranch

I cannot tell which version of the plugin the project is pulling in, as sbt-git does not show in the output of sbt plugins, and it is brought in programatically by some sbt plugin rather than being very explicitly added to the project. So I have not been able thus far to pinpoint the line of code.

matanox avatar Jan 04 '16 16:01 matanox

I came across this issue when trying to have the versions in my submodules. In the end as I did not need all fallbacks and I could easily change the repos (just started them), I went simply with

version := {
    val gitV: String = Process("git" :: "describe" :: "--tags" :: Nil, baseDirectory.value) !!
    val hasUncheckedChanges: Boolean = (
      Process("git" :: "diff" :: "--no-ext-diff" :: "--quiet" :: "--exit-code" :: "HEAD" :: Nil).!
    ) != 0
    gitV.trim + (if (hasUncheckedChanges) "-SNAPSHOT" else "")
  } 

without sbt-git. Still I would welcome proper support in sbt-git...

fawzi avatar Feb 28 '16 13:02 fawzi

Supporting Multi-repo project can be done through this setting

GitKeys.gitReader in ThisProject <<= baseDirectory(base => new DefaultReadableGit(base)),

Add this to each sub-project's settings. Then sub-project will using their own gitReader with it's baseDirectory as the DefaultReadableGit 's base. This uses JGit.

wpc009 avatar Mar 15 '16 06:03 wpc009

The syntax for the solution offered by @wpc009 for SBT v0.13.16+ is:

GitKeys.gitReader in ThisProject := baseDirectory(base => new DefaultReadableGit(base)).value,

mslinn avatar Nov 17 '17 04:11 mslinn