Skip to content

Use gix for cloning repositories #4708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions apps/desktop/src/lib/onboarding/CloneForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@

const targetDir = await join(targetDirPath, remoteUrl.name);

if (remoteUrl.protocol) {
if (remoteUrl.protocol === 'ssh') {
posthog.capture('SSH Clone Attempted');
}
if (!['https', 'http'].includes(remoteUrl.protocol)) {
errors.push({
label: 'Only HTTP(S) Remote URLs allowed'
});
return;
}
}

await invoke('git_clone_repository', {
repositoryUrl,
targetDir
Expand Down
16 changes: 14 additions & 2 deletions crates/gitbutler-tauri/src/repo.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
pub mod commands {
use anyhow::{Context, Result};
use git2::{self};
use gitbutler_project as projects;
use gitbutler_project::ProjectId;
use gitbutler_repo::RepoCommands;
use gix::progress::Discard;
use std::path::Path;
use std::sync::atomic::AtomicBool;
use tauri::State;
use tracing::instrument;

Expand Down Expand Up @@ -45,7 +46,18 @@ pub mod commands {

#[tauri::command(async)]
pub fn git_clone_repository(repository_url: &str, target_dir: &Path) -> Result<(), Error> {
git2::Repository::clone(repository_url, target_dir).context("Cloning failed")?;
let url =
gix::url::parse(repository_url.into()).context("Failed to parse repository URL")?;
let should_interrupt = AtomicBool::new(false);
let mut prepared_clone =
gix::prepare_clone(url, target_dir).context("Failed to prepare clone")?;
let (mut prepared_checkout, _) = prepared_clone
.fetch_then_checkout(Discard, &should_interrupt)
.context("Failed to fetch")?;
let should_interrupt = AtomicBool::new(false);
prepared_checkout
.main_worktree(Discard, &should_interrupt)
.context("Failed to checkout main worktree")?;
Ok(())
}
}
6 changes: 5 additions & 1 deletion crates/gitbutler-watcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ anyhow = "1.0.86"
tokio = { workspace = true, features = ["macros"] }
tokio-util = "0.7.11"
tracing = "0.1.40"
gix = { workspace = true, features = ["excludes"] }
gix = { workspace = true, features = [
"excludes",
"blocking-network-client",
"worktree-mutation",
] }
gitbutler-command-context.workspace = true
gitbutler-project.workspace = true
gitbutler-user.workspace = true
Expand Down
Loading