From 0b669b61e9e78bbae6399be005187509b47c01bc Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Sat, 2 Sep 2023 17:04:27 +0100 Subject: [PATCH] Improve GIT versiion retrieval code to work with worktrees --- renderdoc/renderdoc_version.vcxproj | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/renderdoc/renderdoc_version.vcxproj b/renderdoc/renderdoc_version.vcxproj index f41b6f668..054ea5248 100644 --- a/renderdoc/renderdoc_version.vcxproj +++ b/renderdoc/renderdoc_version.vcxproj @@ -132,12 +132,24 @@ namespace GitIntrospection { return !Log.HasLoggedErrors; } private void GetCommit() { - string HEADpath = Repository + ".git\\HEAD"; + string dotGITpath = Repository + ".git"; + string refGITpath = dotGITpath; + if(File.Exists(dotGITpath)) { + string gitData = File.ReadAllText(dotGITpath).Trim(); + if(gitData.StartsWith("gitdir: ")) { + dotGITpath = Repository + gitData.Substring(8).Replace('/', '\\'); + int index = dotGITpath.IndexOf(".git"); + if (index >= 0) { + refGITpath = dotGITpath.Substring(0, index+4); + } + } + } + string HEADpath = dotGITpath + "\\HEAD"; if(File.Exists(HEADpath)) { string HEADref = File.ReadAllText(HEADpath).Trim(); if(HEADref.StartsWith("ref: ")) { - string refpath = Repository + ".git\\" + HEADref.Substring(5).Replace('/', '\\'); + string refpath = refGITpath + "\\" + HEADref.Substring(5).Replace('/', '\\'); if(File.Exists(refpath)) Sha1 = File.ReadAllText(refpath).Trim(); } else {