Repository navigation
[Backend] feat(git): software-core::git -- Git feature to handle ADJ updates #654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pminmic
wants to merge
14
commits into
new-backend
Choose a base branch
from
backend/git
base: new-backend
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fa9f338
fix: change rust version and add gix
pminmic 9bfceab
feat(backend, git): implementation of ADJ update handling
pminmic 58d320b
docs(backend, git): README
pminmic db77823
docs(backend, git): add some more comments
pminmic 15e7cff
merge(backend, git): new-backend into backend/git to be able to pull …
pminmic 71ccb29
feat(backend, git): separate module in submodules and propagate GitEr…
pminmic f8f04b0
docs(backend, git): update README
pminmic a33f650
update(backend, git): update cargo packages
pminmic 149be35
fix(backend, git): fix implementation of list_remote_branches and bra…
pminmic cda8fb6
docs(backend, git): small changes in README
pminmic 2cf2ee1
Merge branch 'new-backend' into backend/git
pminmic f5821af
refactor(backend, git): separete errors in specific file
pminmic 791cad7
feat(backend, adj): implement auto_adj() and create new LoadError for it
pminmic ec14d41
Merge branch 'new-backend' into backend/git
pminmic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| //! Blocking Git helpers for ADJ, an application-owned, replaceable data cache. | ||
|
|
||
| mod clone; | ||
| mod error; | ||
| mod repository; | ||
| mod update; | ||
|
|
||
| pub use error::{CloneError, GitError, RepositoryError}; | ||
| pub use repository::{branch_exists, list_remote_branches, open_repo}; | ||
| pub(crate) use update::unwrap_repo_path; | ||
| pub use update::update_adj; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # ADJ Git helpers | ||
|
|
||
| This module downloads and updates the local [ADJ repository](https://github.com/Hyperloop-UPV/adj) using [`gix`](https://crates.io/crates/gix), with [`tracing`](https://crates.io/crates/tracing) for logging. It supports branch selection and offline use of an existing local checkout. | ||
|
|
||
| ## Workflow | ||
|
|
||
| `update_adj(path, branch)` returns the full hash of the checked-out commit. | ||
| A custom path identifies the ADJ repository itself. The default is | ||
| `<cache directory>/hyperloop-control-station/adj`, using `dirs::cache_dir()`. | ||
| An existing invalid repository or inaccessible path returns an error. | ||
|
|
||
| The existing connectivity check attempts a TCP connection to `1.1.1.1:443` | ||
| with a three-second timeout. This checks external TCP connectivity, not GitHub | ||
| availability. | ||
|
|
||
| ### Online | ||
|
|
||
| Online updates replace the local checkout and do not preserve local edits or commits. | ||
|
|
||
| - Shallow-clone the requested branch into a temporary directory beside ADJ. | ||
| - Complete checkout and read its commit hash before touching the cache. | ||
| - Move the old cache aside and install the new checkout. | ||
| - Restore the old cache if installation fails. If restoration also fails, | ||
| preserve the backup and include its location in the error. | ||
| - Remove the old cache after successful installation. | ||
|
|
||
| A clone error leaves the old cache untouched and is returned directly; it does | ||
| not automatically fall back to offline operation. No separate fetch of the | ||
| existing cache, merge, or branch switch is needed because the checkout is replaced. | ||
|
|
||
| ### Offline | ||
|
|
||
| - If ADJ exists, return its current commit hash without updating or switching branches. | ||
| - Otherwise, return `ADJ is not available locally and cannot be downloaded`. | ||
|
|
||
| The cached branch may differ from the requested branch when offline. | ||
|
|
||
| ## Other Helpers | ||
|
|
||
| - `open_repo` opens the custom or default repository path. | ||
| - `list_remote_branches(repo)` queries the default fetch remote and returns sorted short | ||
| branch names, without downloading objects or updating local references. It | ||
| requires remote access and does not fall back to cached branches on failure. | ||
| - `branch_exists(repo, name)` uses that listing to check an exact short branch | ||
| name. Query errors are propagated; `false` means a successful query did not | ||
| find the branch, not that the remote was unreachable. | ||
|
|
||
| ## Limitations | ||
|
|
||
| Replacement is intended for startup, before the backend reads ADJ, with one | ||
| updater at a time. The backup and installation renames are not jointly atomic | ||
| across a process crash. The connectivity probe can succeed when GitHub is | ||
| unreachable, or fail when GitHub is reachable. | ||
|
|
||
| ## Errors | ||
|
|
||
| Public helpers return `GitError` with five categories: `Path`, `Repository`, | ||
| `Clone`, `Replacement`, and `UnavailableOffline`. `RepositoryError` and | ||
| `CloneError` group the concrete `gix` causes inside the corresponding categories. | ||
| If rollback fails, `Replacement` also retains the restoration error and backup | ||
| path for recovery. | ||
|
|
||
| ## Verification | ||
|
|
||
| Tests use temporary local Git repositories and the Git CLI to create fixtures; | ||
| they do not require external network access. Production Git operations use `gix`. | ||
|
|
||
| ```bash | ||
| cargo test -p software-core -F git | ||
| cargo doc --open -p software-core -F git --no-deps | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.