diff options
Diffstat (limited to 'src/lib/git/mod.rs')
| -rw-r--r-- | src/lib/git/mod.rs | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs index 45ac58c..a49d306 100644 --- a/src/lib/git/mod.rs +++ b/src/lib/git/mod.rs | |||
| @@ -99,16 +99,16 @@ impl RepoActions for Repo { | |||
| 99 | self.git_repo | 99 | self.git_repo |
| 100 | .path() | 100 | .path() |
| 101 | .parent() | 101 | .parent() |
| 102 | .context("cannot find repositiory path as .git has no parent") | 102 | .context("failed to find repositiory path as .git has no parent") |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | fn get_origin_url(&self) -> Result<String> { | 105 | fn get_origin_url(&self) -> Result<String> { |
| 106 | Ok(self | 106 | Ok(self |
| 107 | .git_repo | 107 | .git_repo |
| 108 | .find_remote("origin") | 108 | .find_remote("origin") |
| 109 | .context("cannot find origin")? | 109 | .context("failed to find origin")? |
| 110 | .url() | 110 | .url() |
| 111 | .context("cannot find origin url")? | 111 | .context("failed to find origin url")? |
| 112 | .to_string()) | 112 | .to_string()) |
| 113 | } | 113 | } |
| 114 | 114 | ||
| @@ -116,7 +116,7 @@ impl RepoActions for Repo { | |||
| 116 | let main_branch_name = { | 116 | let main_branch_name = { |
| 117 | let remote_branches = self | 117 | let remote_branches = self |
| 118 | .get_remote_branch_names() | 118 | .get_remote_branch_names() |
| 119 | .context("cannot find any local branches")?; | 119 | .context("failed to find any local branches")?; |
| 120 | if remote_branches.contains(&"origin/main".to_string()) { | 120 | if remote_branches.contains(&"origin/main".to_string()) { |
| 121 | "origin/main" | 121 | "origin/main" |
| 122 | } else if remote_branches.contains(&"origin/master".to_string()) { | 122 | } else if remote_branches.contains(&"origin/master".to_string()) { |
| @@ -129,7 +129,7 @@ impl RepoActions for Repo { | |||
| 129 | let tip = self | 129 | let tip = self |
| 130 | .get_tip_of_branch(main_branch_name) | 130 | .get_tip_of_branch(main_branch_name) |
| 131 | .context(format!( | 131 | .context(format!( |
| 132 | "branch {main_branch_name} was listed as a remote branch but cannot get its tip commit id", | 132 | "branch {main_branch_name} was listed as a remote branch but failed to get its tip commit id", |
| 133 | ))?; | 133 | ))?; |
| 134 | 134 | ||
| 135 | Ok((main_branch_name, tip)) | 135 | Ok((main_branch_name, tip)) |
| @@ -139,7 +139,7 @@ impl RepoActions for Repo { | |||
| 139 | let main_branch_name = { | 139 | let main_branch_name = { |
| 140 | let local_branches = self | 140 | let local_branches = self |
| 141 | .get_local_branch_names() | 141 | .get_local_branch_names() |
| 142 | .context("cannot find any local branches")?; | 142 | .context("failed to find any local branches")?; |
| 143 | if local_branches.contains(&"main".to_string()) { | 143 | if local_branches.contains(&"main".to_string()) { |
| 144 | "main" | 144 | "main" |
| 145 | } else if local_branches.contains(&"master".to_string()) { | 145 | } else if local_branches.contains(&"master".to_string()) { |
| @@ -152,7 +152,7 @@ impl RepoActions for Repo { | |||
| 152 | let tip = self | 152 | let tip = self |
| 153 | .get_tip_of_branch(main_branch_name) | 153 | .get_tip_of_branch(main_branch_name) |
| 154 | .context(format!( | 154 | .context(format!( |
| 155 | "branch {main_branch_name} was listed as a local branch but cannot get its tip commit id", | 155 | "branch {main_branch_name} was listed as a local branch but failed to get its tip commit id", |
| 156 | ))?; | 156 | ))?; |
| 157 | 157 | ||
| 158 | Ok((main_branch_name, tip)) | 158 | Ok((main_branch_name, tip)) |
| @@ -217,13 +217,15 @@ impl RepoActions for Repo { | |||
| 217 | let branch = if let Ok(branch) = self | 217 | let branch = if let Ok(branch) = self |
| 218 | .git_repo | 218 | .git_repo |
| 219 | .find_branch(branch_name, git2::BranchType::Local) | 219 | .find_branch(branch_name, git2::BranchType::Local) |
| 220 | .context(format!("cannot find local branch {branch_name}")) | 220 | .context(format!("failed to find local branch {branch_name}")) |
| 221 | { | 221 | { |
| 222 | branch | 222 | branch |
| 223 | } else { | 223 | } else { |
| 224 | self.git_repo | 224 | self.git_repo |
| 225 | .find_branch(branch_name, git2::BranchType::Remote) | 225 | .find_branch(branch_name, git2::BranchType::Remote) |
| 226 | .context(format!("cannot find local or remote branch {branch_name}"))? | 226 | .context(format!( |
| 227 | "failed to find local or remote branch {branch_name}" | ||
| 228 | ))? | ||
| 227 | }; | 229 | }; |
| 228 | Ok(oid_to_sha1(&branch.into_reference().peel_to_commit()?.id())) | 230 | Ok(oid_to_sha1(&branch.into_reference().peel_to_commit()?.id())) |
| 229 | } | 231 | } |
| @@ -385,7 +387,7 @@ impl RepoActions for Repo { | |||
| 385 | .context("failed to extract signature - perhaps there is no signature?")?; | 387 | .context("failed to extract signature - perhaps there is no signature?")?; |
| 386 | 388 | ||
| 387 | Ok(std::str::from_utf8(&sign) | 389 | Ok(std::str::from_utf8(&sign) |
| 388 | .context("commit signature cannot be converted to a utf8 string")? | 390 | .context("commit signature failed to be converted to a utf8 string")? |
| 389 | .to_owned()) | 391 | .to_owned()) |
| 390 | } | 392 | } |
| 391 | 393 | ||
| @@ -525,7 +527,7 @@ impl RepoActions for Repo { | |||
| 525 | last_patch | 527 | last_patch |
| 526 | } else { | 528 | } else { |
| 527 | self.checkout(branch_name) | 529 | self.checkout(branch_name) |
| 528 | .context("no patches and so cannot create a proposal branch")?; | 530 | .context("no patches and so failed to create a proposal branch")?; |
| 529 | return Ok(vec![]); | 531 | return Ok(vec![]); |
| 530 | }, | 532 | }, |
| 531 | "parent-commit", | 533 | "parent-commit", |
| @@ -533,7 +535,7 @@ impl RepoActions for Repo { | |||
| 533 | 535 | ||
| 534 | // check patches can be applied | 536 | // check patches can be applied |
| 535 | if !self.does_commit_exist(&parent_commit_id)? { | 537 | if !self.does_commit_exist(&parent_commit_id)? { |
| 536 | bail!("cannot find parent commit ({parent_commit_id}). run git pull and try again.") | 538 | bail!("failed to find parent commit ({parent_commit_id}). run git pull and try again.") |
| 537 | } | 539 | } |
| 538 | 540 | ||
| 539 | // checkout branch | 541 | // checkout branch |
| @@ -644,7 +646,7 @@ impl RepoActions for Repo { | |||
| 644 | None, | 646 | None, |
| 645 | None, | 647 | None, |
| 646 | ) | 648 | ) |
| 647 | .context("cannot amend commit to produce new oid")?; | 649 | .context("failed to amend commit to produce new oid")?; |
| 648 | } | 650 | } |
| 649 | if !applied_oid.to_string().eq(commit_id) { | 651 | if !applied_oid.to_string().eq(commit_id) { |
| 650 | bail!( | 652 | bail!( |
| @@ -669,12 +671,12 @@ impl RepoActions for Repo { | |||
| 669 | &oid_to_sha1( | 671 | &oid_to_sha1( |
| 670 | &revspec | 672 | &revspec |
| 671 | .from() | 673 | .from() |
| 672 | .context("cannot get starting commit from specified value")? | 674 | .context("failed to get starting commit from specified value")? |
| 673 | .id(), | 675 | .id(), |
| 674 | ), | 676 | ), |
| 675 | &self | 677 | &self |
| 676 | .get_head_commit() | 678 | .get_head_commit() |
| 677 | .context("cannot get head commit with gitlib2")?, | 679 | .context("failed to get head commit with gitlib2")?, |
| 678 | ) | 680 | ) |
| 679 | .context("specified commit is not an ancestor of current head")?; | 681 | .context("specified commit is not an ancestor of current head")?; |
| 680 | Ok(ahead) | 682 | Ok(ahead) |
| @@ -684,13 +686,13 @@ impl RepoActions for Repo { | |||
| 684 | &oid_to_sha1( | 686 | &oid_to_sha1( |
| 685 | &revspec | 687 | &revspec |
| 686 | .from() | 688 | .from() |
| 687 | .context("cannot get starting commit of range from specified value")? | 689 | .context("failed to get starting commit of range from specified value")? |
| 688 | .id(), | 690 | .id(), |
| 689 | ), | 691 | ), |
| 690 | &oid_to_sha1( | 692 | &oid_to_sha1( |
| 691 | &revspec | 693 | &revspec |
| 692 | .to() | 694 | .to() |
| 693 | .context("cannot get end of range commit from specified value")? | 695 | .context("failed to get end of range commit from specified value")? |
| 694 | .id(), | 696 | .id(), |
| 695 | ), | 697 | ), |
| 696 | ) | 698 | ) |
| @@ -720,11 +722,13 @@ impl RepoActions for Repo { | |||
| 720 | match if just_global { | 722 | match if just_global { |
| 721 | self.git_repo | 723 | self.git_repo |
| 722 | .config() | 724 | .config() |
| 723 | .context("cannot open git config")? | 725 | .context("failed to open git config")? |
| 724 | .open_global() | 726 | .open_global() |
| 725 | .context("cannot open global git config")? | 727 | .context("failed to open global git config")? |
| 726 | } else { | 728 | } else { |
| 727 | self.git_repo.config().context("cannot open git config")? | 729 | self.git_repo |
| 730 | .config() | ||
| 731 | .context("failed to open git config")? | ||
| 728 | } | 732 | } |
| 729 | .get_entry(item) | 733 | .get_entry(item) |
| 730 | { | 734 | { |
| @@ -742,7 +746,7 @@ impl RepoActions for Repo { | |||
| 742 | } | 746 | } |
| 743 | Ok(Some( | 747 | Ok(Some( |
| 744 | item.value() | 748 | item.value() |
| 745 | .context("cannot find git config item")? | 749 | .context("failed to find git config item")? |
| 746 | .to_string(), | 750 | .to_string(), |
| 747 | )) | 751 | )) |
| 748 | } | 752 | } |
| @@ -754,15 +758,17 @@ impl RepoActions for Repo { | |||
| 754 | if global { | 758 | if global { |
| 755 | self.git_repo | 759 | self.git_repo |
| 756 | .config() | 760 | .config() |
| 757 | .context("cannot open git config")? | 761 | .context("failed to open git config")? |
| 758 | .open_global() | 762 | .open_global() |
| 759 | .context("cannot open global git config")? | 763 | .context("failed to open global git config")? |
| 760 | } else { | 764 | } else { |
| 761 | self.git_repo.config().context("cannot open git config")? | 765 | self.git_repo |
| 766 | .config() | ||
| 767 | .context("failed to open git config")? | ||
| 762 | } | 768 | } |
| 763 | .set_str(item, value) | 769 | .set_str(item, value) |
| 764 | .context(format!( | 770 | .context(format!( |
| 765 | "cannot set {} git config item {}", | 771 | "failed to set {} git config item {}", |
| 766 | if global { "global" } else { "local" }, | 772 | if global { "global" } else { "local" }, |
| 767 | item | 773 | item |
| 768 | ))?; | 774 | ))?; |
| @@ -777,14 +783,16 @@ impl RepoActions for Repo { | |||
| 777 | if global { | 783 | if global { |
| 778 | self.git_repo | 784 | self.git_repo |
| 779 | .config() | 785 | .config() |
| 780 | .context("cannot open git config")? | 786 | .context("failed to open git config")? |
| 781 | .open_global() | 787 | .open_global() |
| 782 | .context("cannot open global git config")? | 788 | .context("failed to open global git config")? |
| 783 | } else { | 789 | } else { |
| 784 | self.git_repo.config().context("cannot open git config")? | 790 | self.git_repo |
| 791 | .config() | ||
| 792 | .context("failed to open git config")? | ||
| 785 | } | 793 | } |
| 786 | .remove(item) | 794 | .remove(item) |
| 787 | .context("cannot remove existing git config item")?; | 795 | .context("failed to remove existing git config item")?; |
| 788 | Ok(true) | 796 | Ok(true) |
| 789 | } | 797 | } |
| 790 | } | 798 | } |
| @@ -880,7 +888,7 @@ pub fn save_git_config_item(git_repo: &Option<&Repo>, item: &str, value: &str) - | |||
| 880 | git2::Config::open_default()? | 888 | git2::Config::open_default()? |
| 881 | .open_global()? | 889 | .open_global()? |
| 882 | .set_str(item, value) | 890 | .set_str(item, value) |
| 883 | .context(format!("cannot set global git config item {}", item)) | 891 | .context(format!("failed to set global git config item {}", item)) |
| 884 | } | 892 | } |
| 885 | } | 893 | } |
| 886 | 894 | ||
| @@ -893,7 +901,10 @@ pub fn remove_git_config_item(git_repo: &Option<&Repo>, item: &str) -> Result<bo | |||
| 893 | git2::Config::open_default()? | 901 | git2::Config::open_default()? |
| 894 | .open_global()? | 902 | .open_global()? |
| 895 | .remove(item) | 903 | .remove(item) |
| 896 | .context(format!("cannot remove existing git config item {}", item))?; | 904 | .context(format!( |
| 905 | "failed to remove existing git config item {}", | ||
| 906 | item | ||
| 907 | ))?; | ||
| 897 | Ok(true) | 908 | Ok(true) |
| 898 | } | 909 | } |
| 899 | } | 910 | } |