Merge pull request #1206 from gitbutlerapp/cleanup

rm some unused code
This commit is contained in:
Nikita Galaiko 2023-09-15 09:45:15 +02:00 committed by GitHub
commit 573419c342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 126 deletions

View File

@ -416,13 +416,6 @@ impl App {
project_repository.git_match_paths(pattern)
}
pub fn git_branches(&self, project_id: &str) -> Result<Vec<git::LocalBranchName>> {
let project = self.gb_project(project_id)?;
let project_repository = project_repository::Repository::open(&project)
.context("failed to open project repository")?;
project_repository.git_branches()
}
pub fn git_remote_branches(&self, project_id: &str) -> Result<Vec<git::RemoteBranchName>> {
let project = self.gb_project(project_id)?;
let project_repository = project_repository::Repository::open(&project)
@ -449,35 +442,6 @@ impl App {
Ok(head.name().unwrap().to_string())
}
pub fn git_set_config(&self, project_id: &str, key: &str, value: &str) -> Result<String> {
let project = self.gb_project(project_id)?;
let project_repository = project_repository::Repository::open(&project)
.context("failed to open project repository")?;
let repo = &project_repository.git_repository;
let mut config = repo.config()?;
config.open_level(git2::ConfigLevel::Local)?;
config.set_str(key, value)?;
Ok(value.to_string())
}
pub fn git_get_config(&self, project_id: &str, key: &str) -> Result<Option<String>> {
let project = self.gb_project(project_id)?;
let project_repository = project_repository::Repository::open(&project)?;
let repo = &project_repository.git_repository;
let config = repo.config()?;
let value = config.get_string(key);
match value {
Ok(value) => Ok(Some(value)),
Err(e) => {
if e.code() == git2::ErrorCode::NotFound {
Ok(None)
} else {
Err(e.into())
}
}
}
}
pub fn git_set_global_config(&self, key: &str, value: &str) -> Result<String> {
let mut config = git2::Config::open_default()?;
config.set_str(key, value)?;
@ -499,15 +463,6 @@ impl App {
}
}
pub fn git_switch_branch(&self, project_id: &str, branch: &git::LocalBranchName) -> Result<()> {
let project = self.gb_project(project_id)?;
let project_repository = project_repository::Repository::open(&project)
.context("failed to open project repository")?;
let gb_repository = self.gb_repository(project_id)?;
gb_repository.flush().context("failed to flush session")?;
project_repository.git_switch_branch(branch)
}
pub fn git_gb_push(&self, project_id: &str) -> Result<()> {
let gb_repository = self.gb_repository(project_id)?;
gb_repository.push()

View File

@ -325,19 +325,6 @@ async fn git_match_paths(
Ok(paths)
}
#[tauri::command(async)]
#[instrument(skip(handle))]
async fn git_branches(
handle: tauri::AppHandle,
project_id: &str,
) -> Result<Vec<git::LocalBranchName>, Error> {
let app = handle.state::<app::App>();
let branches = app
.git_branches(project_id)
.with_context(|| format!("failed to get git branches for project {}", project_id))?;
Ok(branches)
}
#[tauri::command(async)]
#[instrument(skip(handle))]
async fn git_remote_branches(
@ -421,22 +408,6 @@ async fn git_head(handle: tauri::AppHandle, project_id: &str) -> Result<String,
Ok(head)
}
#[tauri::command(async)]
#[instrument(skip(handle))]
async fn git_switch_branch(
handle: tauri::AppHandle,
project_id: &str,
branch: &str,
) -> Result<(), Error> {
let app = handle.state::<app::App>();
let branch_name = format!("refs/heads/{}", branch)
.parse()
.context("invalid branch name")?;
app.git_switch_branch(project_id, &branch_name)
.with_context(|| format!("failed to switch git branch for project {}", project_id))?;
Ok(())
}
#[tauri::command(async)]
#[instrument(skip(handle))]
async fn git_stage(
@ -547,31 +518,6 @@ async fn mark_resolved(
Ok(())
}
#[tauri::command(async)]
#[instrument(skip(handle))]
async fn git_set_config(
handle: tauri::AppHandle,
project_id: &str,
key: &str,
value: &str,
) -> Result<String, Error> {
let app = handle.state::<app::App>();
let result = app.git_set_config(project_id, key, value)?;
Ok(result)
}
#[tauri::command(async)]
#[instrument(skip(handle))]
async fn git_get_config(
handle: tauri::AppHandle,
project_id: &str,
key: &str,
) -> Result<Option<String>, Error> {
let app = handle.state::<app::App>();
let result = app.git_get_config(project_id, key)?;
Ok(result)
}
#[tauri::command(async)]
#[instrument(skip(handle))]
async fn git_set_global_config(
@ -730,11 +676,9 @@ async fn main() {
git_status,
git_activity,
git_match_paths,
git_branches,
git_remote_branches,
git_remote_branches_data,
git_head,
git_switch_branch,
git_commit,
git_stage,
git_unstage,
@ -760,8 +704,6 @@ async fn main() {
virtual_branches::commands::create_virtual_branch_from_branch,
fetch_from_target,
mark_resolved,
git_set_config,
git_get_config,
git_set_global_config,
git_get_global_config,
keys::commands::get_public_key,

View File

@ -214,18 +214,6 @@ impl<'repository> Repository<'repository> {
Ok(files)
}
pub fn git_branches(&self) -> Result<Vec<git::LocalBranchName>> {
self.git_repository
.branches(Some(git2::BranchType::Local))?
.flatten()
.map(|(branch, _)| branch)
.map(|branch| {
git::LocalBranchName::try_from(&branch)
.context("failed to convert branch to local name")
})
.collect::<Result<Vec<_>>>()
}
pub fn git_remote_branches(&self) -> Result<Vec<git::RemoteBranchName>> {
self.git_repository
.branches(Some(git2::BranchType::Remote))?
@ -324,17 +312,6 @@ impl<'repository> Repository<'repository> {
Ok(oids.len().try_into()?)
}
pub fn git_switch_branch(&self, branch: &git::LocalBranchName) -> Result<()> {
let branch = self.git_repository.find_branch(&branch.clone().into())?;
self.git_repository
.set_head(branch.name().unwrap())
.context("failed to set head")?;
self.git_repository
.checkout_head(Some(&mut git2::build::CheckoutBuilder::default().force()))
.context("failed to checkout head")?;
Ok(())
}
pub fn git_stage_files<P: AsRef<std::path::Path>>(&self, paths: Vec<P>) -> Result<()> {
let mut index = self.git_repository.index()?;
for path in paths {