delete command #11

Merged
krauterbaquette merged 4 commits from cmd-delete into main 2024-12-22 13:57:12 +00:00

Added a command for branch deletion.

This command will default to delete local & remote branch at once.
The --local flag can be used to only delete the local branch
The --remote flag can be used to only delete the remote branch

Added a command for branch deletion. This command will default to delete local & remote branch at once. \ The `--local` flag can be used to only delete the **local** branch The `--remote` flag can be used to only delete the **remote** branch
added branch deletion command
Some checks failed
Rust Checks / Run Rust Check (push) Failing after 3s
d75b28c3fd
- deletes remote and local branch per default
- --local flag to only delete local branch
- --remote flag to only delete remote branch
added error message when branch is not found
Some checks failed
Rust Checks / Run Rust Check (push) Failing after 3s
0a4284c189
Author
Owner

TODO / Checks

  • show error when trying to delete a remote branch that does not exist
### TODO / Checks - [x] show error when trying to delete a remote branch that does not exist
improved error message if the remote branch does not exist
Some checks failed
Rust Checks / Run Rust Check (push) Failing after 3s
c7535a0d1f
- show a warning, as the desired state was achieved, but not by the desired action
Author
Owner

Testing

To test the branch deletion feature, a remote repository is needed (with a local clone). The demo project can be used.

All error messages should be user friendly

Basic deletion

Create a remote branch and a local branch with the same name.

$ git checkout -b test
$ git push origin test
$ git switch main

Afterwards delete the branch locally and remotely

$ sac delete test

Delete current branch

Create a test branch and switch to it.

$ git checkout -b test

In this case an error should be shown and no branch will be deleted.

$ sac delete test

Delete local branch only

Create a remote branch and a local branch

$ git checkout -b test
$ git push origin test
$ git switch main

Afterwards delete only the local branch

$ sac delete --local test

Check in the remote repository. The test branch should still be present.

Delete remote branch only

Create a remote branch and a local branch

$ git checkout -b test
$ git push origin test
$ git switch main

Afterwards delete only the remote branch

$ sac delete --remote test

Check the local repository for the branch.

git branch

Delete non existing branch

$ sac delete this-branch-does-not-exist

An error should be shown, suggesting to only delete the remote branch.

Delete a local branch with no remote

Create a local branch only

$ git branch local-only
``
Try to delete the branch:

$ sac delete local-only


The local branch should be deleted, while the remote deletion fails and prints an error.

## Delete non-existing remote branch

$ sac delete --remote non-existing

An error message should be shown. No local branch should be deleted.
# Testing To test the _branch deletion_ feature, a remote repository is needed (with a local clone). The [demo project](https://git.solarpunk.social/GTA-HEG/demo) can be used. > All error messages should be user friendly ## Basic deletion Create a remote branch and a local branch with the same name. ``` $ git checkout -b test $ git push origin test $ git switch main ``` Afterwards delete the branch locally and remotely ``` $ sac delete test ``` ## Delete current branch Create a test branch and switch to it. ``` $ git checkout -b test ``` In this case an error should be shown and no branch will be deleted. ``` $ sac delete test ``` ## Delete local branch only Create a remote branch and a local branch ``` $ git checkout -b test $ git push origin test $ git switch main ``` Afterwards delete only the local branch ``` $ sac delete --local test ``` Check in the remote repository. The `test` branch should still be present. ## Delete remote branch only Create a remote branch and a local branch ``` $ git checkout -b test $ git push origin test $ git switch main ``` Afterwards delete only the remote branch ``` $ sac delete --remote test ``` Check the local repository for the branch. ``` git branch ``` ## Delete non existing branch ``` $ sac delete this-branch-does-not-exist ``` An error should be shown, suggesting to only delete the remote branch. ## Delete a local branch with no remote Create a local branch only ``` $ git branch local-only `` Try to delete the branch: ``` $ sac delete local-only ``` The local branch should be deleted, while the remote deletion fails and prints an error. ## Delete non-existing remote branch ``` $ sac delete --remote non-existing ``` An error message should be shown. No local branch should be deleted.
krauterbaquette changed title from WIP: Delete command to WIP: delete command 2024-12-18 20:54:23 +00:00
aviac approved these changes 2024-12-19 11:42:08 +00:00
Dismissed
aviac left a comment
Contributor

Das sieht auch clean aus

Das sieht auch clean aus ✨
@ -0,0 +17,20 @@
/// Name of the branch to delete
name: String,
#[arg(long, short, default_value = "false")]
/// delete the branch only localy
local: bool,
#[arg(long, short, default_value = "false")]
/// delete only the remote branch
/// this will try to delete the remote branch even if no local branch is found
remote: bool,
}
impl Cmd {
pub fn execute(&self) -> anyhow::Result<()> {
if self.remote {
remove_remote(&self.name);
return Ok(());
}
let repo = Repository::discover(".").context("failed to open repository")?;
for branch in repo.branches(Some(BranchType::Local)).unwrap() {
Contributor

Achtung hier sind noch ein paar unwrap()s. Weiss nicht ob das so von dir gewollt ist. Wenn ja, am besten anstelle davon immer expect("eine gute Begruendung") fuer sowas nutzen, damit man selbst spaeter noch unterscheiden kann ob das nur zum schnellen testen war oder gewollt ist

Achtung hier sind noch ein paar `unwrap()`s. Weiss nicht ob das so von dir gewollt ist. Wenn ja, am besten anstelle davon immer `expect("eine gute Begruendung")` fuer sowas nutzen, damit man selbst spaeter noch unterscheiden kann ob das nur zum schnellen testen war oder gewollt ist
Author
Owner

Das problem ist so ein wenig, dass die git2.rs documentation keinen wirklichen hinweis darauf gibt, was genau schief laufen kann.

Ich habe jetzt einfach das ganze mit .context as Undocumented error markiert.
Man kann dan in der Zukunft (sollte jemals ein fehler auftreten), das ganze besser analysieren und eine sinnvollere Fehlermeldung schreiben. Ich glaube aktuell liegt das aber etwas außerhalb des scopes.

Das problem ist so ein wenig, dass die [git2.rs documentation]() keinen wirklichen hinweis darauf gibt, was genau schief laufen kann. Ich habe jetzt einfach das ganze mit `.context` as `Undocumented error` markiert. Man kann dan in der Zukunft (sollte jemals ein fehler auftreten), das ganze besser analysieren und eine sinnvollere Fehlermeldung schreiben. Ich glaube aktuell liegt das aber etwas außerhalb des scopes.
krauterbaquette marked this conversation as resolved
switched unwraps to thrown errors
Some checks failed
Rust Checks / Run Rust Check (push) Failing after 2s
af333e5974
Adressing comment: GTA-HEG/SAC#11 (comment)

Sadly, [git2.rs](https://docs.rs/git2/latest/git2/) has no documentation on the errors
that can happen inside the libgit2-C libary,
so we don't know what could lead to an error
krauterbaquette changed title from WIP: delete command to delete command 2024-12-19 17:08:18 +00:00
krauterbaquette force-pushed cmd-delete from af333e5974
Some checks failed
Rust Checks / Run Rust Check (push) Failing after 2s
to a4035aae7a 2024-12-21 17:37:10 +00:00
Compare
aviac approved these changes 2024-12-22 05:50:17 +00:00
aviac left a comment
Contributor

Super fix, danke dir. Ist ja schade dass die doku so wenig sagt

Super fix, danke dir. Ist ja schade dass die doku so wenig sagt
krauterbaquette force-pushed cmd-delete from a4035aae7a to 29ae304ac9
Some checks failed
Rust Checks / Run Rust Check (push) Failing after 2s
2024-12-22 13:56:33 +00:00
Compare
krauterbaquette deleted branch cmd-delete 2024-12-22 13:57:12 +00:00
krauterbaquette referenced this pull request from a commit 2024-12-22 13:57:13 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
krauterbaquette/sac!11
No description provided.