delete command #11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "cmd-delete"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Added a command for branch deletion.
This command will default to delete local & remote branch at once.
The
--localflag can be used to only delete the local branchThe
--remoteflag can be used to only delete the remote branchTODO / Checks
Testing
To test the branch deletion feature, a remote repository is needed (with a local clone). The demo project can be used.
Basic deletion
Create a remote branch and a local branch with the same name.
Afterwards delete the branch locally and remotely
Delete current branch
Create a test branch and switch to it.
In this case an error should be shown and no branch will be deleted.
Delete local branch only
Create a remote branch and a local branch
Afterwards delete only the local branch
Check in the remote repository. The
testbranch should still be present.Delete remote branch only
Create a remote branch and a local branch
Afterwards delete only the remote branch
Check the local repository for the branch.
Delete non existing branch
An error should be shown, suggesting to only delete the remote branch.
Delete a local branch with no remote
Create a local branch only
$ sac delete local-only
$ sac delete --remote non-existing
WIP: Delete commandto WIP: delete commandDas sieht auch clean aus ✨
@ -0,0 +17,20 @@/// Name of the branch to deletename: String,#[arg(long, short, default_value = "false")]/// delete the branch only localylocal: 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 foundremote: 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() {Achtung hier sind noch ein paar
unwrap()s. Weiss nicht ob das so von dir gewollt ist. Wenn ja, am besten anstelle davon immerexpect("eine gute Begruendung")fuer sowas nutzen, damit man selbst spaeter noch unterscheiden kann ob das nur zum schnellen testen war oder gewollt istDas 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
.contextasUndocumented errormarkiert.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.
WIP: delete commandto delete commandaf333e5974a4035aae7aSuper fix, danke dir. Ist ja schade dass die doku so wenig sagt
a4035aae7ato29ae304ac9