Move git related things into specialized git crate

Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
Julia 2022-09-28 11:43:33 -04:00
parent bf3b3da6ed
commit d5fd531743
17 changed files with 151 additions and 100 deletions

View file

@ -2,20 +2,13 @@
pub mod test;
use futures::Future;
use lazy_static::lazy_static;
use std::{
cmp::Ordering,
ffi::OsStr,
ops::AddAssign,
pin::Pin,
task::{Context, Poll},
};
lazy_static! {
pub static ref DOT_GIT: &'static OsStr = OsStr::new(".git");
pub static ref GITIGNORE: &'static OsStr = OsStr::new(".gitignore");
}
pub fn truncate(s: &str, max_chars: usize) -> &str {
match s.char_indices().nth(max_chars) {
None => s,

View file

@ -2,14 +2,15 @@ mod assertions;
mod marked_text;
use git2;
use std::path::{Path, PathBuf};
use std::{
ffi::OsStr,
path::{Path, PathBuf},
};
use tempdir::TempDir;
pub use assertions::*;
pub use marked_text::*;
use crate::DOT_GIT;
pub fn temp_tree(tree: serde_json::Value) -> TempDir {
let dir = TempDir::new("").unwrap();
write_tree(dir.path(), tree);
@ -28,7 +29,7 @@ fn write_tree(path: &Path, tree: serde_json::Value) {
Value::Object(_) => {
fs::create_dir(&path).unwrap();
if path.file_name() == Some(&DOT_GIT) {
if path.file_name() == Some(&OsStr::new(".git")) {
git2::Repository::init(&path.parent().unwrap()).unwrap();
}