A simple CPU rendered GUI IDE experience.
root for git dir
bendn 4 weeks ago
parent babdf8f · commit d9f9455
-rw-r--r--src/edi.rs10
-rw-r--r--src/git.rs4
2 files changed, 11 insertions, 3 deletions
diff --git a/src/edi.rs b/src/edi.rs
index 1562df1..35a4ef8 100644
--- a/src/edi.rs
+++ b/src/edi.rs
@@ -162,6 +162,7 @@ pub struct Editor {
#[serde(skip)]
pub bar: Bar,
pub workspace: Option<PathBuf>,
+ pub git_dir: Option<PathBuf>,
#[serde(skip)]
pub lsp: Option<(
&'static Client,
@@ -221,7 +222,7 @@ macro_rules! change {
.unwrap();
inlay!($self);
let o_ = $self.origin.clone();
- let w = $self.workspace.clone();
+ let w = $self.git_dir.clone();
let r = $self.text.rope.clone();
let t =
x.runtime.spawn_blocking(move || {
@@ -273,6 +274,11 @@ impl Editor {
.and_then(|x| x.parent())
.and_then(|x| rooter(&x, "Cargo.toml"))
.and_then(|x| x.canonicalize().ok());
+ me.git_dir = me
+ .workspace
+ .as_deref()
+ .and_then(|x| rooter(&x, ".git"))
+ .and_then(|x| x.canonicalize().ok());
let mut loaded_state = false;
if let Some(ws) = me.workspace.as_deref()
&& let h = hash(&ws)
@@ -1868,6 +1874,7 @@ impl Editor {
}
let r = self.text.r;
let ws = self.workspace.clone();
+ let git_dir = self.workspace.clone();
let tree = self.tree.clone();
let lsp = self.lsp.take();
@@ -1883,6 +1890,7 @@ impl Editor {
self.open_or_restore(&x, lsp, Some(w), ws)?;
self.text.r = r;
self.tree = tree;
+ self.git_dir = git_dir; // maybe it should change? you know. sometimes?
Ok(())
}
diff --git a/src/git.rs b/src/git.rs
index 2f4da65..78c7e1b 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -4,8 +4,8 @@ use git2::Repository;
use imara_diff::InternedInput;
use ropey::Rope;
-pub fn load(p: &Path, ws: &Path) -> Result<Vec<u8>, git2::Error> {
- let r = Repository::open(ws)?;
+pub fn load(p: &Path, gd: &Path) -> Result<Vec<u8>, git2::Error> {
+ let r = Repository::open(gd)?;
let o =
r.head()?.peel_to_commit()?.tree()?.get_path(p)?.to_object(&r)?;
let blob = o