|
4 | 4 |
|
5 | 5 | use std::io::Write;
|
6 | 6 |
|
7 |
| -use anyhow::{anyhow, Context, Result}; |
| 7 | +use anyhow::{anyhow, Result}; |
8 | 8 | use bstr::ByteSlice;
|
9 | 9 | use clap::{Arg, ArgMatches};
|
10 | 10 | use termcolor::WriteColor;
|
11 | 11 |
|
12 | 12 | use crate::{
|
13 | 13 | argset::{self, get_one_str},
|
14 |
| - print_info_message, print_warning_message, |
| 14 | + print_info_message, |
15 | 15 | repo::RepositoryExtended,
|
16 | 16 | stack::{get_branch_name, state_refname_from_branch_name, Stack, StackStateAccess},
|
17 | 17 | stupid::Stupid,
|
@@ -248,12 +248,14 @@ fn run(matches: &ArgMatches) -> Result<()> {
|
248 | 248 | if target_branchname == current_branchname {
|
249 | 249 | Err(anyhow!("{target_branchname} is already the current branch"))
|
250 | 250 | } else {
|
| 251 | + let stupid = repo.stupid(); |
| 252 | + let statuses = stupid.statuses(None)?; |
251 | 253 | if !matches.contains_id("merge") {
|
252 |
| - let statuses = repo.stupid().statuses(None)?; |
253 | 254 | statuses.check_worktree_clean()?;
|
254 | 255 | }
|
| 256 | + statuses.check_conflicts()?; |
255 | 257 | let target_branch = repo.get_branch(Some(target_branchname))?;
|
256 |
| - switch_to(matches, &repo, &target_branch) |
| 258 | + stupid.checkout(target_branch.name().unwrap().unwrap()) |
257 | 259 | }
|
258 | 260 | } else {
|
259 | 261 | println!("{current_branchname}");
|
@@ -313,31 +315,6 @@ fn set_stgit_parent(
|
313 | 315 | }
|
314 | 316 | }
|
315 | 317 |
|
316 |
| -fn switch_to(matches: &ArgMatches, repo: &git2::Repository, branch: &git2::Branch) -> Result<()> { |
317 |
| - let target_commit = branch.get().peel_to_commit()?; |
318 |
| - let branch_refname = branch.get().name().expect("new branch has UTF-8 name"); |
319 |
| - let mut opts = git2::build::CheckoutBuilder::new(); |
320 |
| - opts.notify_on( |
321 |
| - git2::CheckoutNotificationType::CONFLICT | git2::CheckoutNotificationType::DIRTY, |
322 |
| - ); |
323 |
| - opts.notify(|notification_type, path, _diff0, _diff1, _diff2| { |
324 |
| - if let Some(path) = path { |
325 |
| - let path_string = path.to_string_lossy(); |
326 |
| - print_warning_message(matches, &format!("{notification_type:?} {path_string}")); |
327 |
| - } else { |
328 |
| - print_warning_message(matches, &format!("{notification_type:?}")); |
329 |
| - } |
330 |
| - true |
331 |
| - }); |
332 |
| - repo.checkout_tree_ex(target_commit.as_object(), Some(&mut opts))?; |
333 |
| - repo.set_head(branch_refname) |
334 |
| - .with_context(|| format!("switching to `{branch_refname}`"))?; |
335 |
| - Ok(()) |
336 |
| - |
337 |
| - // let branchname = get_branch_name(branch)?; |
338 |
| - // repo.stupid().checkout(&branchname) |
339 |
| -} |
340 |
| - |
341 | 318 | fn list(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
|
342 | 319 | let mut branchnames = Vec::new();
|
343 | 320 | for branch_result in repo.branches(Some(git2::BranchType::Local))? {
|
@@ -503,7 +480,7 @@ fn create(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
|
503 | 480 | }
|
504 | 481 | }
|
505 | 482 |
|
506 |
| - match switch_to(matches, &repo, &new_branch) { |
| 483 | + match stupid.checkout(new_branch.name().unwrap().unwrap()) { |
507 | 484 | Ok(()) => Ok(()),
|
508 | 485 | Err(e) => {
|
509 | 486 | new_branch.delete()?;
|
@@ -561,8 +538,7 @@ fn clone(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
|
561 | 538 | )?;
|
562 | 539 |
|
563 | 540 | let new_branch = repo.get_branch(Some(&new_branchname))?;
|
564 |
| - |
565 |
| - switch_to(matches, &repo, &new_branch) |
| 541 | + stupid.checkout(new_branch.name().unwrap().unwrap()) |
566 | 542 | }
|
567 | 543 |
|
568 | 544 | fn rename(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
|
|
0 commit comments