mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2025-03-14 21:25:54 +01:00
feat: use Repository::discover
to open local repo
this way, the repo is still found even in subdirectories
This commit is contained in:
parent
b658dbbfa4
commit
822ff7b97d
2 changed files with 7 additions and 7 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue