-
Notifications
You must be signed in to change notification settings - Fork 1
Implement Git status SSE updates #106
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7182bb6
feat(backend): Extend Git status API
jonasehrlich 4c6b224
fix(reference): Ignore stash reference when creating references map
jonasehrlich 736a0c4
feat(backend): Implement git status watcher
jonasehrlich 3e0de4d
feat(frontend): Implement git status bar
jonasehrlich 9e9c094
feat(frontend): Add typesafe event source
jonasehrlich f0fec3a
feat(git-status-sse): Send event when stream is opened
jonasehrlich 7ffa0a4
Improve event logging and filter status events
jonasehrlich 600c28b
feat(frontend): Implement reconnecting event stream and useEventStrea…
jonasehrlich 3cc6fd3
fix(web): Handle errors in file watcher receiver
jonasehrlich b185c27
fix(git-status): Do not use TryFrom trait
jonasehrlich 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
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
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,175 @@ | ||
| use crate::{CommitWithReferences, Repository, Result, error::Error}; | ||
|
|
||
| type Files = Vec<String>; | ||
|
|
||
| #[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] | ||
| #[cfg_attr( | ||
| feature = "serde", | ||
| derive(serde::Serialize), | ||
| serde(rename_all = "camelCase") | ||
| )] | ||
| #[derive(Default, Debug)] | ||
| pub struct TreeStatus { | ||
| /// Added files | ||
| new_files: Files, | ||
| /// Modified files | ||
| modified_files: Files, | ||
| /// Deleted files | ||
| deleted_files: Files, | ||
| /// Renamed files | ||
| renamed_files: Files, | ||
| } | ||
|
|
||
| impl TreeStatus { | ||
| /// Files that were added | ||
| pub fn new_files(&self) -> &Files { | ||
| &self.new_files | ||
| } | ||
|
|
||
| /// Files that were modified | ||
| pub fn modified_files(&self) -> &Files { | ||
| &self.modified_files | ||
| } | ||
|
|
||
| /// Files that were deleted | ||
| pub fn deleted_files(&self) -> &Files { | ||
| &self.deleted_files | ||
| } | ||
|
|
||
| /// Files that were renamed | ||
| pub fn renamed_files(&self) -> &Files { | ||
| &self.renamed_files | ||
| } | ||
| } | ||
|
|
||
| #[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] | ||
| #[cfg_attr( | ||
| feature = "serde", | ||
| derive(serde::Serialize), | ||
| serde(rename_all = "camelCase") | ||
| )] | ||
| #[derive(Debug)] | ||
| pub struct Status { | ||
| /// Name of the current branch, not set if `is_detached_head` is true | ||
| current_branch: Option<String>, | ||
| /// The commit current HEAD points to | ||
| head: CommitWithReferences, | ||
| /// Whether the head is detached | ||
| is_detached_head: bool, | ||
| /// Whether the worktree or index have changes | ||
| is_dirty: bool, | ||
| /// Status of the index | ||
| index: TreeStatus, | ||
| /// Status in the worktree | ||
| worktree: TreeStatus, | ||
| /// Paths with conflicts | ||
| conflicts: Files, | ||
| } | ||
|
|
||
| impl Status { | ||
| pub fn head(&self) -> &CommitWithReferences { | ||
| &self.head | ||
| } | ||
|
|
||
| pub fn is_detached_head(&self) -> bool { | ||
| self.is_detached_head | ||
| } | ||
|
|
||
| pub fn is_dirty(&self) -> bool { | ||
| self.is_dirty | ||
| } | ||
|
|
||
| pub fn index(&self) -> &TreeStatus { | ||
| &self.index | ||
| } | ||
|
|
||
| pub fn worktree(&self) -> &TreeStatus { | ||
| &self.worktree | ||
| } | ||
|
|
||
| pub fn conflicted(&self) -> &Files { | ||
| &self.conflicts | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<&Repository> for Status { | ||
| type Error = Error; | ||
|
|
||
| fn try_from(repo: &Repository) -> Result<Self> { | ||
| let head = repo.get_commit_for_revision("HEAD")?; | ||
|
|
||
| let mut opts = git2::StatusOptions::new(); | ||
| opts.include_untracked(true) | ||
| .recurse_untracked_dirs(true) | ||
| .include_ignored(false) | ||
| .renames_head_to_index(true) | ||
| .renames_index_to_workdir(true); | ||
|
|
||
| let statuses = repo | ||
| .repo() | ||
| .statuses(Some(&mut opts)) | ||
| .map_err(|e| Error::from_ctx_and_error("Failed to create statuses", e))?; | ||
|
|
||
| let mut index_status = TreeStatus::default(); | ||
| let mut worktree_status = TreeStatus::default(); | ||
| let mut conflicts = Vec::new(); | ||
|
|
||
| for entry in statuses.iter() { | ||
| let status = entry.status(); | ||
| if status.is_index_new() { | ||
| index_status | ||
| .new_files | ||
| .push(entry.path().unwrap_or("<invalid utf-8>").to_string()); | ||
jonasehrlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else if status.is_index_renamed() { | ||
| index_status | ||
| .renamed_files | ||
| .push(entry.path().unwrap_or("<invalid utf-8>").to_string()); | ||
| } else if status.is_index_modified() { | ||
| index_status | ||
| .modified_files | ||
| .push(entry.path().unwrap_or("<invalid utf-8>").to_string()); | ||
| } else if status.is_index_deleted() { | ||
| index_status | ||
| .deleted_files | ||
| .push(entry.path().unwrap_or("<invalid utf-8>").to_string()); | ||
| } else if status.is_wt_new() { | ||
| worktree_status | ||
| .new_files | ||
| .push(entry.path().unwrap_or("<invalid utf-8>").to_string()); | ||
| } else if status.is_wt_renamed() { | ||
| worktree_status | ||
| .renamed_files | ||
| .push(entry.path().unwrap_or("<invalid utf-8>").to_string()); | ||
| } else if status.is_wt_modified() { | ||
| worktree_status | ||
| .modified_files | ||
| .push(entry.path().unwrap_or("<invalid utf-8>").to_string()); | ||
| } else if status.is_wt_deleted() { | ||
| worktree_status | ||
| .deleted_files | ||
| .push(entry.path().unwrap_or("<invalid utf-8>").to_string()); | ||
| } else if status.is_conflicted() { | ||
| conflicts.push(entry.path().unwrap_or("<invalid utf-8>").to_string()); | ||
| } | ||
| } | ||
|
|
||
| Ok(Self { | ||
| current_branch: repo.current_branch_name(), | ||
| head, | ||
| is_detached_head: repo.repo().head_detached().map_err(|e| { | ||
| Error::from_ctx_and_error("Failed to determined if head is detached", e) | ||
| })?, | ||
| is_dirty: !statuses.is_empty(), | ||
| index: index_status, | ||
| worktree: worktree_status, | ||
| conflicts, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<Repository> for Status { | ||
| type Error = Error; | ||
| fn try_from(repo: Repository) -> Result<Self> { | ||
| Status::try_from(&repo) | ||
| } | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would probably prefer a method e.g.
Status::try_from_repositoryin this case. AsTryFromis more about type conversions.Alternatively we could just have an impl block:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used
Status::try_from_repositoryI don't like to have all this logic ingit2_ox::Repository