mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-22 17:11:43 +03:00
move fetch and push to project
This commit is contained in:
parent
8878c89f06
commit
21ec8d9f14
@ -467,7 +467,8 @@ impl App {
|
||||
pub fn push_virtual_branch(&self, project_id: &str, branch_id: &str) -> Result<()> {
|
||||
let gb_repository = self.gb_repository(project_id)?;
|
||||
let project = self.gb_project(project_id)?;
|
||||
virtual_branches::push(&project.path, &gb_repository, branch_id)?;
|
||||
let project_repository = project_repository::Repository::open(&project)?;
|
||||
virtual_branches::push(&project_repository, &gb_repository, branch_id)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::{collections::HashMap, env};
|
||||
use std::{collections::HashMap, env, process::Command};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use git2::Diff;
|
||||
@ -359,6 +359,39 @@ impl<'repository> Repository<'repository> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn push(&self, head: &git2::Oid, upstream: &str) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.arg("push")
|
||||
.arg("origin")
|
||||
.arg(format!("{}:{}", head, upstream))
|
||||
.current_dir(&self.project.path)
|
||||
.output()
|
||||
.context("failed to fork exec")?;
|
||||
|
||||
output.status.success().then(|| ()).ok_or_else(|| {
|
||||
anyhow::anyhow!(
|
||||
"failed to push: {}",
|
||||
String::from_utf8(output.stderr).unwrap()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn fetch(&self) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.arg("fetch")
|
||||
.arg("origin")
|
||||
.current_dir(&self.project.path)
|
||||
.output()
|
||||
.context("failed to fork exec")?;
|
||||
|
||||
output.status.success().then(|| ()).ok_or_else(|| {
|
||||
anyhow::anyhow!(
|
||||
"failed to fetch: {}",
|
||||
String::from_utf8(output.stderr).unwrap()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn git_commit(&self, message: &str, push: bool) -> Result<()> {
|
||||
let config = self
|
||||
.git_repository
|
||||
|
@ -1700,12 +1700,11 @@ fn name_to_branch(name: &str) -> String {
|
||||
.map(|c| if c.is_ascii_alphanumeric() { c } else { '-' })
|
||||
.collect::<String>();
|
||||
|
||||
return format!("refs/heads/{}", cleaned_name);
|
||||
format!("refs/heads/{}", cleaned_name)
|
||||
}
|
||||
|
||||
use std::process::Command;
|
||||
pub fn push(
|
||||
project_path: &str,
|
||||
project_repository: &project_repository::Repository,
|
||||
gb_repository: &gb_repository::Repository,
|
||||
branch_id: &str,
|
||||
) -> Result<()> {
|
||||
@ -1728,45 +1727,18 @@ pub fn push(
|
||||
vbranch.upstream.clone()
|
||||
};
|
||||
|
||||
let output = Command::new("git")
|
||||
.arg("push")
|
||||
.arg("origin")
|
||||
.arg(format!("{}:{}", vbranch.head, upstream))
|
||||
.current_dir(project_path)
|
||||
.output()
|
||||
.context("failed to fork exec")?;
|
||||
project_repository
|
||||
.push(&vbranch.head, &upstream)
|
||||
.context("failed to fetch before push")?;
|
||||
|
||||
if output.status.success() {
|
||||
vbranch.upstream = upstream;
|
||||
branch_writer
|
||||
.write(&vbranch)
|
||||
.context("failed to write target branch after push")?;
|
||||
fetch(project_path).context("failed to fetch after push")?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow::anyhow!(
|
||||
"failed to push branch: {}",
|
||||
String::from_utf8(output.stderr)?
|
||||
))
|
||||
}
|
||||
}
|
||||
vbranch.upstream = upstream;
|
||||
branch_writer
|
||||
.write(&vbranch)
|
||||
.context("failed to write target branch after push")?;
|
||||
|
||||
fn fetch(project_path: &str) -> Result<()> {
|
||||
let output = Command::new("git")
|
||||
.arg("fetch")
|
||||
.arg("origin")
|
||||
.current_dir(project_path)
|
||||
.output()
|
||||
.context("failed to fork exec")?;
|
||||
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow::anyhow!(
|
||||
"failed to fetch: {}",
|
||||
String::from_utf8(output.stderr)?
|
||||
))
|
||||
}
|
||||
project_repository
|
||||
.fetch()
|
||||
.context("failed to fetch before push")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Loading…
Reference in New Issue
Block a user