remove git2 dependency for repository cloning in semantic_index eval

KCaverly created

Change summary

Cargo.lock                             | 19 ------------------
Cargo.toml                             |  2 
crates/semantic_index/Cargo.toml       |  1 
crates/semantic_index/examples/eval.rs | 29 +++++++++++++--------------
4 files changed, 15 insertions(+), 36 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -3059,8 +3059,6 @@ dependencies = [
  "libc",
  "libgit2-sys",
  "log",
- "openssl-probe",
- "openssl-sys",
  "url",
 ]
 
@@ -4023,9 +4021,7 @@ checksum = "7f3d95f6b51075fe9810a7ae22c7095f12b98005ab364d8544797a825ce946a4"
 dependencies = [
  "cc",
  "libc",
- "libssh2-sys",
  "libz-sys",
- "openssl-sys",
  "pkg-config",
 ]
 
@@ -4066,20 +4062,6 @@ dependencies = [
  "vcpkg",
 ]
 
-[[package]]
-name = "libssh2-sys"
-version = "0.2.23"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b094a36eb4b8b8c8a7b4b8ae43b2944502be3e59cd87687595cf6b0a71b3f4ca"
-dependencies = [
- "cc",
- "libc",
- "libz-sys",
- "openssl-sys",
- "pkg-config",
- "vcpkg",
-]
-
 [[package]]
 name = "libz-sys"
 version = "1.1.12"
@@ -6756,7 +6738,6 @@ dependencies = [
  "editor",
  "env_logger 0.9.3",
  "futures 0.3.28",
- "git2",
  "globset",
  "gpui",
  "isahc",

Cargo.toml 🔗

@@ -116,7 +116,7 @@ toml = { version = "0.5" }
 tree-sitter = "0.20"
 unindent = { version = "0.1.7" }
 pretty_assertions = "1.3.0"
-git2 = { version = "0.15" }
+git2 = { version = "0.15", default-features = false}
 
 tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "1b0321ee85701d5036c334a6f04761cdc672e64c" }
 tree-sitter-c = "0.20.1"

crates/semantic_index/Cargo.toml 🔗

@@ -55,7 +55,6 @@ rust-embed = { version = "8.0", features = ["include-exclude"] }
 client = { path = "../client" }
 zed = { path = "../zed"}
 node_runtime = { path = "../node_runtime"}
-git2.workspace = true
 
 pretty_assertions.workspace = true
 rand.workspace = true

crates/semantic_index/examples/eval.rs 🔗

@@ -1,6 +1,5 @@
 use anyhow::{anyhow, Result};
 use client::{self, UserStore};
-use git2::{Object, Oid, Repository};
 use gpui::{AsyncAppContext, ModelHandle, Task};
 use language::LanguageRegistry;
 use node_runtime::RealNodeRuntime;
@@ -11,6 +10,7 @@ use semantic_index::{SearchResult, SemanticIndex};
 use serde::{Deserialize, Serialize};
 use settings::{default_settings, handle_settings_file_changes, watch_config_file, SettingsStore};
 use std::path::{Path, PathBuf};
+use std::process::Command;
 use std::sync::Arc;
 use std::time::{Duration, Instant};
 use std::{cmp, env, fs};
@@ -95,23 +95,22 @@ fn clone_repo(repo_eval: RepoEval) -> anyhow::Result<(String, PathBuf)> {
         .ok_or(anyhow!("path canonicalization failed"))?
         .parent()
         .unwrap()
-        .join(TMP_REPO_PATH)
-        .join(&repo_name);
+        .join(TMP_REPO_PATH);
 
     // Delete Clone Path if already exists
     let _ = fs::remove_dir_all(&clone_path);
-
-    // Clone in Repo
-    git2::build::RepoBuilder::new()
-        // .branch(repo_eval.sha.as_str())
-        .clone(repo_eval.repo.as_str(), clone_path.as_path())?;
-
-    let repo: Repository = Repository::open(clone_path.clone())?;
-    let obj: Object = repo
-        .find_commit(Oid::from_str(repo_eval.commit.as_str())?)?
-        .into_object();
-    repo.checkout_tree(&obj, None)?;
-    repo.set_head_detached(obj.id())?;
+    let _ = fs::create_dir(&clone_path);
+
+    let _ = Command::new("git")
+        .args(["clone", repo_eval.repo.as_str()])
+        .current_dir(clone_path.clone())
+        .output()?;
+    // Update clone path to be new directory housing the repo.
+    let clone_path = clone_path.join(repo_name.clone());
+    let _ = Command::new("git")
+        .args(["checkout", repo_eval.commit.as_str()])
+        .current_dir(clone_path.clone())
+        .output()?;
 
     Ok((repo_name, clone_path))
 }