summaryrefslogtreecommitdiff
path: root/src/rebase.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2014-07-18 14:50:06 -0400
committerEdward Thomson <ethomson@microsoft.com>2014-10-26 22:59:21 -0400
commit93a7004cc234da31d912bb0f266c39b99ab8c8db (patch)
tree06fc49a4dda32a64a77e221f6ebe7109d1754d1b /src/rebase.c
parenta35a9890b00b538cd0f3ef94a526c0dd2ec461bf (diff)
downloadlibgit2-93a7004cc234da31d912bb0f266c39b99ab8c8db.tar.gz
git_rebase_commit: drop already-picked commits
Already cherry-picked commits should not be re-included. If all changes included in a commit exist in the upstream, then we should error with GIT_EAPPLIED.
Diffstat (limited to 'src/rebase.c')
-rw-r--r--src/rebase.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/rebase.c b/src/rebase.c
index 9245dcada..a28a928fc 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -674,7 +674,8 @@ static int rebase_commit_merge(
git_index *index = NULL;
git_reference *head = NULL;
git_commit *head_commit = NULL;
- git_tree *tree = NULL;
+ git_tree *head_tree = NULL, *tree = NULL;
+ git_diff *diff = NULL;
git_oid tree_id;
char old_idstr[GIT_OID_HEXSZ], new_idstr[GIT_OID_HEXSZ];
int error;
@@ -694,11 +695,19 @@ static int rebase_commit_merge(
goto done;
}
- /* TODO: if there are no changes, error with a useful code */
-
if ((error = git_repository_head(&head, repo)) < 0 ||
(error = git_reference_peel((git_object **)&head_commit, head, GIT_OBJ_COMMIT)) < 0 ||
- (error = git_index_write_tree(&tree_id, index)) < 0 ||
+ (error = git_commit_tree(&head_tree, head_commit)) < 0 ||
+ (error = git_diff_tree_to_index(&diff, repo, head_tree, index, NULL)) < 0)
+ goto done;
+
+ if (git_diff_num_deltas(diff) == 0) {
+ giterr_set(GITERR_REBASE, "This patch has already been applied");
+ error = GIT_EAPPLIED;
+ goto done;
+ }
+
+ if ((error = git_index_write_tree(&tree_id, index)) < 0 ||
(error = git_tree_lookup(&tree, repo, &tree_id)) < 0)
goto done;
@@ -722,7 +731,9 @@ static int rebase_commit_merge(
"%.*s %.*s\n", GIT_OID_HEXSZ, old_idstr, GIT_OID_HEXSZ, new_idstr);
done:
+ git_diff_free(diff);
git_tree_free(tree);
+ git_tree_free(head_tree);
git_commit_free(head_commit);
git_reference_free(head);
git_index_free(index);