summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-12-09 03:03:53 +0100
committerCyborus <cyborus@cyborus.xyz>2024-12-09 03:03:53 +0100
commit822ff7b97dd9f5cc04a32308a50943e023b341e2 (patch)
treebc39db6f2d156917d99fd254653534e19f6e31d6
parentMerge pull request 'fix ssh url parsing' (#141) from ssh-parse-mistake into main (diff)
downloadforgejo-cli-822ff7b97dd9f5cc04a32308a50943e023b341e2.tar.xz
forgejo-cli-822ff7b97dd9f5cc04a32308a50943e023b341e2.zip
feat: use `Repository::discover` to open local repo
this way, the repo is still found even in subdirectories
-rw-r--r--src/prs.rs8
-rw-r--r--src/repo.rs6
2 files changed, 7 insertions, 7 deletions
diff --git a/src/prs.rs b/src/prs.rs
index 98d54cd..4b629e9 100644
--- a/src/prs.rs
+++ b/src/prs.rs
@@ -391,7 +391,7 @@ impl PrCommand {
eyre::eyre!("can't figure what repo to access, try specifying with `--repo`")
}
Checkout { .. } => {
- if git2::Repository::open(".").is_ok() {
+ if git2::Repository::discover(".").is_ok() {
eyre::eyre!("can't figure out what repo to access, try setting a remote tracking branch")
} else {
eyre::eyre!("pr checkout only works if the current directory is a git repo")
@@ -899,7 +899,7 @@ async fn create_pr(
let head = match head {
Some(head) => head,
None => {
- let local_repo = git2::Repository::open(".")?;
+ let local_repo = git2::Repository::discover(".")?;
let head = local_repo.head()?;
eyre::ensure!(
head.is_branch(),
@@ -1126,7 +1126,7 @@ async fn checkout_pr(
pr: PrNumber,
branch_name: Option<String>,
) -> eyre::Result<()> {
- let local_repo = git2::Repository::open(".").unwrap();
+ let local_repo = git2::Repository::discover(".").unwrap();
let mut options = git2::StatusOptions::new();
options.include_ignored(false);
@@ -1486,7 +1486,7 @@ async fn guess_pr(
repo: &RepoName,
api: &Forgejo,
) -> eyre::Result<forgejo_api::structs::PullRequest> {
- let local_repo = git2::Repository::open(".")?;
+ let local_repo = git2::Repository::discover(".")?;
let head = local_repo.head()?;
eyre::ensure!(head.is_branch(), "head is not on branch");
let local_branch = git2::Branch::wrap(head);
diff --git a/src/repo.rs b/src/repo.rs
index 3780642..923c30c 100644
--- a/src/repo.rs
+++ b/src/repo.rs
@@ -75,7 +75,7 @@ impl RepoInfo {
let (remote_url, remote_repo_name) = {
let mut out = (None, None);
- if let Ok(local_repo) = git2::Repository::open(".") {
+ if let Ok(local_repo) = git2::Repository::discover(".") {
let mut name = remote.map(|s| s.to_owned());
// if there's only one remote, use that
@@ -544,7 +544,7 @@ pub async fn create_repo(
push: bool,
) -> eyre::Result<()> {
if remote.is_some() || push {
- let repo = git2::Repository::open(".")?;
+ let repo = git2::Repository::discover(".")?;
let upstream = remote.as_deref().unwrap_or("origin");
if repo.find_remote(upstream).is_ok() {
@@ -573,7 +573,7 @@ pub async fn create_repo(
println!("created new repo at {}", html_url);
if remote.is_some() || push {
- let repo = git2::Repository::open(".")?;
+ let repo = git2::Repository::discover(".")?;
let upstream = remote.as_deref().unwrap_or("origin");
let clone_url = new_repo