Method: Rugged::BranchCollection#move

Defined in:
ext/rugged/rugged_branch_collection.c

#move(old_name, new_name, options = {}) ⇒ Object #move(branch, new_name, options = {}) ⇒ Object #rename(old_name, new_name, options = {}) ⇒ Object #rename(branch, new_name, options = {}) ⇒ Object

Rename a branch to new_name.

new_name needs to be a branch name, not an absolute reference path (e.g. development instead of refs/heads/development).

The following options can be passed in the options Hash:

:force

Overwrites the branch with the given name, if it already exists, instead of raising an exception.

If a branch with the given new_name already exists and :force is not true, an exception will be raised.

A new Rugged::Branch object for the renamed branch will be returned.



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
# File 'ext/rugged/rugged_branch_collection.c', line 312

static VALUE rb_git_branch_collection_move(int argc, VALUE *argv, VALUE self)
{
  VALUE rb_repo = rugged_owner(self), rb_name_or_branch, rb_new_branch_name, rb_options;
  git_reference *old_branch = NULL, *new_branch = NULL;
  git_repository *repo;
  int error, force = 0;

  rb_scan_args(argc, argv, "20:", &rb_name_or_branch, &rb_new_branch_name, &rb_options);
  Check_Type(rb_new_branch_name, T_STRING);

  rugged_check_repo(rb_repo);
  Data_Get_Struct(rb_repo, git_repository, repo);

  error = rugged_branch_lookup(&old_branch, repo, rb_name_or_branch);
  rugged_exception_check(error);

  if (!NIL_P(rb_options)) {
    force = RTEST(rb_hash_aref(rb_options, CSTR2SYM("force")));
  }

  error = git_branch_move(&new_branch, old_branch, StringValueCStr(rb_new_branch_name), force);

  git_reference_free(old_branch);

  rugged_exception_check(error);

  return rugged_branch_new(rugged_owner(self), new_branch);
}