git_workflow/commands/
home.rs1use crate::error::{GwError, Result};
4use crate::git;
5use crate::output;
6use crate::state::RepoType;
7
8pub fn run(verbose: bool) -> Result<()> {
10 if !git::is_git_repo() {
12 return Err(GwError::NotAGitRepository);
13 }
14
15 let repo_type = RepoType::detect()?;
16 let home_branch = repo_type.home_branch();
17 let current = git::current_branch()?;
18
19 println!();
20 output::info(&format!("Home branch: {}", output::bold(home_branch)));
21
22 output::info("Fetching from origin...");
24 git::fetch_prune(verbose)?;
25 output::success("Fetched (stale remote branches pruned)");
26
27 if current != home_branch {
29 if !git::branch_exists(home_branch) {
30 output::info("Creating home branch from origin/main...");
31 git::checkout_new_branch(home_branch, "origin/main", verbose)?;
32 output::success(&format!(
33 "Created and switched to {}",
34 output::bold(home_branch)
35 ));
36 } else {
37 git::checkout(home_branch, verbose)?;
38 output::success(&format!("Switched to {}", output::bold(home_branch)));
39 }
40 } else {
41 output::success(&format!("Already on {}", output::bold(home_branch)));
42 }
43
44 output::info("Syncing with origin/main...");
46 let before = git::head_commit()?;
47 git::pull("origin", "main", verbose)?;
48 let after = git::head_commit()?;
49
50 if before != after {
51 let count = git::commit_count(&before, &after)?;
52 output::success(&format!(
53 "Pulled {} commit(s) from origin/main",
54 output::bold(&count.to_string())
55 ));
56 } else {
57 output::success("Already up to date with origin/main");
58 }
59
60 output::ready("Ready", home_branch);
61 output::hints(&["mise run git:new feature/your-feature # Create new branch"]);
62
63 Ok(())
64}