Skip to content

feat: allow signing rebased commits #3243

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

Closed
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
17 changes: 16 additions & 1 deletion gitbutler-app/src/project_repository/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::{Context, Result};

use crate::{
askpass::AskpassBroker,
git::{self, credentials::HelpError, Url},
git::{self, credentials::HelpError, Oid, Url},
keys,
projects::{self, AuthKey},
ssh, users,
Expand Down Expand Up @@ -138,6 +138,21 @@ impl Repository {
Ok(head)
}

pub fn get_index(&self) -> Result<git::Index, git::Error> {
let index = self.git_repository.index()?;
Ok(index)
}

pub fn find_commit(&self, oid: Oid) -> Result<git::Commit, git::Error> {
let commit = self.git_repository.find_commit(oid)?;
Ok(commit)
}

pub fn find_tree(&self, oid: Oid) -> Result<git::Tree, git::Error> {
let tree = self.git_repository.find_tree(oid)?;
Ok(tree)
}

pub fn get_wd_tree(&self) -> Result<git::Tree> {
let tree = self.git_repository.get_wd_tree()?;
Ok(tree)
Expand Down
40 changes: 34 additions & 6 deletions gitbutler-app/src/virtual_branches/virtual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ pub fn merge_virtual_branch_upstream(
let (_, committer) = project_repository.git_signatures(user)?;
let mut rebase_options = git2::RebaseOptions::new();
rebase_options.quiet(true);
rebase_options.inmemory(true);
rebase_options.inmemory(false);
let mut rebase = repo
.rebase(
Some(branch.head),
Expand All @@ -1526,16 +1526,44 @@ pub fn merge_virtual_branch_upstream(
let mut rebase_success = true;
// check to see if these commits have already been pushed
let mut last_rebase_head = upstream_commit.id();
while rebase.next().is_some() {
let index = rebase
.inmemory_index()
.context("failed to get inmemory index")?;
loop {
let rebase_operation = rebase.next();

if rebase_operation.is_none() {
break;
}

let rebase_operation = rebase_operation.unwrap().unwrap();

let mut index = project_repository.get_index().unwrap();
if index.has_conflicts() {
rebase_success = false;
break;
}

if let Ok(commit_id) = rebase.commit(None, &committer.clone().into(), None) {
if signing_key.is_some() {
let commit_id = rebase_operation.id();
let commit = project_repository.find_commit(commit_id.into()).unwrap();
let message = commit.message().unwrap();
let tree_id = index.write_tree().unwrap();
let tree = project_repository.find_tree(tree_id).unwrap();

let head = project_repository.get_head().unwrap();
let head_commit = head.peel_to_commit().unwrap();

if let Ok(commit_id) = project_repository.commit(
user,
message,
&tree,
&[&head_commit],
signing_key,
) {
last_rebase_head = commit_id;
} else {
rebase_success = false;
break;
}
} else if let Ok(commit_id) = rebase.commit(None, &committer.clone().into(), None) {
last_rebase_head = commit_id.into();
} else {
rebase_success = false;
Expand Down