Class: Rugged::Rebase
- Inherits:
-
Object
- Object
- Rugged::Rebase
- Defined in:
- ext/rugged/rugged_rebase.c
Class Method Summary collapse
-
.new(repo, branch, upstream[, onto][, options]) ⇒ Object
Initialize a new rebase operation.
Instance Method Summary collapse
-
#abort ⇒ nil
Abort the rebase currently in process, resetting the repository and working directory to their state before the rebase began.
-
#commit(author: nil, committer: committer, message: nil) ⇒ nil
Commit the current patch.
-
#finish ⇒ nil
Finish the rebase currently in progress once all patches have been applied.
-
#inmemory_index ⇒ Object
Gets the index produced by the last operation, which is the result of
nextand which will be committed by the next invocation ofcommit. -
#next ⇒ nil
Perform the next step in the rebase.
Class Method Details
.new(repo, branch, upstream[, onto][, options]) ⇒ Object
Initialize a new rebase operation. This will put repo in a
rebase state.
branch is the branch to be rebased, and upstream is the branch
which is to be the new base. If onto is specified, this will be
the one base, and upstream is used to determine which commits
from branch to use for the rebase.
You can pass merge and checkout options for the options hash, plus a few rebase-specific ones:
:quiet ::
If true, a flag will be set to ask tools to activate quiet
mode. This does not do anything for libgit2/rugged but can be
used to interact with other implementations.
:inmemory ::
Do not put the repository in a rebase state but perform all the
operations in-memory. In case of conflicts, the rebase operation
Hash returned by #next will contain the index which can be used to
resolve conflicts.
:rewrite_notes_ref ::
Name of the notes reference used to rewrite notes for rebased
commits when finishing the rebase. If +nil+, it will be taken
from the configuration.
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 |
# File 'ext/rugged/rugged_rebase.c', line 157
static VALUE rb_git_rebase_new(int argc, VALUE* argv, VALUE klass)
{
int error = 0, exception = 0;
git_rebase *rebase = NULL;
git_repository *repo;
git_annotated_commit *branch = NULL, *upstream = NULL, *onto = NULL;
VALUE rb_repo, rb_branch, rb_upstream, rb_onto, rb_options;
git_rebase_options options = GIT_REBASE_OPTIONS_INIT;
rb_scan_args(argc, argv, "31:", &rb_repo, &rb_branch, &rb_upstream, &rb_onto, &rb_options);
TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
if ((exception = rugged_get_annotated_commit(&branch, rb_repo, rb_branch)))
goto cleanup;
if ((exception = rugged_get_annotated_commit(&upstream, rb_repo, rb_upstream)))
goto cleanup;
if (!NIL_P(rb_onto)) {
if ((exception = rugged_get_annotated_commit(&onto, rb_repo, rb_onto)))
goto cleanup;
}
parse_rebase_options(&options, rb_options);
error = git_rebase_init(&rebase, repo, branch, upstream, onto, &options);
cleanup:
git_annotated_commit_free(branch);
git_annotated_commit_free(upstream);
git_annotated_commit_free(onto);
if (exception)
rb_jump_tag(exception);
rugged_exception_check(error);
return rugged_rebase_new(klass, rb_repo, rebase);
}
|
Instance Method Details
#abort ⇒ nil
Abort the rebase currently in process, resetting the repository and working directory to their state before the rebase began.
337 338 339 340 341 342 343 344 345 |
# File 'ext/rugged/rugged_rebase.c', line 337
static VALUE rb_git_rebase_abort(VALUE self)
{
git_rebase *rebase;
TypedData_Get_Struct(self, git_rebase, &rugged_rebase_type, rebase);
rugged_exception_check(git_rebase_abort(rebase));
return Qnil;
}
|
#commit(author: nil, committer: committer, message: nil) ⇒ nil
Commit the current patch. Any conflicts must have been resolved.
If author is nil, the existing author for the commit will be
used. If message is nil, the existing message will be used.
Returns a string containing the oid of the newly created commit,
or nil if there are no changes to be committed.
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 |
# File 'ext/rugged/rugged_rebase.c', line 285
static VALUE rb_git_rebase_commit(int argc, VALUE *argv, VALUE self)
{
int error;
git_oid id;
git_rebase *rebase;
git_signature *author = NULL, *committer;
const char *message = NULL;
VALUE rb_options, rb_author, rb_committer, rb_message;
TypedData_Get_Struct(self, git_rebase, &rugged_rebase_type, rebase);
rb_scan_args(argc, argv, ":", &rb_options);
Check_Type(rb_options, T_HASH);
rb_author = rb_hash_aref(rb_options, CSTR2SYM("author"));
rb_committer = rb_hash_aref(rb_options, CSTR2SYM("committer"));
rb_message = rb_hash_aref(rb_options, CSTR2SYM("message"));
if (!NIL_P(rb_message)) {
Check_Type(rb_message, T_STRING);
message = StringValueCStr(rb_message);
}
if (NIL_P(rb_committer))
rb_raise(rb_eArgError, "Expected non-nil committer");
else
committer = rugged_signature_get(rb_committer, NULL);
if (!NIL_P(rb_author))
author = rugged_signature_get(rb_author, NULL);
error = git_rebase_commit(&id, rebase, author, committer, NULL, message);
git_signature_free(author);
git_signature_free(committer);
if (error == GIT_EAPPLIED) {
giterr_clear();
return Qnil;
}
rugged_exception_check(error);
return rugged_create_oid(&id);
}
|
#finish ⇒ nil
Finish the rebase currently in progress once all patches have been applied.
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'ext/rugged/rugged_rebase.c', line 354
static VALUE rb_git_rebase_finish(VALUE self, VALUE rb_sig)
{
git_rebase *rebase;
git_signature *sig;
int error;
TypedData_Get_Struct(self, git_rebase, &rugged_rebase_type, rebase);
sig = rugged_signature_get(rb_sig, NULL);
error = git_rebase_finish(rebase, sig);
git_signature_free(sig);
rugged_exception_check(error);
return Qnil;
}
|
#inmemory_index ⇒ Object
Gets the index produced by the last operation, which is the result
of next and which will be committed by the next invocation of
commit. This is useful for resolving conflicts in an in-memory
rebase before committing them.
This is only applicable for in-memory rebases; for rebases within a working directory, the changes were applied to the repository's index.
262 263 264 265 266 267 268 269 270 271 |
# File 'ext/rugged/rugged_rebase.c', line 262
static VALUE rb_git_rebase_inmemory_index(VALUE self)
{
git_rebase *rebase;
git_index *index;
TypedData_Get_Struct(self, git_rebase, &rugged_rebase_type, rebase);
rugged_exception_check(git_rebase_inmemory_index(&index, rebase));
return rugged_index_new(rb_cRuggedIndex, self, index);
}
|
#next ⇒ nil
Perform the next step in the rebase. The returned operation is a Hash with its details or nil if there are no more operations to perform. The Hash contains some of the following entries:
:type ::
The type of operation being done. Can be one of +:pick+,
+:reword+, +:edit+, +:squash+, +:fixup+ or +:exec+.
:id ::
The id of the commit being cherry-picked. Exists for all but
+:exec+ operations.
:exec ::
If the operatin is +:exec+ this is what the user asked to be
executed.
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 |
# File 'ext/rugged/rugged_rebase.c', line 217
static VALUE rb_git_rebase_next(VALUE self)
{
int error;
git_rebase *rebase;
git_rebase_operation *operation;
VALUE hash, val;
TypedData_Get_Struct(self, git_rebase, &rugged_rebase_type, rebase);
error = git_rebase_next(&operation, rebase);
if (error == GIT_ITEROVER)
return Qnil;
rugged_exception_check(error);
/* Create the operation hash out of the relevant details */
hash = rb_hash_new();
val = rebase_operation_type(operation);
rb_hash_aset(hash, CSTR2SYM("type"), val);
if (operation->type != GIT_REBASE_OPERATION_EXEC) {
val = rugged_create_oid(&operation->id);
rb_hash_aset(hash, CSTR2SYM("id"), val);
}
if (operation->exec) {
val = rb_str_new_utf8(operation->exec);
rb_hash_aset(hash, CSTR2SYM("exec"), val);
}
return hash;
}
|