This is an automated email from the ASF dual-hosted git repository.

jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 25b138c6b [#4329] improvement(build): fix get commit id failed as a 
submodule (#4330)
25b138c6b is described below

commit 25b138c6b685a787cab83bb735da42e802f0f247
Author: mchades <[email protected]>
AuthorDate: Thu Aug 1 15:15:19 2024 +0800

    [#4329] improvement(build): fix get commit id failed as a submodule (#4330)
    
    ### What changes were proposed in this pull request?
    
    fix get commit id failed as a submodule
    
    ### Why are the changes needed?
    
    when the project is a submodule, the `.git` is a file, not a directory,
    we should handle the case
    
    Fix: #4329
    
    ### Does this PR introduce _any_ user-facing change?
    
    no
    
    ### How was this patch tested?
    
    test locally by hand
---
 common/build.gradle.kts | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/common/build.gradle.kts b/common/build.gradle.kts
index 1f341257c..91e2d137f 100644
--- a/common/build.gradle.kts
+++ b/common/build.gradle.kts
@@ -52,13 +52,20 @@ dependencies {
 fun getGitCommitId(): String {
   var gitCommitId: String
   try {
-    val gitFolder = rootDir.path + "/.git/"
-    val head = File(gitFolder + "HEAD").readText().split(":")
+    val gitPath = File(rootDir.path, ".git")
+    val gitFolder = if (gitPath.isDirectory) {
+      gitPath
+    } else {
+      val content = gitPath.readText().trim()
+      File(rootDir.path, content.substringAfter("gitdir: ").trim())
+    }
+
+    val head = File(gitFolder, "HEAD").readText().split(":")
     val isCommit = head.size == 1
     gitCommitId = if (isCommit) {
       head[0].trim()
     } else {
-      val refHead = File(gitFolder + head[1].trim())
+      val refHead = File(gitFolder, head[1].trim())
       refHead.readText().trim()
     }
   } catch (e: Exception) {

Reply via email to