Improve reading repo information.

Relying on logs/HEAD in case of CI doesn't work.
This commit is contained in:
Roman Telezhynskyi 2024-03-29 17:20:57 +02:00
parent 2ed50a772e
commit fda3ec4783

View File

@ -84,8 +84,6 @@ Module {
property string tool: toolFilePath
property string theRepoDir: repoDir
property string filePath: FileInfo.joinPaths(metaDataBaseDir, "logs/HEAD")
property var timestamp: File.lastModified(filePath)
property string repoState
property string repoStateTag
@ -93,8 +91,24 @@ Module {
property string repoStateRevision
configure: {
if (!File.exists(filePath))
return; // No commits yet.
var commitsProbe = new Process();
try {
commitsProbe.setWorkingDirectory(theRepoDir);
var exitCode = commitsProbe.exec(tool, ["rev-list", "HEAD", "--count"], false);
if (exitCode !== 0) {
console.info("Cannot read repo state.");
return;
}
var count = parseInt(commitsProbe.readStdOut().trim());
if (count < 1) {
console.info("The repo has no commits yet.");
return;
}
} finally {
commitsProbe.close();
}
var proc = new Process();
try {
proc.setWorkingDirectory(theRepoDir);
@ -108,9 +122,14 @@ Module {
found = true;
const tagSections = repoState.split("-");
if (tagSections.length >= 3) {
repoStateTag = tagSections[0];
repoStateDistance = tagSections[1];
repoStateRevision = tagSections[2];
} else {
repoStateRevision = tagSections[0];
}
}
} finally {
proc.close();