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

generateGitProperties fails when Git's core.fsmonitor is enabled #230

Open
henrik242 opened this issue Feb 21, 2024 · 4 comments
Open

generateGitProperties fails when Git's core.fsmonitor is enabled #230

henrik242 opened this issue Feb 21, 2024 · 4 comments

Comments

@henrik242
Copy link

henrik242 commented Feb 21, 2024

The generateGitProperties task will fail if .git/config contains core.fsmonitor = true:

[core]
	fsmonitor = true

The error is:

Execution failed for task ':my-project:generateGitProperties'.
> Cannot access input property 'source' of task ':fhh-integration:generateGitProperties'. Accessing 
  unreadable inputs or outputs is not supported. Declare the task as untracked by using
  Task.doNotTrackState(). For more information, please refer to
  https://docs.gradle.org/8.6/userguide/incremental_build.html#sec:disable-state-tracking
  in the Gradle documentation.
   > java.io.IOException: Cannot snapshot /Users/me/src/my-project/.git/fsmonitor--daemon.ipc:
     not a regular file

Should be solved by ignoring .git/fsmonitor--daemon.ipc (or generally all sockets) by default.

@henrik242 henrik242 changed the title generateGitProperties fails when Git's core.fsmonitor is enabled generateGitProperties fails when Git's core.fsmonitor is enabled Feb 21, 2024
@henrik242
Copy link
Author

@n0mer Is there a way to exclude .git/fsmonitor--daemon.ipc in the current implementation?

@henrik242
Copy link
Author

henrik242 commented Jul 9, 2024

I have worked around this by ditching this plugin and using an Exec task with a bash script instead.

Bash script:

#!/usr/bin/env bash

# Replacement for the gradle-git-properties plugin since it clashes with git.fsmonitor,
# see https://github.com/n0mer/gradle-git-properties/issues/230

branch=$(git branch --show-current)
host=$(hostname)
user_email=$(git config user.email)
user_name=$(git config user.name)
version="1.0.0-SNAPSHOT"
describe=$(git describe --tags --long)
closest_tag_name=$(git describe --tags)
closest_tag_commit_count=$(git rev-list $(git describe --tags --abbrev=0)..HEAD --count)
commit_id=$(git rev-parse HEAD)
commit_id_abbrev=$(git rev-parse --short HEAD)
commit_message_full=$(git log -1 --pretty=%B | cut -c1-100 | jq -Rsa)
commit_message_short=$(git log -1 --pretty=%s)
commit_time=$(git log -1 --date=format-local:%Y-%m-%dT%H:%M:%S%z --pretty=format:%cd)
commit_user_email=$(git log -1 --pretty=%ce)
commit_user_name=$(git log -1 --pretty=%cn)
dirty=$(git diff-index --quiet HEAD -- || echo "true")
[ -z "$dirty" ] && dirty="false"
remote_origin_url=$(git config --get remote.origin.url)
tags=$(git tag --points-at HEAD)
total_commit_count=$(git rev-list --count HEAD)

cat <<EOL > git.properties
git.branch=${branch}
git.build.host=${host}
git.build.user.email=${user_email}
git.build.user.name=${user_name}
git.build.version=${version}
git.closest.tag.commit.count=${closest_tag_commit_count}
git.closest.tag.name=${closest_tag_name}
git.commit.id=${commit_id}
git.commit.id.abbrev=${commit_id_abbrev}
git.commit.id.describe=${describe}
git.commit.message.full=${commit_message_full}
git.commit.message.short=${commit_message_short}
git.commit.time=${commit_time}
git.commit.user.email=${commit_user_email}
git.commit.user.name=${commit_user_name}
git.dirty=${dirty}
git.remote.origin.url=${remote_origin_url}
git.tags=${tags}
git.total.commit.count=${total_commit_count}
EOL

Gradle task:

val generateGitProperties by tasks.registering(Exec::class) {
  description = "Generates git.properties file with git information"
  group = "Build"
  workingDir = project.layout.buildDirectory.dir("resources/main").get().asFile
  outputs.file(project.layout.buildDirectory.file("resources/main/git.properties"))
  commandLine("$rootDir/tools/utils/generate-git-properties.sh")
}
named("assemble") { dependsOn(generateGitProperties) }

@someok
Copy link

someok commented Nov 25, 2024

Temporary solution:

This issue is due to the addition of the fsmonitor daemon in git, which can be disabled using the following method.

  1. Current git closed

    git fsmonitor--daemon stop

  2. Global

    git config --global core.fsmonitor false

@joschi
Copy link
Contributor

joschi commented Nov 25, 2024

Alternatively you can also disable state tracking for GenerateGitPropertiesTask in your Gradle build:

tasks.withType(com.gorylenko.GenerateGitPropertiesTask::class.java) {
  // https://github.com/n0mer/gradle-git-properties/issues/230
  doNotTrackState(".git/fsmonitor--daemon.ipc: not a regular file")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants