Skip to content

Commit f1cdd8d

Browse files
committed
Use directory-specific GitCommit in stackbrew library output
Instead of using the branch head commit for all images, find the last commit that actually changed each image directory. This ensures the GitCommit field accurately reflects when each image was last modified.
1 parent 9452815 commit f1cdd8d

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

generate-stackbrew-library.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def sort_key(d):
7373
dirs.sort(key=sort_key)
7474
return dirs
7575

76+
def get_directory_commit(branch_commit, dir_path):
77+
"""Get the last commit that changed the given directory."""
78+
output = run_command(["git", "log", "-1", "--format=%H", branch_commit, "--", f"{dir_path}/"])
79+
return output.strip()
80+
7681
def get_arches(image, cache):
7782
if image in cache:
7883
return cache[image]
@@ -145,7 +150,8 @@ def main():
145150

146151
first_version = None
147152
for dir_path in directories:
148-
dockerfile = run_command(["git", "show", f"{commit}:{dir_path}/Dockerfile"])
153+
dir_commit = get_directory_commit(commit, dir_path)
154+
dockerfile = run_command(["git", "show", f"{dir_commit}:{dir_path}/Dockerfile"])
149155

150156
# Extract FROM
151157
from_match = re.search(r"^\s*FROM\s+(\S+)", dockerfile, re.MULTILINE | re.IGNORECASE)
@@ -298,7 +304,7 @@ def main():
298304
print(f"\nTags: {', '.join(actual_tags)}")
299305
print(f"Architectures: {arches}")
300306
print(f"GitFetch: refs/heads/{branch}")
301-
print(f"GitCommit: {commit}")
307+
print(f"GitCommit: {dir_commit}")
302308
print(f"Directory: {dir_path}")
303309

304310
if __name__ == "__main__":

0 commit comments

Comments
 (0)