Skip to content

Commit 39543e0

Browse files
authored
Merge pull request #85 from aws4embeddedlinux/fix/git-add-targeted-staging
fix: prevent accidental gitlink staging in backporter and upgrader
2 parents 0a965f7 + f0be971 commit 39543e0

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

auto-upgrader/upgrader/updates.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,16 @@ def update(layer_path: Path, target_branch: str) -> None:
162162
result["fail"].append(upgrade)
163163
continue
164164

165-
# Commit upgrade
166-
run(f"git -C {layer_path} add --all")
167-
run(f'git -C {layer_path} commit -a -m "{commit_msg}"')
165+
# Commit upgrade — stage only layer content, not unrelated checkouts
166+
# that may appear in the working tree (e.g. CI tool repos). Using
167+
# pathspecs for known layer directories prevents accidental gitlink
168+
# staging (see meta-aws#16495).
169+
run(f"git -C {layer_path} add -u") # stage modifications/deletions to tracked files
170+
run(
171+
f"git -C {layer_path} add"
172+
f" -- recipes-* classes conf dynamic-layers images .github"
173+
) # stage new files only in known layer directories
174+
run(f'git -C {layer_path} commit -m "{commit_msg}"')
168175

169176
with open(BRANCH_FILE, "a") as f:
170177
f.write(new_branch + "\n")

backporter/auto-backport.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ jobs:
2929
ref: master
3030
path: ci
3131

32+
- name: Exclude ci/ from git tracking
33+
run: |
34+
# The ci/ checkout lives inside the meta-aws working tree.
35+
# Ensure git never stages it as a gitlink (fixes #16495).
36+
echo "ci/" >> .git/info/exclude
37+
3238
- name: Set up Python
3339
uses: actions/setup-python@v5
3440
with:

backporter/backporter/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,11 @@ def backport(layer_path: Path, input: BackportInput) -> BackportResult:
293293
# Write updated content
294294
new_path.write_text(content)
295295

296-
# Stage and commit
297-
run_git(["add", "--all"], cwd=layer_path)
296+
# Stage only the specific recipe files that changed (the git mv already
297+
# staged the rename; we just need to stage the content update to the new file).
298+
# Avoid "git add --all" which can accidentally stage unrelated files such as
299+
# CI tool checkouts that appear inside the working tree (see #16495).
300+
run_git(["add", str(new_path.relative_to(layer_path))], cwd=layer_path)
298301

299302
commit_msg = f"{recipe}: upgrade {old_version} -> {new_version}"
300303
try:

0 commit comments

Comments
 (0)