Class: Rugged::Remote

Inherits:
Object
  • Object
show all
Defined in:
ext/rugged/remote.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*args) ⇒ Object



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

static VALUE rb_git_remote__new(int argc, VALUE *argv, VALUE klass)
{
	VALUE rb_remote, rb_repo, rb_url, rb_name;
	git_remote *remote;
	git_repository *repo;
	const char *url;
	int error;

	rb_scan_args(argc, argv, "21", &rb_repo, &rb_url, &rb_name);

	Check_Type(rb_url, T_STRING);

	if (!rb_obj_is_instance_of(rb_repo, rb_cRuggedRepo))
		rb_raise(rb_eTypeError, "Expecting a Rugged Repository");

	Data_Get_Struct(rb_repo, git_repository, repo);

	url = StringValueCStr(rb_url);

	if (git_remote_valid_url(url)) {
		if (!NIL_P(rb_name))
			Check_Type(rb_name, T_STRING);

		error = git_remote_new(
			&remote,
			repo,
			StringValueCStr(rb_url),
			NIL_P(rb_name) ? NULL : StringValueCStr(rb_name)
		);
	} else {
		error = git_remote_load(&remote, repo, url);
	}

	rugged_exception_check(error);

	rb_remote = Data_Wrap_Struct(klass, NULL, &rb_git_remote__free, remote);
	rugged_set_owner(rb_remote, rb_repo);
	return rb_remote;
}

Instance Method Details

#connect(rb_direction) ⇒ Object



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

static VALUE rb_git_remote_connect(VALUE self, VALUE rb_direction)
{
	int error, direction = 0;
	git_remote *remote;
	ID id_direction;

	Data_Get_Struct(self, git_remote, remote);

	Check_Type(rb_direction, T_SYMBOL);
	id_direction = SYM2ID(rb_direction);

	if (id_direction == rb_intern("fetch"))
		direction = GIT_DIR_FETCH;
	else if (id_direction == rb_intern("push"))
		direction = GIT_DIR_PUSH;
	else
		rb_raise(rb_eTypeError,
			"Invalid remote direction. Expected `:fetch` or `:push`");

	error = git_remote_connect(remote, direction);
	rugged_exception_check(error);

	if (rb_block_given_p())
		rb_ensure(rb_yield, self, rb_git_remote_disconnect, self);

	return Qnil;
}

#connected?Boolean

Returns:

  • (Boolean)


162
163
164
165
166
167
168
# File 'ext/rugged/remote.c', line 162

static VALUE rb_git_remote_connected(VALUE self)
{
	git_remote *remote;
	Data_Get_Struct(self, git_remote, remote);

	return git_remote_connected(remote) ? Qtrue : Qfalse;
}

#disconnectObject



76
77
78
79
80
81
82
83
# File 'ext/rugged/remote.c', line 76

static VALUE rb_git_remote_disconnect(VALUE self)
{
	git_remote *remote;
	Data_Get_Struct(self, git_remote, remote);

	git_remote_disconnect(remote);
	return Qnil;
}

#downloadObject



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'ext/rugged/remote.c', line 170

static VALUE rb_git_remote_download(VALUE self)
{
	int error;
	git_remote *remote;
	char *path;
	VALUE rb_path;

	Data_Get_Struct(self, git_remote, remote);

	error = git_remote_download(&path, remote);
	rugged_exception_check(error);

	rb_path = rugged_str_new2(path, NULL);
	free(path);

	return rb_path;
}

#lsObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'ext/rugged/remote.c', line 131

static VALUE rb_git_remote_ls(VALUE self)
{
	int error;
	git_remote *remote;
	Data_Get_Struct(self, git_remote, remote);

	if (!rb_block_given_p())
		return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("ls"));

	error = git_remote_ls(remote, &cb_remote__ls, (void *)rb_block_proc());
	rugged_exception_check(error);

	return Qnil;
}

#nameObject



146
147
148
149
150
151
152
# File 'ext/rugged/remote.c', line 146

static VALUE rb_git_remote_name(VALUE self)
{
	git_remote *remote;
	Data_Get_Struct(self, git_remote, remote);

	return rugged_str_new2(git_remote_name(remote), NULL);
}

#update_tips!Object



188
189
190
191
192
193
194
195
196
197
198
199
# File 'ext/rugged/remote.c', line 188

static VALUE rb_git_remote_update_tips(VALUE self)
{
	int error;
	git_remote *remote;

	Data_Get_Struct(self, git_remote, remote);

	error = git_remote_update_tips(remote);
	rugged_exception_check(error);

	return Qnil;
}

#urlObject



154
155
156
157
158
159
160
# File 'ext/rugged/remote.c', line 154

static VALUE rb_git_remote_url(VALUE self)
{
	git_remote *remote;
	Data_Get_Struct(self, git_remote, remote);

	return rugged_str_new2(git_remote_url(remote), NULL);
}