Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2b84784

Browse files
committedFeb 28, 2025··
cmd-diff: support showing source-control diffs for two builds
Useful for trying to determine the changes that occured for two builds that were outside of RPM changes. Example: ``` $ cosa diff --source-control --from=42.20240919.91.0 --to=42.20240920.91.0 https://github.com/coreos/fedora-coreos-config: 80f646d..051fb67 --> coreos/fedora-coreos-config@80f646d...051fb67 https://github.com/coreos/coreos-assembler.git: d3302e0..d3302e0 --> d3302e0...d3302e0 ```
1 parent 49002e6 commit 2b84784

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
 

‎src/cmd-diff

+29
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,33 @@ def parse_args():
111111
return parser.parse_args()
112112

113113

114+
def diff_source_control(diff_from, diff_to):
115+
for source in ['coreos-assembler.container-config-git', 'coreos-assembler.container-image-git']:
116+
config_from = diff_from.meta[source]
117+
config_to = diff_to.meta[source]
118+
config_shared_history = True
119+
for item in ['origin', 'branch', 'dirty']:
120+
if config_from[item] != config_to[item]:
121+
config_shared_history = False
122+
break
123+
if not config_shared_history:
124+
# If they weren't from the same repo/branch, etc then
125+
# there's not really any way to compare them easily
126+
# so just output the details gory details and move on.
127+
print(f"from: {config_from}")
128+
print(f"to: {config_to}")
129+
else:
130+
print(f"{config_from['origin']}: {config_from['commit'][:7]}..{config_to['commit'][:7]}")
131+
# If the git repo is on github (which our repos are) let's print a link
132+
# where a user can click (or share) and view the changes from one commit
133+
# to another.
134+
if 'github.com' in config_from['origin']:
135+
# Also pull off `.git` if it is on the end of the URL since the
136+
# compare API won't work if `.git` is in there.
137+
origin_url = f"{config_from['origin']}".removesuffix('.git')
138+
print(f" --> {origin_url}/compare/{config_from['commit'][:7]}...{config_to['commit'][:7]}")
139+
140+
114141
def diff_rpms(diff_from, diff_to):
115142
commit_from = diff_from.meta['ostree-commit']
116143
commit_to = diff_to.meta['ostree-commit']
@@ -303,6 +330,8 @@ def cache_dir(dir):
303330
# unfortunately, this has to come at the end to resolve functions
304331
DIFFERS = [
305332
Differ("rpms", "Diff RPMs", needs_ostree=OSTreeImport.PARTIAL, function=diff_rpms),
333+
Differ("source-control", "Diff config and COSA input commits",
334+
needs_ostree=OSTreeImport.NO, function=diff_source_control),
306335
Differ("ostree-ls", "Diff OSTree contents using 'ostree diff'",
307336
needs_ostree=OSTreeImport.FULL, function=diff_ostree_ls),
308337
Differ("ostree", "Diff OSTree contents using 'git diff'",

0 commit comments

Comments
 (0)
Please sign in to comment.