2022-03-21 17:36:06 +09:00
|
|
|
use napi::bindgen_prelude::*;
|
|
|
|
|
|
|
|
pub struct Repository {
|
|
|
|
dir: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Repository {
|
|
|
|
fn remote(&self) -> Remote {
|
|
|
|
Remote { inner: self }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Remote<'repo> {
|
|
|
|
inner: &'repo Repository,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'repo> Remote<'repo> {
|
|
|
|
fn name(&self) -> String {
|
|
|
|
"origin".to_owned()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[napi]
|
|
|
|
pub struct JsRepo {
|
|
|
|
inner: Repository,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[napi]
|
|
|
|
impl JsRepo {
|
|
|
|
#[napi(constructor)]
|
|
|
|
pub fn new(dir: String) -> Self {
|
|
|
|
JsRepo {
|
|
|
|
inner: Repository { dir },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[napi]
|
2022-04-02 16:19:53 +09:00
|
|
|
pub fn remote(&self, reference: Reference<JsRepo>, env: Env) -> Result<JsRemote> {
|
2022-03-21 17:36:06 +09:00
|
|
|
Ok(JsRemote {
|
2022-04-02 16:19:53 +09:00
|
|
|
inner: reference.share_with(env, |repo| Ok(repo.inner.remote()))?,
|
2022-03-21 17:36:06 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[napi]
|
|
|
|
pub struct JsRemote {
|
|
|
|
inner: SharedReference<JsRepo, Remote<'static>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[napi]
|
|
|
|
impl JsRemote {
|
|
|
|
#[napi]
|
|
|
|
pub fn name(&self) -> String {
|
|
|
|
self.inner.name()
|
|
|
|
}
|
|
|
|
}
|