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.


39
40
41
42
43
# File 'ext/rugged/rugged_remote_collection.c', line 39

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)

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'ext/rugged/rugged_remote_collection.c', line 131

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_load(&remote, repo, StringValueCStr(rb_name));

	if (error == GIT_ENOTFOUND)
		return Qnil;

	rugged_exception_check(error);

	return rugged_remote_new(rb_repo, remote);
}

#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>

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

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);
	rugged_validate_remote_url(rb_url);

	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>

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'ext/rugged/rugged_remote_collection.c', line 56

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);
	rugged_validate_remote_url(rb_url);

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

	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)

244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'ext/rugged/rugged_remote_collection.c', line 244

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

	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_load(&remote, repo, StringValueCStr(rb_name_or_remote));
	rugged_exception_check(error);

	error = git_remote_delete(remote);
	rugged_exception_check(error);

	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)

213
214
215
216
# File 'ext/rugged/rugged_remote_collection.c', line 213

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)

229
230
231
232
# File 'ext/rugged/rugged_remote_collection.c', line 229

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