branch command #9
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "cmd-branch"
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?
This command will behave like
git branchwith some add-ons.When executing
sac branchwithout arguments, it will list all the local branches and highlight the current branch.When executing
sac branchwith an argument, it will try to create a branch with the given argument as a branch name.Afterwards it will push the branch to the remote and set up the upstream correctly.
This way the branch will be in sync with the remote from the start.
For situations where one does not has an internet connection, the
--localflag can be used to skip the branch syncing with the remote.Todo
--localflagWIP: branch commandto branch commandTesting
To test the branch creation feature a remote repository is needed with a local clone.
List branch
This should work the same as
git branch.Log all locally known branches and highlight the current branch.
Create branch
This should create a local branch, push it to the remote and sync them.
HEAD should point to the new branch.
Already existing branch
This should error.
Local only branch
Only the local branch will be created.
No branch should be created on the remote.
No internet
The branch creation should fail and inform the user about
--localfor work without internet.No branch should be created and the user should stay inside the current branch.
Remote branch ahead
Create a branch
Make a commit & push to remote
Delete the local branch
Try to create a new branch
aheadThe process should fail (with a user friendly error).
No branch should be created, and the user should stay on the starting branch.
branch commandto WIP: branch commandSieht gut aus vom code her!
@ -0,0 +39,20 @@let repo = Repository::open(".").context("failed to open git repository")?;let branches = repo.branches(Some(BranchType::Local)).unwrap();let mut out = String::from("");for branch in branches {let branch = branch.unwrap();let branch_name = match branch.0.name().unwrap() {Some(name) => name,None => "???",};let prefix;if branch.0.is_head() {prefix = ">";} else {prefix = " ";}let mut line = format!("{} {}", prefix, branch_name);Allgemein bei allen diesen format strings kannst du die Variable (falls sie sich normal ausgeben laesst -> das kannst du testen indem du schaust ob sie
to_string()implementiert hat) auch direkt in die Klammern hauen. Das liest sich imo besser:@ -0,0 +52,20 @@if branch.0.is_head() {prefix = ">";} else {prefix = " ";}let mut line = format!("{} {}", prefix, branch_name);if branch.0.is_head() {line = line.green().to_string();}let line = format!("{}\n", line);out += &line;}if out == "" {println!("no branches\ncreate one with 'sac branch NAME'");return Ok(());}out = out[..out.len() - 1].to_string();Wenn du nur das letzte newline wegmachen willst geht glaube ich auch
.trim()oder alternativ kannst du auchprint!()nutzen, was nicht noch ein extra newline hinten dranhaengt.@ -0,0 +83,20 @@let repo = Repository::discover(".").context("failed to open local repository")?;let recover_to = repo.head();let mut sp = Spinner::new(Spinners::Line, "create branch localy".into());let checkout = Command::new("git").args(["checkout", "-b", name]).output().context("failed to execute git")?;if !checkout.status.success() {sp.stop_with_symbol("☓");let err = match_checkout_error(&checkout.stderr, name);anyhow::bail!(err);} else {sp.stop_with_symbol("🗸");}if self.local {return Ok(());}let mut sp = Spinner::new(Spinners::Line, "create branch remotly".into());Schick!
danke, auf die spinner bin ich auch sehr stolz :)
WIP: branch commandto branch command882cb4cee090b116ba90Sieht gut aus
90b116ba90to9e0c318e50