Skip to content

Fix rollback after failed diff deployments - #194

Open
giscebot wants to merge 1 commit into
masterfrom
fix/rollback-failed-diff
Open

giscebot wants to merge 1 commit into
masterfrom
fix/rollback-failed-diff

Conversation

@giscebot

@giscebot giscebot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Context

An sastre deploy --as-diff --reject against staging failed while applying an ERP pull request. The installed apply_pr 3.4.8 then raised an ASCII decoding error while handling Git output containing UTF-8 text, which hid the actual patch conflict. Its unconditional git stash pop restored pre-existing work over the partially applied diff and left the staging checkout dirty with rejected/partial files.

The UTF-8 diagnostic issue has already been addressed on current master by #189. This pull request closes the remaining operational gap: failed diff deployments must not leave their partial changes in the target checkout.

@abaena-gisce: Això m'ho vaig trobar quan em va petar per tenir accents al cos de la PR quan vaig correr el sastre a l'entorn de python 2 que per defecte no es UTF-8. I et deixa tot el repo brut i amb un estat inconsistent. Hauria de netejar sempre tot el que fa tant els fitxers modificats/creats/eliminats + els .rej. Si no per accident es poden arribar a pujar fitxers o canvis no desitjats. La implementació del giscebot no sé si és correcte això no ho he provat encara.

Changes

  • Roll back a failed remote diff to the HEAD captured before git apply.
  • Remove untracked files created by the failed diff before restoring the pre-deploy stash.
  • Keep the stash untouched when rollback itself fails, avoiding a stash pop over an inconsistent checkout.
  • Preserve the original application error as the deployment failure; rollback errors are reported separately.
  • Document the failure and recovery guarantees for --as-diff deployments.

Regression coverage

  • Unresolved --reject hunks no longer leave .rej files or partial changes.
  • Pre-existing untracked work containing UTF-8 text is restored after rollback.
  • A failed rollback keeps the stash and does not hide the original Git error.
  • A failed commit is also rolled back to a clean checkout.

Validation

  • Python 2.7: PYTHONPATH=. python -m unittest discover -s tests — 59 tests passed.
  • Python 3.11: PYTHONPATH=. python -m unittest discover -s tests — 59 tests passed.
  • git diff --check — clean.

Traceability

  • ERP task: TASK-95718
  • Incident observed while deploying gisce/erp#29405 to staging.
  • Requested by: @abaena-gisce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant