From c60697b3dcc56a2a62f892f48effce802c35a006 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 29 Jul 2024 09:01:41 +0100 Subject: refactor(remote): abstract `list` in preparation for managing state via nostr --- src/git_remote_helper.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/git_remote_helper.rs') diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs index 793e714..506fd5e 100644 --- a/src/git_remote_helper.rs +++ b/src/git_remote_helper.rs @@ -98,22 +98,10 @@ async fn main() -> Result<()> { push(&git_repo.git_repo, url, &mut temp_remote, &stdin, refspec)?; } ["list"] => { - temp_remote.connect(git2::Direction::Fetch)?; - for head in temp_remote.list()? { - println!("{} {}", head.oid(), head.name()); - } - temp_remote.disconnect()?; - println!(); + list(&mut temp_remote, false)?; } ["list", "for-push"] => { - temp_remote.connect(git2::Direction::Fetch)?; - for head in temp_remote.list()? { - if head.name() != "HEAD" { - println!("{} {}", head.oid(), head.name()); - } - } - temp_remote.disconnect()?; - println!(); + list(&mut temp_remote, true)?; } [] => { return Ok(()); @@ -150,6 +138,18 @@ fn nostr_git_url_to_repo_coordinates(url: &str) -> Result> { Ok(repo_coordinattes) } +fn list(temp_remote: &mut Remote, for_push: bool) -> Result<()> { + temp_remote.connect(git2::Direction::Fetch)?; + for head in temp_remote.list()? { + if !for_push || head.name() != "HEAD" { + println!("{} {}", head.oid(), head.name()); + } + } + temp_remote.disconnect()?; + println!(); + Ok(()) +} + fn fetch(temp_remote: &mut Remote, stdin: &Stdin, refstr: &str) -> Result<()> { temp_remote.connect(git2::Direction::Fetch)?; temp_remote.download(&get_refstrs_from_fetch_batch(stdin, refstr)?, None)?; -- cgit v1.2.3