From 16973be42817b206cd948384b9c1c2198a6ca524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Thu, 28 Aug 2025 18:23:22 +0200 Subject: [PATCH 1/5] Fix comment --- tests/it/src/commands/blame_copy_royal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/it/src/commands/blame_copy_royal.rs b/tests/it/src/commands/blame_copy_royal.rs index 75a31bd90e2..6eaa2e51e09 100644 --- a/tests/it/src/commands/blame_copy_royal.rs +++ b/tests/it/src/commands/blame_copy_royal.rs @@ -217,7 +217,7 @@ git commit -m {commit_id} // history’s root being the last element. We reverse the order in place so that all // methods can rely on the assumption that the root comes first, followed by its // descendants. That way, we can use a simple `for` loop to iterate through - // `self.blame_path` below. + // `self.blame_infos` below. self.blame_infos.reverse(); for blame_path_entry in self.blame_infos.clone() { From 58b5060958e0090773bb15ffb3679d99704b70a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Thu, 28 Aug 2025 18:24:02 +0200 Subject: [PATCH 2/5] feat: add first debug version of `gix branch list` --- gitoxide-core/src/repository/branch.rs | 68 ++++++++++++++++++++++++++ gitoxide-core/src/repository/mod.rs | 1 + src/plumbing/main.rs | 24 ++++++++- src/plumbing/options/mod.rs | 21 ++++++++ 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 gitoxide-core/src/repository/branch.rs diff --git a/gitoxide-core/src/repository/branch.rs b/gitoxide-core/src/repository/branch.rs new file mode 100644 index 00000000000..778875a6fcd --- /dev/null +++ b/gitoxide-core/src/repository/branch.rs @@ -0,0 +1,68 @@ +use crate::OutputFormat; + +pub enum Kind { + Local, + All, +} + +impl Kind { + fn includes_local_branches(&self) -> bool { + match self { + Self::Local | Self::All => true, + } + } + + fn includes_remote_branches(&self) -> bool { + match self { + Self::Local => false, + Self::All => true, + } + } +} + +pub struct Options { + pub kind: Kind, +} + +pub fn list( + repo: gix::Repository, + out: &mut dyn std::io::Write, + format: OutputFormat, + options: Options, +) -> anyhow::Result<()> { + if format != OutputFormat::Human { + anyhow::bail!("JSON output isn't supported"); + } + + let platform = repo.references()?; + + if options.kind.includes_local_branches() { + let mut branch_names: Vec = platform + .local_branches()? + .flatten() + .map(|branch| branch.name().shorten().to_string()) + .collect(); + + branch_names.sort(); + + for branch_name in branch_names { + writeln!(out, "{branch_name}")?; + } + } + + if options.kind.includes_remote_branches() { + let mut branch_names: Vec = platform + .remote_branches()? + .flatten() + .map(|branch| branch.name().shorten().to_string()) + .collect(); + + branch_names.sort(); + + for branch_name in branch_names { + writeln!(out, "{branch_name}")?; + } + } + + Ok(()) +} diff --git a/gitoxide-core/src/repository/mod.rs b/gitoxide-core/src/repository/mod.rs index bf3f5fe0e6d..53161d5696c 100644 --- a/gitoxide-core/src/repository/mod.rs +++ b/gitoxide-core/src/repository/mod.rs @@ -6,6 +6,7 @@ use gix::bstr::BString; #[cfg(feature = "archive")] pub mod archive; +pub mod branch; pub mod cat; pub use cat::function::cat; pub mod blame; diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index 24148035056..ff830ce523f 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -16,8 +16,8 @@ use gix::bstr::{io::BufReadExt, BString}; use crate::{ plumbing::{ options::{ - attributes, commit, commitgraph, config, credential, exclude, free, fsck, index, mailmap, merge, odb, - revision, tag, tree, Args, Subcommands, + attributes, branch, commit, commitgraph, config, credential, exclude, free, fsck, index, mailmap, merge, + odb, revision, tag, tree, Args, Subcommands, }, show_progress, }, @@ -509,6 +509,26 @@ pub fn main() -> Result<()> { ) }, ), + Subcommands::Branch(platform) => match platform.cmds { + Some(branch::Subcommands::List) | None => { + use core::repository::branch::{Kind, Options}; + + let kind = if platform.all { Kind::All } else { Kind::Local }; + let options = Options { kind }; + + prepare_and_run( + "branch-list", + trace, + auto_verbose, + progress, + progress_keep_open, + None, + move |_progress, out, _err| { + core::repository::branch::list(repository(Mode::Lenient)?, out, format, options) + }, + ) + } + }, #[cfg(feature = "gitoxide-core-tools-corpus")] Subcommands::Corpus(crate::plumbing::options::corpus::Platform { db, path, cmd }) => { let reverse_trace_lines = progress; diff --git a/src/plumbing/options/mod.rs b/src/plumbing/options/mod.rs index 33f636b323b..be9830bf97f 100644 --- a/src/plumbing/options/mod.rs +++ b/src/plumbing/options/mod.rs @@ -83,6 +83,9 @@ pub enum Subcommands { /// Subcommands for creating worktree archives. #[cfg(feature = "gitoxide-core-tools-archive")] Archive(archive::Platform), + /// Interact with branches. + #[clap(visible_alias = "branches")] + Branch(branch::Platform), /// Remove untracked files from the working tree. #[cfg(feature = "gitoxide-core-tools-clean")] Clean(clean::Command), @@ -236,6 +239,24 @@ pub mod archive { } } +pub mod branch { + #[derive(Debug, clap::Parser)] + pub struct Platform { + #[clap(subcommand)] + pub cmds: Option, + + /// List remote-tracking as well as local branches. + #[clap(long, short = 'a')] + pub all: bool, + } + + #[derive(Debug, clap::Subcommand)] + pub enum Subcommands { + /// List all tags. + List, + } +} + pub mod status { use gix::bstr::BString; From e53761181b05f90f59b33906da033096b57a50d8 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 29 Aug 2025 05:47:43 +0200 Subject: [PATCH 3/5] refactor --- gitoxide-core/src/repository/branch.rs | 24 +++++++----------------- src/plumbing/main.rs | 10 +++++++--- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/gitoxide-core/src/repository/branch.rs b/gitoxide-core/src/repository/branch.rs index 778875a6fcd..f30593ce6e6 100644 --- a/gitoxide-core/src/repository/branch.rs +++ b/gitoxide-core/src/repository/branch.rs @@ -5,21 +5,6 @@ pub enum Kind { All, } -impl Kind { - fn includes_local_branches(&self) -> bool { - match self { - Self::Local | Self::All => true, - } - } - - fn includes_remote_branches(&self) -> bool { - match self { - Self::Local => false, - Self::All => true, - } - } -} - pub struct Options { pub kind: Kind, } @@ -36,7 +21,12 @@ pub fn list( let platform = repo.references()?; - if options.kind.includes_local_branches() { + let (show_local, show_remotes) = match options.kind { + Kind::Local => (true, false), + Kind::All => (true, true), + }; + + if show_local { let mut branch_names: Vec = platform .local_branches()? .flatten() @@ -50,7 +40,7 @@ pub fn list( } } - if options.kind.includes_remote_branches() { + if show_remotes { let mut branch_names: Vec = platform .remote_branches()? .flatten() diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index ff830ce523f..8c1b077fea2 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -511,10 +511,14 @@ pub fn main() -> Result<()> { ), Subcommands::Branch(platform) => match platform.cmds { Some(branch::Subcommands::List) | None => { - use core::repository::branch::{Kind, Options}; + use core::repository::branch; - let kind = if platform.all { Kind::All } else { Kind::Local }; - let options = Options { kind }; + let kind = if platform.all { + branch::Kind::All + } else { + branch::Kind::Local + }; + let options = branch::Options { kind }; prepare_and_run( "branch-list", From 6651548f6e426d79f834c5948e3d7877784dfc77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Sat, 30 Aug 2025 20:18:56 +0200 Subject: [PATCH 4/5] Move --all to 'branch list' --- gitoxide-core/src/repository/branch.rs | 20 +++++++++++--------- src/plumbing/main.rs | 14 +++++--------- src/plumbing/options/mod.rs | 12 ++++++------ 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/gitoxide-core/src/repository/branch.rs b/gitoxide-core/src/repository/branch.rs index f30593ce6e6..a9fe9b2afa0 100644 --- a/gitoxide-core/src/repository/branch.rs +++ b/gitoxide-core/src/repository/branch.rs @@ -1,19 +1,21 @@ use crate::OutputFormat; -pub enum Kind { - Local, - All, -} +pub mod list { + pub enum Kind { + Local, + All, + } -pub struct Options { - pub kind: Kind, + pub struct Options { + pub kind: Kind, + } } pub fn list( repo: gix::Repository, out: &mut dyn std::io::Write, format: OutputFormat, - options: Options, + options: list::Options, ) -> anyhow::Result<()> { if format != OutputFormat::Human { anyhow::bail!("JSON output isn't supported"); @@ -22,8 +24,8 @@ pub fn list( let platform = repo.references()?; let (show_local, show_remotes) = match options.kind { - Kind::Local => (true, false), - Kind::All => (true, true), + list::Kind::Local => (true, false), + list::Kind::All => (true, true), }; if show_local { diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index 8c1b077fea2..1d0bb96343c 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -509,16 +509,12 @@ pub fn main() -> Result<()> { ) }, ), - Subcommands::Branch(platform) => match platform.cmds { - Some(branch::Subcommands::List) | None => { - use core::repository::branch; + Subcommands::Branch(platform) => match platform.cmd { + branch::Subcommands::List { all } => { + use core::repository::branch::list; - let kind = if platform.all { - branch::Kind::All - } else { - branch::Kind::Local - }; - let options = branch::Options { kind }; + let kind = if all { list::Kind::All } else { list::Kind::Local }; + let options = list::Options { kind }; prepare_and_run( "branch-list", diff --git a/src/plumbing/options/mod.rs b/src/plumbing/options/mod.rs index be9830bf97f..df88032e3b8 100644 --- a/src/plumbing/options/mod.rs +++ b/src/plumbing/options/mod.rs @@ -243,17 +243,17 @@ pub mod branch { #[derive(Debug, clap::Parser)] pub struct Platform { #[clap(subcommand)] - pub cmds: Option, - - /// List remote-tracking as well as local branches. - #[clap(long, short = 'a')] - pub all: bool, + pub cmd: Subcommands, } #[derive(Debug, clap::Subcommand)] pub enum Subcommands { /// List all tags. - List, + List { + /// List remote-tracking as well as local branches. + #[clap(long, short = 'a')] + all: bool, + }, } } From 04650a7786f5fb0ea4f4454d08ca16ab6cef3b74 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 30 Aug 2025 20:57:54 +0200 Subject: [PATCH 5/5] Fix copy-paste doc comment --- src/plumbing/options/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plumbing/options/mod.rs b/src/plumbing/options/mod.rs index df88032e3b8..597c7b7aaea 100644 --- a/src/plumbing/options/mod.rs +++ b/src/plumbing/options/mod.rs @@ -248,7 +248,7 @@ pub mod branch { #[derive(Debug, clap::Subcommand)] pub enum Subcommands { - /// List all tags. + /// List branches. List { /// List remote-tracking as well as local branches. #[clap(long, short = 'a')]