Skip to content

Commit 3ff92e4

Browse files
committed
added Git2\Repository::clone()
1 parent 0f55800 commit 3ff92e4

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

git2_repository.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ static PHP_METHOD(Repository, init_ext) {
106106
zval *data;
107107
git2_repository_object_t *intern;
108108

109-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sh", &path, &path_len, &opts) == FAILURE) {
110-
RETURN_FALSE;
111-
}
109+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sh", &path, &path_len, &opts) == FAILURE)
110+
return;
112111

113112
git_repository_init_options opts_libgit2 = GIT_REPOSITORY_INIT_OPTIONS_INIT;
114113
if ((data = zend_hash_str_find(opts, ZEND_STRL("flags"))) != NULL) {
@@ -134,6 +133,46 @@ static PHP_METHOD(Repository, init_ext) {
134133
}
135134
}
136135

136+
ZEND_BEGIN_ARG_INFO_EX(arginfo_repository_clone, 0, 0, 2)
137+
ZEND_ARG_INFO(0, url)
138+
ZEND_ARG_INFO(0, local_path)
139+
ZEND_ARG_INFO(0, options)
140+
ZEND_END_ARG_INFO()
141+
142+
static PHP_METHOD(Repository, clone) {
143+
char *url, *local_path;
144+
size_t url_len, local_path_len;
145+
zval *data;
146+
HashTable *opts = NULL;
147+
git2_repository_object_t *intern;
148+
git_clone_options opts_libgit2 = GIT_CLONE_OPTIONS_INIT;
149+
150+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssh", &url, &url_len, &local_path, &local_path_len, &opts) == FAILURE)
151+
return;
152+
153+
if (opts != NULL) {
154+
// TODO hnadle options
155+
if ((data = zend_hash_str_find(opts, ZEND_STRL("bare"))) != NULL) {
156+
convert_to_bool(data);
157+
opts_libgit2.bare = Z_BVAL_P(data);
158+
}
159+
if ((data = zend_hash_str_find(opts, ZEND_STRL("checkout_branch"))) != NULL) {
160+
convert_to_string(data);
161+
opts_libgit2.checkout_branch = Z_STRVAL_P(data);
162+
}
163+
}
164+
165+
object_init_ex(return_value, php_git2_repository_ce);
166+
intern = (git2_repository_object_t*)Z_OBJ_P(return_value);
167+
168+
int res = git_clone(&intern->repo, url, local_path, &opts_libgit2);
169+
170+
if (res != 0) {
171+
git2_throw_last_error(TSRMLS_C);
172+
return;
173+
}
174+
}
175+
137176
#define GIT2_REPOSITORY_FETCH() git2_repository_object_t *intern = (git2_repository_object_t*)Z_OBJ_P(getThis()); \
138177
if (intern->repo == NULL) { \
139178
git2_throw_exception(0 TSRMLS_CC, "Git2\\Repository object in invalid state"); \
@@ -300,6 +339,7 @@ static zend_function_entry git2_repository_methods[] = {
300339
PHP_ME(Repository, open_bare, arginfo_repository_open_bare, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
301340
PHP_ME(Repository, init, arginfo_repository_init, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
302341
PHP_ME(Repository, init_ext, arginfo_repository_init_ext, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
342+
PHP_ME(Repository, clone, arginfo_repository_clone, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
303343
PHP_ME(Repository, config, arginfo_repository_config, ZEND_ACC_PUBLIC)
304344
PHP_ME(Repository, head, arginfo_repository_head, ZEND_ACC_PUBLIC)
305345
PHP_ME(Repository, set_head, arginfo_repository_set_head, ZEND_ACC_PUBLIC)

0 commit comments

Comments
 (0)