-
Notifications
You must be signed in to change notification settings - Fork 0
Command push
#51
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
Command push
#51
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
255a18c
push command template
adamgracikowski 53e30ba
receive-pack first steps
adamgracikowski 3213c85
Merge branch 'develop' into feature/command-push
adamgracikowski f701f3e
Merge branch 'develop' into feature/command-push
adamgracikowski a90fb5f
add first step to receive-pack protocol
adamgracikowski 9ee658a
add packfile generation and sending by client
adamgracikowski 9ddd142
add packfile decoding on server side
adamgracikowski 06372e9
finish push client side
adamgracikowski edc4cce
add push server side logic
adamgracikowski 2e639f0
add documenting comments and improve logging with verbose arguments
adamgracikowski d81850d
improve fetch logging and displaying results
adamgracikowski 9e64edd
clippy & fmt
adamgracikowski 04e6aef
fix detailed logging
adamgracikowski 3666a4b
add colors to ls-files output
adamgracikowski 85891df
improve colors in console
adamgracikowski b99bd16
connect push handler to gui
adamgracikowski fcfc3de
remote and clone improvements
adamgracikowski 588b1e6
change colors
adamgracikowski 9a6b4b4
invert quiet flag default value
adamgracikowski 13870c7
add pull cli template
adamgracikowski 6256992
suggestions
adamgracikowski 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| use async_trait::async_trait; | ||
| use clap::{Arg, ArgMatches, Command}; | ||
| use miette::Result; | ||
|
|
||
| use engine::engine_container::MevaContainer; | ||
|
|
||
| use crate::{commands::MevaCommand, extensions::WithVerbose}; | ||
|
|
||
| /// Implements the `pull` command for Meva DVCS. | ||
| #[derive(Default)] | ||
| pub struct PullCommand; | ||
|
|
||
| impl PullCommand { | ||
| const ARG_ORIGIN: &'static str = "origin"; | ||
|
|
||
| const ARG_BRANCH: &'static str = "branch"; | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl MevaCommand for PullCommand { | ||
| type Container = MevaContainer; | ||
|
|
||
| fn name(&self) -> &'static str { | ||
| "pull" | ||
| } | ||
|
|
||
| fn about(&self) -> &'static str { | ||
| "Fetch and integrate the latest changes from the remote repository into your local branch" | ||
| } | ||
|
|
||
| fn version(&self) -> &'static str { | ||
| "1.0.0" | ||
| } | ||
|
|
||
| /// Builds the CLI argument parser for the `pull` command. | ||
| fn build_command(&self) -> Command { | ||
| self.build_base_command() | ||
| .with_verbose_arg("Enable verbose output when pulling from remote server") | ||
| .arg( | ||
| Arg::new(Self::ARG_ORIGIN) | ||
| .value_name("ORIGIN") | ||
| .index(1) | ||
| .required(false) | ||
| .default_value("origin") | ||
| .help("Name of the remote repository to pull from"), | ||
| ) | ||
| .arg( | ||
| Arg::new(Self::ARG_BRANCH) | ||
| .value_name("BRANCH") | ||
| .index(2) | ||
| .required(false) | ||
| .help("Name of the branch to pull from"), | ||
| ) | ||
| } | ||
|
|
||
| /// Executes the `pull` command. | ||
| /// | ||
| /// # Arguments | ||
| /// * `matches`: Parsed command-line arguments. | ||
| /// * `container`: Dependency injection container. | ||
| /// | ||
| /// # Returns | ||
| /// * `Result<()>`: Success or error during execution. | ||
| async fn execute(&self, _matches: &ArgMatches, _container: &Self::Container) -> Result<()> { | ||
| Ok(()) | ||
|
adamgracikowski marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use pretty_assertions::assert_eq; | ||
| use rstest::rstest; | ||
|
|
||
| #[rstest] | ||
| fn test_command_name_about_version() { | ||
| let cmd = PullCommand; | ||
| assert_eq!(cmd.name(), "pull"); | ||
| assert_eq!( | ||
| cmd.about(), | ||
| "Fetch and integrate the latest changes from the remote repository into your local branch" | ||
| ); | ||
| assert_eq!(cmd.version(), "1.0.0"); | ||
| } | ||
| } | ||
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,120 @@ | ||
| use async_trait::async_trait; | ||
| use clap::{Arg, ArgAction, ArgMatches, Command}; | ||
| use miette::{IntoDiagnostic, Result}; | ||
|
|
||
| use engine::{EngineContainer, engine_container::MevaContainer, handlers::push::Request}; | ||
|
|
||
| use crate::{commands::MevaCommand, extensions::WithVerbose}; | ||
|
|
||
| /// Implements the `push` command for Meva DVCS. | ||
| /// | ||
| /// This command pushes local commits to a remote repository. | ||
| /// It supports pushing specific branches or all local branches | ||
| /// Deletion of remote branches is also supported. | ||
| #[derive(Default)] | ||
| pub struct PushCommand; | ||
|
|
||
| impl PushCommand { | ||
| const ARG_ORIGIN: &'static str = "origin"; | ||
|
|
||
| const ARG_BRANCH: &'static str = "branch"; | ||
|
|
||
| const ARG_ALL: &'static str = "all"; | ||
|
|
||
| const ARG_DELETE: &'static str = "delete"; | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl MevaCommand for PushCommand { | ||
| type Container = MevaContainer; | ||
|
|
||
| fn name(&self) -> &'static str { | ||
| "push" | ||
| } | ||
|
|
||
| fn about(&self) -> &'static str { | ||
| "Push local commits to a remote repository" | ||
| } | ||
|
|
||
| fn version(&self) -> &'static str { | ||
| "1.0.0" | ||
| } | ||
|
|
||
| /// Builds the CLI argument parser for the `push` command. | ||
| fn build_command(&self) -> Command { | ||
| self.build_base_command() | ||
| .with_verbose_arg("Enable verbose output when pushing to remote server") | ||
| .arg( | ||
| Arg::new(Self::ARG_ORIGIN) | ||
| .value_name("ORIGIN") | ||
| .index(1) | ||
| .required(false) | ||
| .default_value("origin") | ||
|
adamgracikowski marked this conversation as resolved.
|
||
| .help("Name of the remote repository to push to"), | ||
| ) | ||
| .arg( | ||
| Arg::new(Self::ARG_BRANCH) | ||
| .value_name("BRANCH") | ||
| .index(2) | ||
| .required(false) | ||
| .help("Name of the branch to push to"), | ||
| ) | ||
| .arg( | ||
| Arg::new(Self::ARG_ALL) | ||
| .long(Self::ARG_ALL) | ||
| .short('a') | ||
| .help("Push all local branches to the specified remote") | ||
| .action(ArgAction::SetTrue) | ||
| .conflicts_with_all([Self::ARG_BRANCH, Self::ARG_DELETE]), | ||
| ) | ||
| .arg( | ||
| Arg::new(Self::ARG_DELETE) | ||
| .long(Self::ARG_DELETE) | ||
| .short('d') | ||
| .help("Delete the given remote branch.") | ||
| .action(ArgAction::SetTrue) | ||
| .requires(Self::ARG_BRANCH), | ||
| ) | ||
| } | ||
|
|
||
| /// Executes the `push` command. | ||
| /// | ||
| /// # Arguments | ||
| /// * `matches`: Parsed command-line arguments. | ||
| /// * `container`: Dependency injection container. | ||
| /// | ||
| /// # Returns | ||
| /// * `Result<()>`: Success or error during execution. | ||
| async fn execute(&self, matches: &ArgMatches, container: &Self::Container) -> Result<()> { | ||
| let request = Request { | ||
| origin: matches.get_one::<String>(Self::ARG_ORIGIN).unwrap().clone(), | ||
| branch: matches.get_one::<String>(Self::ARG_BRANCH).cloned(), | ||
| all: matches.get_flag(Self::ARG_ALL), | ||
| delete: matches.get_flag(Self::ARG_DELETE), | ||
| verbose: matches.get_flag(Command::ARG_VERBOSE), | ||
| }; | ||
|
|
||
| let handler = container.push_handler().into_diagnostic()?; | ||
|
|
||
| let response = handler.handle_push(request).await.into_diagnostic()?; | ||
|
|
||
| println!(); | ||
| println!("{response}"); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use pretty_assertions::assert_eq; | ||
| use rstest::rstest; | ||
|
|
||
| #[rstest] | ||
| fn test_command_name_about_version() { | ||
| let cmd = PushCommand; | ||
| assert_eq!(cmd.name(), "push"); | ||
| assert_eq!(cmd.about(), "Push local commits to a remote repository"); | ||
| assert_eq!(cmd.version(), "1.0.0"); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.