Handle stale inventory git conflicts and add clean-reset action#12
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the inventory “save/commit” workflow against stale-clone git conflicts by syncing with the upstream before applying UI-generated patches, and adds a user-confirmed fallback to reset the inventory repository to a clean remote state when automatic recovery isn’t possible.
Changes:
- Updated
commit.shto synchronize with upstream and apply patches usinggit apply --3way, with added cleanup/reset helpers. - Added
clean_inventory.shto abort in-progress operations and hard-reset/clean the inventory repo back to the remote branch. - Updated
commit.pyto persist/show conflict output and offer a confirmed “clean reset” action from the UI.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
commit.sh |
Adds upstream sync + 3-way patch apply and more robust cleanup/reset logic during failures. |
commit.py |
Improves conflict UX by persisting command output and adding a clean-reset action that runs the new script. |
clean_inventory.sh |
New script to force-reset the inventory repo to a deterministic clean state from remote. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+23
to
+27
| if [[ -e "$lockfile" ]]; then | ||
| error 'Could not acquire lock. Try again.' | ||
| fi | ||
| touch $lockfile | ||
| touch "$lockfile" | ||
| trap cleanup EXIT |
Comment on lines
29
to
33
| patchfile=$1 | ||
| sed -e 's/\x1b\[[0-9;]*m//g' -i $patchfile | ||
| sed -e 's/\x1b\[[0-9;]*m//g' -i "$patchfile" | ||
|
|
||
| if [[ -z $2 ]]; then | ||
| if [[ -z ${2:-} ]]; then | ||
| error 'Commit message not provided' |
Comment on lines
+17
to
+21
| function reset_worktree() { | ||
| git rebase --abort >/dev/null 2>&1 || true | ||
| git merge --abort >/dev/null 2>&1 || true | ||
| git reset --hard HEAD >/dev/null 2>&1 || true | ||
| } |
Comment on lines
55
to
+56
| git add inventory/group_vars/ccc-cluster/{user-list,user-containers}.yml | ||
| git commit -m "$2" | ||
| git commit -m "$2" || error 'Commit failed' |
Comment on lines
+68
to
+72
| p = subprocess.run(['bash', 'clean_inventory.sh'], capture_output=True) | ||
| if p.returncode == 0: | ||
| discard() | ||
| st.rerun() | ||
|
|
Comment on lines
+4
to
+21
| lockfile=/opt/ccc-manager/commit.lock | ||
| inventory_dir=${CCC_INVENTORY_DIR:-/opt/ccc-inventory} | ||
|
|
||
| function cleanup() { | ||
| rm -f "$lockfile" | ||
| } | ||
|
|
||
| function error() { | ||
| echo "$1" | ||
| cleanup | ||
| exit 1 | ||
| } | ||
|
|
||
| if [[ -e "$lockfile" ]]; then | ||
| error 'Could not acquire lock. Try again.' | ||
| fi | ||
| touch "$lockfile" | ||
| trap cleanup EXIT |
| load_containers(st.session_state) | ||
|
|
||
| def clean_inventory(): | ||
| p = subprocess.run(['bash', 'clean_inventory.sh'], capture_output=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Patch failedorCould not pull with rebase.Description
commit.shmore robust by using aninventory_dirvariable, addingset -u, acleanuptrap, and areset_worktreehelper that aborts in-progress operations and hard-resets the worktree.git apply --3wayto handle non-conflicting remote edits automatically; on failure the script shows conflict output and performs a safe reset.clean_inventory.shwhich aborts rebase/merge, fetches the remote, hard-resets the local branch to the upstream (ororigin/$CCC_INVENTORY_BRANCH), and removes untracked files to provide a deterministic clean state.commit.pyto surface a clearer conflict message, persist command output inst.session_statefor display, and offer a confirmedClean git clone / discard local inventory changesaction that runs the newclean_inventory.sh.Testing
PYTHONDONTWRITEBYTECODE=1 python3 -m py_compile commit.pycompleted successfully.bash -n commit.sh clean_inventory.sh(shell syntax check) completed successfully.python3 -m unittest test_logs.pyran 9 tests and reportedOK.Codex Task