New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project.git=true inside git repo causes FNFEs #960

Closed
annappropriate opened this Issue Jun 2, 2017 · 5 comments

Comments

3 participants
@annappropriate
Contributor

annappropriate commented Jun 2, 2017

Scalafmt fails to correctly detect path for files if project is under git and project.git=true

Workspace

[/tmp/scalafmt-git-test]$ tree -a
.
├── bin
│   └── scalafmt
├── .git
│   └── <standard git stuff, skipping>
└── scala-sources
    └── build.sbt

[/tmp/scalafmt-git-test]$ bin/scalafmt --version
scalafmt 1.0.0-RC1

[/tmp/scalafmt-git-test]$ git --version
git version 2.13.0

project.git=false → scalafmt works

[/tmp/scalafmt-git-test/scala-sources]$ ../bin/scalafmt --config-str 'project.git=false' --test --debug
Working directory: /tmp/scalafmt-git-test/scala-sources
Formatting files: List(FileContents(/tmp/scalafmt-git-test/scala-sources/build.sbt))
Exception in thread "main" org.scalafmt.Error$MisformattedFile: /tmp/scalafmt-git-test/scala-sources/build.sbt is mis-formatted. 
	...

project.git=true → scalafmt fails

[/tmp/scalafmt-git-test/scala-sources]$ ../bin/scalafmt --config-str 'project.git=true' --test --debug
Working directory: /tmp/scalafmt-git-test/scala-sources
Formatting files: List(FileContents(/tmp/scalafmt-git-test/build.sbt))
Exception in thread "main" java.io.FileNotFoundException: /tmp/scalafmt-git-test/build.sbt (No such file or directory)
	at java.io.FileInputStream.open0(Native Method)
	at java.io.FileInputStream.open(FileInputStream.java:195)
	at java.io.FileInputStream.<init>(FileInputStream.java:138)
	at org.scalafmt.util.FileOps$.readFile(FileOps.scala:63)
	at org.scalafmt.util.FileOps$.readFile(FileOps.scala:51)
	at org.scalafmt.cli.InputMethod$FileContents.readInput(InputMethod.scala:40)
	at org.scalafmt.cli.Cli$.handleFile(Cli.scala:112)
	at org.scalafmt.cli.Cli$.$anonfun$run$1(Cli.scala:175)
	at org.scalafmt.cli.Cli$.$anonfun$run$1$adapted(Cli.scala:173)
	at scala.collection.Iterator.foreach(Iterator.scala:929)
	...

For some reason, drops scala-sources from path

Reproducible setup

[/tmp]$ mkdir -p scalafmt-git-test/{bin,scala-sources}

[/tmp]$ cd scalafmt-git-test

[/tmp/scalafmt-git-test]$ coursier bootstrap com.geirsson:scalafmt-cli_2.12:1.0.0-RC1 -o bin/scalafmt -f --main org.scalafmt.cli.Cli

[/tmp/scalafmt-git-test]$ cat > scala-sources/build.sbt
lazy val root   =    (project in file("."))

[/tmp/scalafmt-git-test]$ git init && git add . && git commit -am "Init"
Initialized empty Git repository in /tmp/scalafmt-git-test/.git/
[master (root-commit) e1b9d2a] Init
 2 files changed, 1 insertion(+)
 create mode 100755 bin/scalafmt
 create mode 100644 scala-sources/build.sbt
@pjrt

This comment has been minimized.

Show comment
Hide comment
@pjrt

pjrt Jun 2, 2017

Collaborator

So it looks like #927 wasn't actually fixed. Bummer.

Collaborator

pjrt commented Jun 2, 2017

So it looks like #927 wasn't actually fixed. Bummer.

@pjrt pjrt added the bug label Jun 2, 2017

@pjrt pjrt self-assigned this Jun 2, 2017

pjrt added a commit to pjrt/scalafmt that referenced this issue Jun 2, 2017

Fix scalameta#960 and scalameta#927: Oddness with git and non-root
Fixes an issue where git commands would act oddly if `scalafmt` is called
from where NOT at the git root.

@olafurpg olafurpg closed this in d5f24b4 Jun 3, 2017

olafurpg added a commit that referenced this issue Jun 3, 2017

@annappropriate

This comment has been minimized.

Show comment
Hide comment
@annappropriate

annappropriate Jun 4, 2017

Contributor

@olafurpg @pjrt can you make a new version so I can test it?

Contributor

annappropriate commented Jun 4, 2017

@olafurpg @pjrt can you make a new version so I can test it?

@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Jun 4, 2017

Member

@anna-zzz you can build the fatjar locally with cli/assembly I won't have time today to release RC2, I will try to get it out in the coming week

Member

olafurpg commented Jun 4, 2017

@anna-zzz you can build the fatjar locally with cli/assembly I won't have time today to release RC2, I will try to get it out in the coming week

@annappropriate

This comment has been minimized.

Show comment
Hide comment
@annappropriate

annappropriate Jun 7, 2017

Contributor

I'd love RC2 as I'm including scalafmt as a coursier-pulled "dependency" in my project!

Contributor

annappropriate commented Jun 7, 2017

I'd love RC2 as I'm including scalafmt as a coursier-pulled "dependency" in my project!

@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Jun 8, 2017

Member

I just published RC2 and enabled auto-publish pre-releases on merge to hopefully not block again like this #968 The changelog is still behind tho, #970

Member

olafurpg commented Jun 8, 2017

I just published RC2 and enabled auto-publish pre-releases on merge to hopefully not block again like this #968 The changelog is still behind tho, #970

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment