rebase: take `checkout_options` where appropriate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
diff --git a/include/git2/rebase.h b/include/git2/rebase.h
index 3d8d180..8171682 100644
--- a/include/git2/rebase.h
+++ b/include/git2/rebase.h
@@ -143,6 +143,8 @@ GIT_EXTERN(int) git_rebase_init_options(
* @param onto The branch to rebase onto, or NULL to rebase onto the given
* upstream
* @param opts Options to specify how rebase is performed
+ * @param checkout_opts Options to specify how the checkout to the `onto`
+ * branch is performed
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_init(
@@ -151,7 +153,8 @@ GIT_EXTERN(int) git_rebase_init(
const git_annotated_commit *branch,
const git_annotated_commit *upstream,
const git_annotated_commit *onto,
- const git_rebase_options *opts);
+ const git_rebase_options *opts,
+ const git_checkout_options *checkout_opts);
/**
* Opens an existing rebase that was previously started by either an
@@ -245,10 +248,14 @@ GIT_EXTERN(int) git_rebase_commit(
* and working directory to their state before rebase began.
*
* @param rebase The rebase that is in-progress
+ * @param checkout_opts The checkout options that will be used to influence a
+ * hard reset of the working directory.
* @return Zero on success; GIT_ENOTFOUND if a rebase is not in progress,
* -1 on other errors.
*/
-GIT_EXTERN(int) git_rebase_abort(git_rebase *rebase);
+GIT_EXTERN(int) git_rebase_abort(
+ git_rebase *rebase,
+ const git_checkout_options *checkout_opts);
/**
* Finishes a rebase that is currently in progress once all patches have
diff --git a/src/rebase.c b/src/rebase.c
index f8f4a1b..c51bf60 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -658,19 +658,37 @@ done:
return error;
}
+static void normalize_checkout_opts(
+ git_checkout_options *checkout_opts,
+ const git_checkout_options *given_checkout_opts)
+{
+ if (given_checkout_opts != NULL)
+ memcpy(checkout_opts, given_checkout_opts, sizeof(git_checkout_options));
+ else {
+ git_checkout_options default_checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
+ default_checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+
+ memcpy(checkout_opts, &default_checkout_opts, sizeof(git_checkout_options));
+ }
+
+ if (! (checkout_opts->checkout_strategy & (GIT_CHECKOUT_SAFE | GIT_CHECKOUT_FORCE)))
+ checkout_opts->checkout_strategy |= GIT_CHECKOUT_SAFE;
+}
+
int git_rebase_init(
git_rebase **out,
git_repository *repo,
const git_annotated_commit *branch,
const git_annotated_commit *upstream,
const git_annotated_commit *onto,
- const git_rebase_options *given_opts)
+ const git_rebase_options *given_opts,
+ const git_checkout_options *given_checkout_opts)
{
git_rebase *rebase = NULL;
git_rebase_options opts;
git_buf reflog = GIT_BUF_INIT;
git_commit *onto_commit = NULL;
- git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
+ git_checkout_options checkout_opts;
git_reference *head_ref = NULL;
int error;
@@ -679,11 +697,12 @@ int git_rebase_init(
*out = NULL;
GITERR_CHECK_VERSION(given_opts, GIT_REBASE_OPTIONS_VERSION, "git_rebase_options");
+ GITERR_CHECK_VERSION(given_checkout_opts, GIT_CHECKOUT_OPTIONS_VERSION, "git_checkout_options");
if (!onto)
onto = upstream;
- checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+ normalize_checkout_opts(&checkout_opts, given_checkout_opts);
if ((error = rebase_normalize_opts(repo, &opts, given_opts)) < 0 ||
(error = git_repository__ensure_not_bare(repo, "rebase")) < 0 ||
@@ -723,20 +742,13 @@ done:
return error;
}
-static void normalize_checkout_opts(
+static void normalize_checkout_opts_for_apply(
git_rebase *rebase,
git_commit *current_commit,
git_checkout_options *checkout_opts,
const git_checkout_options *given_checkout_opts)
{
- if (given_checkout_opts != NULL)
- memcpy(checkout_opts, given_checkout_opts, sizeof(git_checkout_options));
- else {
- git_checkout_options default_checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
- default_checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
-
- memcpy(checkout_opts, &default_checkout_opts, sizeof(git_checkout_options));
- }
+ normalize_checkout_opts(checkout_opts, given_checkout_opts);
if (!checkout_opts->ancestor_label)
checkout_opts->ancestor_label = "ancestor";
@@ -805,7 +817,7 @@ static int rebase_next_merge(
git_oid_fmt(current_idstr, &operation->id);
- normalize_checkout_opts(rebase, current_commit, &checkout_opts, given_checkout_opts);
+ normalize_checkout_opts_for_apply(rebase, current_commit, &checkout_opts, given_checkout_opts);
if ((error = git_indexwriter_init_for_operation(&indexwriter, rebase->repo, &checkout_opts.checkout_strategy)) < 0 ||
(error = rebase_setupfile(rebase, MSGNUM_FILE, -1, "%d\n", rebase->current+1)) < 0 ||
@@ -960,7 +972,9 @@ int git_rebase_commit(
return error;
}
-int git_rebase_abort(git_rebase *rebase)
+int git_rebase_abort(
+ git_rebase *rebase,
+ const git_checkout_options *checkout_opts)
{
git_reference *orig_head_ref = NULL;
git_commit *orig_head_commit = NULL;
@@ -981,7 +995,7 @@ int git_rebase_abort(git_rebase *rebase)
if ((error = git_commit_lookup(
&orig_head_commit, rebase->repo, &rebase->orig_head_id)) < 0 ||
(error = git_reset(rebase->repo, (git_object *)orig_head_commit,
- GIT_RESET_HARD, NULL)) < 0)
+ GIT_RESET_HARD, checkout_opts)) < 0)
goto done;
error = rebase_cleanup(rebase);
diff --git a/tests/rebase/abort.c b/tests/rebase/abort.c
index 24af2d1..a04a34b 100644
--- a/tests/rebase/abort.c
+++ b/tests/rebase/abort.c
@@ -28,7 +28,7 @@ static void test_abort(git_annotated_commit *branch, git_annotated_commit *onto)
const git_reflog_entry *reflog_entry;
cl_git_pass(git_rebase_open(&rebase, repo));
- cl_git_pass(git_rebase_abort(rebase));
+ cl_git_pass(git_rebase_abort(rebase, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
@@ -73,7 +73,7 @@ void test_rebase_abort__merge(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
@@ -102,7 +102,7 @@ void test_rebase_abort__detached_head(void)
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
@@ -131,7 +131,7 @@ void test_rebase_abort__old_style_head_file(void)
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
p_rename("rebase-merge/.git/rebase-merge/orig-head",
diff --git a/tests/rebase/iterator.c b/tests/rebase/iterator.c
index 23272d5..d2f4278 100644
--- a/tests/rebase/iterator.c
+++ b/tests/rebase/iterator.c
@@ -64,7 +64,7 @@ void test_rebase_iterator__iterates(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
test_operations(rebase, GIT_REBASE_NO_OPERATION);
git_rebase_free(rebase);
diff --git a/tests/rebase/merge.c b/tests/rebase/merge.c
index 02c3960..ade6f5c 100644
--- a/tests/rebase/merge.c
+++ b/tests/rebase/merge.c
@@ -53,7 +53,7 @@ void test_rebase_merge__next(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
@@ -120,7 +120,7 @@ void test_rebase_merge__next_with_conflicts(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
@@ -167,7 +167,7 @@ void test_rebase_merge__next_stops_with_iterover(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
@@ -223,7 +223,7 @@ void test_rebase_merge__commit(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
@@ -316,7 +316,7 @@ void test_rebase_merge__commit_updates_rewritten(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
@@ -356,7 +356,7 @@ void test_rebase_merge__commit_drops_already_applied(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_fail(error = git_rebase_commit(&commit_id, rebase, NULL, signature,
@@ -399,7 +399,7 @@ void test_rebase_merge__finish(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
@@ -470,7 +470,7 @@ static void test_copy_note(
git_commit_id(branch_commit),
"This is a commit note.", 0));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, opts));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, opts, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
diff --git a/tests/rebase/setup.c b/tests/rebase/setup.c
index 627d3b9..61d8869 100644
--- a/tests/rebase/setup.c
+++ b/tests/rebase/setup.c
@@ -39,12 +39,12 @@ void test_rebase_setup__blocked_when_in_progress(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
git_rebase_free(rebase);
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
- cl_git_fail(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_fail(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
@@ -70,7 +70,7 @@ void test_rebase_setup__merge(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
@@ -118,7 +118,7 @@ void test_rebase_setup__merge_root(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL, NULL));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
@@ -168,7 +168,7 @@ void test_rebase_setup__merge_onto_and_upstream(void)
cl_git_pass(git_annotated_commit_from_ref(&branch2_head, repo, branch2_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch1_head, branch2_head, onto_head, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch1_head, branch2_head, onto_head, NULL, NULL));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
@@ -215,7 +215,7 @@ void test_rebase_setup__branch_with_merges(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
@@ -263,7 +263,7 @@ void test_rebase_setup__orphan_branch(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
@@ -314,7 +314,7 @@ void test_rebase_setup__merge_null_branch_uses_HEAD(void)
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- cl_git_pass(git_rebase_init(&rebase, repo, NULL, upstream_head, NULL, NULL));
+ cl_git_pass(git_rebase_init(&rebase, repo, NULL, upstream_head, NULL, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
@@ -358,7 +358,7 @@ static int rebase_is_blocked(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- error = git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL);
+ error = git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL, NULL);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);