upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/sub_commands
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-02-09 07:21:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-02-09 07:21:00 +0000
commit9cd3e43b899b23b7f6e75276fa3d19bf9550f8fd (patch)
treef88539e7988e13a7fdd9736a6a672048ee00e59a /src/sub_commands
parent4b0a35583644e703eb615e0724d33fe93aec932b (diff)
refactor(git): find root commit from head
this is simpler there is no need to check whether main or master exist because one does 99+% of the time the root commit wil be te same for head as master 99+% of the time
Diffstat (limited to 'src/sub_commands')
-rw-r--r--src/sub_commands/claim.rs6
-rw-r--r--src/sub_commands/prs/create.rs16
-rw-r--r--src/sub_commands/prs/list.rs6
-rw-r--r--src/sub_commands/pull.rs2
-rw-r--r--src/sub_commands/push.rs2
5 files changed, 8 insertions, 24 deletions
diff --git a/src/sub_commands/claim.rs b/src/sub_commands/claim.rs
index 05ad961..d3a80c8 100644
--- a/src/sub_commands/claim.rs
+++ b/src/sub_commands/claim.rs
@@ -33,12 +33,8 @@ pub struct SubCommandArgs {
33pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { 33pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
34 let git_repo = Repo::discover().context("cannot find a git repository")?; 34 let git_repo = Repo::discover().context("cannot find a git repository")?;
35 35
36 let (main_or_master_branch_name, _) = git_repo
37 .get_main_or_master_branch()
38 .context("no main or master branch")?;
39
40 let root_commit = git_repo 36 let root_commit = git_repo
41 .get_root_commit(main_or_master_branch_name) 37 .get_root_commit()
42 .context("failed to get root commit of the repository")?; 38 .context("failed to get root commit of the repository")?;
43 39
44 // TODO: check for empty repo 40 // TODO: check for empty repo
diff --git a/src/sub_commands/prs/create.rs b/src/sub_commands/prs/create.rs
index 82824a1..8506303 100644
--- a/src/sub_commands/prs/create.rs
+++ b/src/sub_commands/prs/create.rs
@@ -103,7 +103,7 @@ pub async fn launch(
103 let repo_ref = repo_ref::fetch( 103 let repo_ref = repo_ref::fetch(
104 &git_repo, 104 &git_repo,
105 git_repo 105 git_repo
106 .get_root_commit(&to_branch) 106 .get_root_commit()
107 .context("failed to get root commit of the repository")? 107 .context("failed to get root commit of the repository")?
108 .to_string(), 108 .to_string(),
109 &client, 109 &client,
@@ -111,15 +111,8 @@ pub async fn launch(
111 ) 111 )
112 .await?; 112 .await?;
113 113
114 let events = generate_pr_and_patch_events( 114 let events =
115 &title, 115 generate_pr_and_patch_events(&title, &description, &git_repo, &ahead, &keys, &repo_ref)?;
116 &description,
117 &to_branch,
118 &git_repo,
119 &ahead,
120 &keys,
121 &repo_ref,
122 )?;
123 116
124 println!( 117 println!(
125 "posting 1 pull request with {} commits...", 118 "posting 1 pull request with {} commits...",
@@ -315,14 +308,13 @@ pub static PATCH_KIND: u64 = 1617;
315pub fn generate_pr_and_patch_events( 308pub fn generate_pr_and_patch_events(
316 title: &str, 309 title: &str,
317 description: &str, 310 description: &str,
318 to_branch: &str,
319 git_repo: &Repo, 311 git_repo: &Repo,
320 commits: &Vec<Sha1Hash>, 312 commits: &Vec<Sha1Hash>,
321 keys: &nostr::Keys, 313 keys: &nostr::Keys,
322 repo_ref: &RepoRef, 314 repo_ref: &RepoRef,
323) -> Result<Vec<nostr::Event>> { 315) -> Result<Vec<nostr::Event>> {
324 let root_commit = git_repo 316 let root_commit = git_repo
325 .get_root_commit(to_branch) 317 .get_root_commit()
326 .context("failed to get root commit of the repository")?; 318 .context("failed to get root commit of the repository")?;
327 319
328 let mut pr_tags = vec![ 320 let mut pr_tags = vec![
diff --git a/src/sub_commands/prs/list.rs b/src/sub_commands/prs/list.rs
index 96004d4..88b325b 100644
--- a/src/sub_commands/prs/list.rs
+++ b/src/sub_commands/prs/list.rs
@@ -27,12 +27,8 @@ pub async fn launch(
27) -> Result<()> { 27) -> Result<()> {
28 let git_repo = Repo::discover().context("cannot find a git repository")?; 28 let git_repo = Repo::discover().context("cannot find a git repository")?;
29 29
30 let (main_or_master_branch_name, _) = git_repo
31 .get_main_or_master_branch()
32 .context("no main or master branch")?;
33
34 let root_commit = git_repo 30 let root_commit = git_repo
35 .get_root_commit(main_or_master_branch_name) 31 .get_root_commit()
36 .context("failed to get root commit of the repository")?; 32 .context("failed to get root commit of the repository")?;
37 33
38 // TODO: check for empty repo 34 // TODO: check for empty repo
diff --git a/src/sub_commands/pull.rs b/src/sub_commands/pull.rs
index 342c8bb..c426510 100644
--- a/src/sub_commands/pull.rs
+++ b/src/sub_commands/pull.rs
@@ -22,7 +22,7 @@ pub async fn launch() -> Result<()> {
22 .context("no main or master branch")?; 22 .context("no main or master branch")?;
23 23
24 let root_commit = git_repo 24 let root_commit = git_repo
25 .get_root_commit(main_or_master_branch_name) 25 .get_root_commit()
26 .context("failed to get root commit of the repository")?; 26 .context("failed to get root commit of the repository")?;
27 27
28 let branch_name = git_repo 28 let branch_name = git_repo
diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs
index de2a92f..037d512 100644
--- a/src/sub_commands/push.rs
+++ b/src/sub_commands/push.rs
@@ -25,7 +25,7 @@ pub async fn launch(cli_args: &Cli) -> Result<()> {
25 .context("no main or master branch")?; 25 .context("no main or master branch")?;
26 26
27 let root_commit = git_repo 27 let root_commit = git_repo
28 .get_root_commit(main_or_master_branch_name) 28 .get_root_commit()
29 .context("failed to get root commit of the repository")?; 29 .context("failed to get root commit of the repository")?;
30 30
31 let branch_name = git_repo 31 let branch_name = git_repo