Class: Rugged::RemoteCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/rugged/rugged_remote_collection.c

Instance Method Summary collapse

Constructor Details

#new(repo) ⇒ Object

Creates and returns a new collection of remotes for the given repo.



22
23
24
25
26
# File 'ext/rugged/rugged_remote_collection.c', line 22

static VALUE rb_git_remote_collection_initialize(VALUE self, VALUE repo)
{
  rugged_set_owner(self, repo);
  return self;
}

Instance Method Details

#[](name) ⇒ nil

Lookup a remote in the collection with the given name.

Returns a new Rugged::Remote object or nil if the remote doesn’t exist.

@repo.remotes["origin"] #=> #<Rugged::Remote:0x00000001fbfa80>

Returns:

  • (nil)


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'ext/rugged/rugged_remote_collection.c', line 110

static VALUE rb_git_remote_collection_aref(VALUE self, VALUE rb_name)
{
  git_remote *remote;
  git_repository *repo;
  int error;

  VALUE rb_repo = rugged_owner(self);
  rugged_check_repo(rb_repo);
  Data_Get_Struct(rb_repo, git_repository, repo);

  Check_Type(rb_name, T_STRING);

  error = git_remote_lookup(&remote, repo, StringValueCStr(rb_name));

  if (error == GIT_ENOTFOUND)
    return Qnil;

  rugged_exception_check(error);

  return rugged_remote_new(rb_repo, remote);
}

#add_fetch_refspec(remote, refspec) ⇒ nil #add_fetch_refspec(name, refspec) ⇒ nil

Add a fetch refspec to the remote.

Overloads:

  • #add_fetch_refspec(remote, refspec) ⇒ nil

    Returns:

    • (nil)
  • #add_fetch_refspec(name, refspec) ⇒ nil

    Returns:

    • (nil)


395
396
397
398
# File 'ext/rugged/rugged_remote_collection.c', line 395

static VALUE rb_git_remote_collection_add_fetch_refspec(VALUE self, VALUE rb_name_or_remote, VALUE rb_refspec)
{
  return rb_git_remote_collection_add_refspec(self, rb_name_or_remote, rb_refspec, GIT_DIRECTION_FETCH);
}

#add_push_refspec(remote, refspec) ⇒ nil #add_push_refspec(name, refspec) ⇒ nil

Add a push refspec to the remote.

Overloads:

  • #add_push_refspec(remote, refspec) ⇒ nil

    Returns:

    • (nil)
  • #add_push_refspec(name, refspec) ⇒ nil

    Returns:

    • (nil)


407
408
409
410
# File 'ext/rugged/rugged_remote_collection.c', line 407

static VALUE rb_git_remote_collection_add_push_refspec(VALUE self, VALUE rb_name_or_remote, VALUE rb_refspec)
{
  return rb_git_remote_collection_add_refspec(self, rb_name_or_remote, rb_refspec, GIT_DIRECTION_PUSH);
}

#create(name, url) ⇒ Object

Add a new remote with name and url to repository

  • url: a valid remote url

  • name: a valid remote name

Returns a new Rugged::Remote object.

@repo.remotes.create('origin', 'git://github.com/libgit2/rugged.git') #=> #<Rugged::Remote:0x00000001fbfa80>


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'ext/rugged/rugged_remote_collection.c', line 74

static VALUE rb_git_remote_collection_create(VALUE self, VALUE rb_name, VALUE rb_url)
{
  git_remote *remote;
  git_repository *repo;
  int error;

  VALUE rb_repo = rugged_owner(self);

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

  Check_Type(rb_name, T_STRING);
  Check_Type(rb_url, T_STRING);

  error = git_remote_create(
      &remote,
      repo,
      StringValueCStr(rb_name),
      StringValueCStr(rb_url));

  rugged_exception_check(error);

  return rugged_remote_new(rb_repo, remote);
}

#create_anonymous(url) ⇒ Object

Return a new remote with url in repository , the remote is not persisted:

  • url: a valid remote url

Returns a new Rugged::Remote object.

@repo.remotes.create_anonymous('git://github.com/libgit2/libgit2.git') #=> #<Rugged::Remote:0x00000001fbfa80>


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'ext/rugged/rugged_remote_collection.c', line 39

static VALUE rb_git_remote_collection_create_anonymous(VALUE self, VALUE rb_url)
{
  git_remote *remote;
  git_repository *repo;
  int error;

  VALUE rb_repo = rugged_owner(self);

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

  Check_Type(rb_url, T_STRING);

  error = git_remote_create_anonymous(
      &remote,
      repo,
      StringValueCStr(rb_url));

  rugged_exception_check(error);

  return rugged_remote_new(rb_repo, remote);
}

#delete(remote) ⇒ nil #delete(name) ⇒ nil

Delete the specified remote.

repo.remotes.delete("origin")
# Remote no longer exists in the configuration.

Overloads:

  • #delete(remote) ⇒ nil

    Returns:

    • (nil)
  • #delete(name) ⇒ nil

    Returns:

    • (nil)


274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'ext/rugged/rugged_remote_collection.c', line 274

static VALUE rb_git_remote_collection_delete(VALUE self, VALUE rb_name_or_remote)
{
  VALUE rb_repo = rugged_owner(self);
  git_repository *repo;

  if (rb_obj_is_kind_of(rb_name_or_remote, rb_cRuggedRemote))
    rb_name_or_remote = rb_funcall(rb_name_or_remote, rb_intern("name"), 0);

  if (TYPE(rb_name_or_remote) != T_STRING)
    rb_raise(rb_eTypeError, "Expecting a String or Rugged::Remote instance");

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

  rugged_exception_check(
    git_remote_delete(repo, StringValueCStr(rb_name_or_remote))
  );

  return Qnil;
}

#each {|remote| ... } ⇒ nil #eachObject

Iterate through all the remotes in the collection’s repository.

The given block will be called once with a Rugged::Remote instance for each remote.

If no block is given, an enumerator will be returned.

Overloads:

  • #each {|remote| ... } ⇒ nil

    Yields:

    • (remote)

    Returns:

    • (nil)


187
188
189
190
# File 'ext/rugged/rugged_remote_collection.c', line 187

static VALUE rb_git_remote_collection_each(VALUE self)
{
  return rb_git_remote_collection__each(self, 0);
}

#each_name {|str| ... } ⇒ nil #each_nameObject

Iterate through all the remote names in the collection’s repository.

The given block will be called once with the name of each remote.

If no block is given, an enumerator will be returned.

Overloads:

  • #each_name {|str| ... } ⇒ nil

    Yields:

    • (str)

    Returns:

    • (nil)


203
204
205
206
# File 'ext/rugged/rugged_remote_collection.c', line 203

static VALUE rb_git_remote_collection_each_name(VALUE self)
{
  return rb_git_remote_collection__each(self, 1);
}

#rename(remote, new_name) {|str| ... } ⇒ Object #rename(name, new_name) {|str| ... } ⇒ Object

Renames a remote.

All remote-tracking branches and configuration settings for the remote are updated.

Non-default refspecs cannot be renamed automatically and will be yielded to the given block.

Anonymous, in-memory remotes created through ReferenceCollection#create_anonymous can not be given a name through this method.

Returns a new Rugged::Remote object with the new name.

Overloads:

  • #rename(remote, new_name) {|str| ... } ⇒ Object

    Yields:

    • (str)
  • #rename(name, new_name) {|str| ... } ⇒ Object

    Yields:

    • (str)


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

static VALUE rb_git_remote_collection_rename(VALUE self, VALUE rb_name_or_remote, VALUE rb_new_name)
{
  VALUE rb_repo = rugged_owner(self);
  git_repository *repo;
  size_t i;
  int error, exception;
  git_strarray problems;

  if (!rb_block_given_p())
    rb_raise(rb_eArgError, "Rugged::RemoteCollection#rename must be called with a block");

  Check_Type(rb_new_name, T_STRING);

  if (rb_obj_is_kind_of(rb_name_or_remote, rb_cRuggedRemote))
    rb_name_or_remote = rb_funcall(rb_name_or_remote, rb_intern("name"), 0);

  if (TYPE(rb_name_or_remote) != T_STRING)
    rb_raise(rb_eTypeError, "Expecting a String or Rugged::Remote instance");

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

  error = git_remote_rename(&problems, repo, StringValueCStr(rb_name_or_remote), StringValueCStr(rb_new_name));
  rugged_exception_check(error);

  for (i = exception = 0; !exception && i < problems.count; ++i) {
    rb_protect(rb_yield, rb_str_new_utf8(problems.strings[i]), &exception);
  }

  git_strarray_free(&problems);

  if (exception)
    rb_jump_tag(exception);

  return rb_git_remote_collection_aref(self, rb_new_name);
}

#set_push_url(remote, url) ⇒ nil #set_push_url(name, url) ⇒ nil

Sets the remote’s url for pushing in the configuration. Rugged::Remote objects already in memory will not be affected.

repo.remotes.set_push_url("origin", 'git://github.com/libgit2/rugged.git')

Overloads:

  • #set_push_url(remote, url) ⇒ nil

    Returns:

    • (nil)
  • #set_push_url(name, url) ⇒ nil

    Returns:

    • (nil)


338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'ext/rugged/rugged_remote_collection.c', line 338

static VALUE rb_git_remote_collection_set_push_url(VALUE self, VALUE rb_name_or_remote, VALUE rb_url)
{
  VALUE rb_repo = rugged_owner(self);
  git_repository *repo;

  if (rb_obj_is_kind_of(rb_name_or_remote, rb_cRuggedRemote))
    rb_name_or_remote = rb_funcall(rb_name_or_remote, rb_intern("name"), 0);

  if (TYPE(rb_name_or_remote) != T_STRING)
    rb_raise(rb_eTypeError, "Expecting a String or Rugged::Remote instance");

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

  Check_Type(rb_url, T_STRING);

  rugged_exception_check(
    git_remote_set_pushurl(repo, StringValueCStr(rb_name_or_remote), StringValueCStr(rb_url))
  );

  return Qnil;
}

#set_url(remote, url) ⇒ nil #set_url(name, url) ⇒ nil

Sets the remote’s url in the configuration. Rugged::Remote objects already in memory will not be affected.

repo.remotes.set_url("origin", 'git://github.com/libgit2/rugged.git')

Overloads:

  • #set_url(remote, url) ⇒ nil

    Returns:

    • (nil)
  • #set_url(name, url) ⇒ nil

    Returns:

    • (nil)


305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'ext/rugged/rugged_remote_collection.c', line 305

static VALUE rb_git_remote_collection_set_url(VALUE self, VALUE rb_name_or_remote, VALUE rb_url)
{
  VALUE rb_repo = rugged_owner(self);
  git_repository *repo;

  if (rb_obj_is_kind_of(rb_name_or_remote, rb_cRuggedRemote))
    rb_name_or_remote = rb_funcall(rb_name_or_remote, rb_intern("name"), 0);

  if (TYPE(rb_name_or_remote) != T_STRING)
    rb_raise(rb_eTypeError, "Expecting a String or Rugged::Remote instance");

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

  Check_Type(rb_url, T_STRING);

  rugged_exception_check(
    git_remote_set_url(repo, StringValueCStr(rb_name_or_remote), StringValueCStr(rb_url))
  );

  return Qnil;
}