Skip to content
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

Could not get top level Git directory #1572

Open
guest73 opened this issue Aug 8, 2024 · 12 comments
Open

Could not get top level Git directory #1572

guest73 opened this issue Aug 8, 2024 · 12 comments
Labels
bug Something isn't working help wanted

Comments

@guest73
Copy link

guest73 commented Aug 8, 2024

Extension Name: vscode-gradle
Extension Version: 3.16.2
OS Version: Linux Mint 21.3
VSCode version: 1.92.0

Describe the bug
When I try to open a Java-Gradle project I get this error message

* What went wrong:
A problem occurred evaluating root project 'fo.server'.
> Failed to apply plugin 'booqstrap.flyway-conventions'.
   > Failed to apply plugin 'booqstrap.misc-conventions'.
      > Could not get top level Git directory, make sure your project is in a valid Git repository

Those plugins are our own custom Gradle plugins to automate some repetitive task for many projects we have. And they require a project to be in a git repo so the version is automatically identified. A simple command

gitRunner.runGitCommand("rev-parse", "--show-toplevel")

is issued for that purpose.
The thing is that Language Support for Java(TM) by Red Hat works fine and there is no such a problem. The project is imported and I can edit code in vscode, do auto-completion ect. But once I install vscode-gradle and do ‘Java: Clean Java Language Server Workspace > Reload and delete‘ - everything breaks.

Expected behavior
My project opens correctly by the plugin without any errors.

Additional context
I expect that some "current directory" is incorrectly set by the extension.

@guest73 guest73 added the bug Something isn't working label Aug 8, 2024
@jdneo
Copy link
Member

jdneo commented Aug 9, 2024

Is it possible to share a sample project for this issue?

@guest73
Copy link
Author

guest73 commented Aug 10, 2024

Hi. Unfortunately it is proprietary code. I cannot share it.

There is simply this piece I found in the custom plugin booqstrap.misc-conventions written by someone else

ext['getGitToplevel'] = { ->
    try {
        final Process process = "git rev-parse --show-toplevel".execute()
        if (process.waitFor() != 0) {
            throw new InvalidUserCodeException("Could not get top level Git directory, make sure your project is in a valid Git repository")
        }
        return process.getInputStream().getText().trim()
    } catch (IOException e) {
        throw new InvalidUserCodeException("Could not get top level Git directory, is Git installed?", e)
    }
}

So, running ./gradlew build from the project's folder, everything works fine but when vscode-gradle tries to build it fails with the aforementioned exception

@jdneo
Copy link
Member

jdneo commented Aug 12, 2024

Or is it possible to describe the folder structure of your project? I need to be able to reproduce it to find the root cause, otherwise, it will be very difficult to fix the issue

@guest73
Copy link
Author

guest73 commented Aug 12, 2024

Thanks for your response.
I guess I can share some screenshots
project-structure.zip
The project is a bit different than the one I originally posted but the problem is the same.

@jdneo
Copy link
Member

jdneo commented Aug 13, 2024

Thank you! for the project of the attached screenshot, is it still reproducible if you remove all the source code and just leave the gradle script files in the directory?

@guest73
Copy link
Author

guest73 commented Aug 16, 2024

Hi.
Yep same errors
image
Removed all java classes and packages and some other unnecessary files.

@guest73
Copy link
Author

guest73 commented Aug 16, 2024

I made a fake project without any plugins and it gives me the same result.
booq.promotions1.zip

@jdneo
Copy link
Member

jdneo commented Aug 19, 2024

Is there any steps required using the attached project?

I tried opening it in my vscode and did not observe any errors.

@guest73
Copy link
Author

guest73 commented Aug 19, 2024

Nope. No extra steps.
And I am getting this

[debug] [gradle-server] Gradle Server cmd: /home/myuser/.vscode/extensions/vscjava.vscode-gradle-3.16.2024081608/lib/gradle-server "--port=40507" "--startBuildServer=true" "--languageServerPipePath=/run/user/1000/a43cf79573bb83394e84b072e9cd8a46.sock" "--pipeName=/run/user/1000/f039ee38553020d79a07746a1c82834b.sock" "--bundleDir=/home/myuser/.vscode/extensions/vscjava.vscode-gradle-3.16.2024081608/server"
[info] [gradle-server] Gradle Server started, listening on 40507
[info] Gradle client connected to server
[debug] Refreshing tasks
[info] Java Home: /opt/jdk/11
[info] JVM Args: --add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-XX:MaxMetaspaceSize=384m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant
[info] Gradle User Home: /home/myuser/.gradle
[info] Gradle Version: 8.2.1
[error] FAILURE: Build failed with an exception.

* Where:
Build file '/depot/booq.promotions1/build.gradle' line: 21

* What went wrong:
A problem occurred evaluating root project 'promotions'.
> Could not get top level Git directory, make sure your project is in a valid Git repository

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

CONFIGURE FAILED in 4s
[error] [gradle-server] The supplied build action failed with an exception.
[error] Error getting build for /depot/booq.promotions1: The supplied build action failed with an exception.
[info] Java Home: /opt/jdk/11
[info] JVM Args: --add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-XX:MaxMetaspaceSize=384m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant
[info] Gradle User Home: /home/myuser/.gradle
[info] Gradle Version: 8.2.1
[error] FAILURE: Build failed with an exception.```

Maybe it is because I am on Linux?

@guest73
Copy link
Author

guest73 commented Aug 20, 2024

What helped, was specifying a full path to the project.

image
This way it works.

Seems like executing a process this way sets up a different working directory.

@jdneo
Copy link
Member

jdneo commented Aug 21, 2024

Thanks, that's a hint that the logic of dealing with the working directory may have some issue. I'll take a look on it.

@jdneo
Copy link
Member

jdneo commented Sep 6, 2024

I found that when I debug the code, the working directory is set correctly. But when run from production code, I get the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted
Projects
None yet
Development

No branches or pull requests

2 participants