Permalink
Browse files

Add a API to work with remotes

Create remote, getters and setters for url, pushurl work for now
  • Loading branch information...
sa1 committed Sep 7, 2013
1 parent bc6b3da commit 9e39a10839f824d8cee8d83242a035059e55a22e
Showing with 102 additions and 1 deletion.
  1. +1 −0 setup.winxed
  2. +56 −0 src/Git2/Remote.winxed
  3. +16 −0 src/parrotgit.c
  4. +2 −1 src/parrotgit.nci
  5. +2 −0 src/parrotgit.pir
  6. +25 −0 t/winxed/001_load.t
View
@@ -54,6 +54,7 @@ function setup_stable_libraries(var parrot_libgit2) {
'RefCache',
'AttrCache',
'Repository',
+ 'Remote',
'RevWalk'
];
View
@@ -0,0 +1,56 @@
+$include_const 'datatypes.pasm';
+$include_const "iglobals.pasm";
+
+namespace Git2{
+ class Common;
+}
+
+namespace Git2{
+ class Remote {
+ var ptr;
+ function Remote(){
+ }
+ function create_remote(repo, name, url){
+ using Git2.Git.remote_create;
+ self.ptr = remote_create(repo.ptr, cstring(name), cstring(url));
+ }
+ //TODO: convert to Parrot string
+ function url(){
+ using Git2.Raw.git_remote_url;
+ var j = git_remote_url(self.ptr);
+ return j;
+ }
+ /*
+ * 1 if valid, 0 if invalid
+ */
+ function valid_url(url){
+ using Git2.Raw.git_remote_valid_url;
+ using cstring;
+ int j = git_remote_valid_url(cstring(url));
+ return j;
+ }
+ /*
+ * 0 or error value
+ */
+ function set_url(url){
+ using Git2.Raw.git_remote_set_url;
+ using cstring;
+ int j = git_remote_set_url(self.ptr, cstring(url));
+ return j;
+ }
+ function pushurl(){
+ using Git2.Raw.git_remote_pushurl;
+ var pushurl = git_remote_pushurl(self.ptr);
+ return pushurl;
+ }
+ function set_pushurl(url){
+ using Git2.Raw.git_remote_set_pushurl;
+ using cstring;
+ int j = git_remote_set_pushurl(self.ptr, cstring(url));
+ }
+ function free(){
+ using Git2.Raw.git_remote_free;
+ git_remote_free(self.ptr);
+ }
+ }
+}
View
@@ -103,3 +103,19 @@ int get_config_int32(git_config * config, char * cfg_variable){
git_config_get_int32(&j, config, cfg_variable);
return j;
}
+
+git_remote * remote_create(git_repository *repo, char *name, char * url){
+ git_remote * remote;
+ int ret;
+ ret = git_remote_create(&remote, repo, name, url);
+ if (ret == GIT_EINVALIDSPEC){
+ fprintf(stderr, "Invalid spec\n");
+ }
+ else if (ret == GIT_EEXISTS){
+ fprintf(stderr, "Remote Exists");
+ }
+ else if (ret < 0){
+ fprintf(stderr, "Error creating remote");
+ }
+ return remote;
+}
View
@@ -17,4 +17,5 @@ i get_config_int32 pp
p commit_lookup pp
p parent pi
p new_revwalk p
-p blob_lookup pp
+p blob_lookup pp
+p remote_create ppp
View
@@ -25,4 +25,6 @@
set_global ['Git2';'Git'], 'new_revwalk', nci
dlfunc nci, lib, 'blob_lookup', 'ppp'
set_global ['Git2';'Git'], 'blob_lookup', nci
+ dlfunc nci, lib, 'remote_create', 'pppp'
+ set_global ['Git2';'Git'], 'remote_create', nci
.end
View
@@ -14,10 +14,12 @@ $load "./src/Git2/RevWalk.pbc";
$load "./src/Git2/Odb.pbc";
$load "./src/Git2/AttrCache.pbc";
$load "./src/Git2/Blob.pbc";
+$load "./src/Git2/Remote.pbc";
$load "dumper.pbc";
$include_const 'datatypes.pasm';
$include_const "iglobals.pasm";
+$loadlib "io_ops";
namespace Git2 {
class Repository;
@@ -28,6 +30,7 @@ namespace Git2 {
class Commit;
class Oid;
class RevWalk;
+ class Remote;
class Blob;
}
@@ -219,6 +222,28 @@ class Test_git2_repository_open {
blob.free();
repo.free();
}
+
+ function remote(){
+ using Git2.Remote;
+ using Git2.Repository;
+
+ var repo = new Git2.Repository(".");
+ var remote = new Git2.Remote;
+ remote.create_remote(repo, "Test_Remote", "http://testremote/remote.git");
+
+ var url = "http://testurl/url.git";
+ int valid = remote.valid_url(url);
+ self.assert.equal(valid, 1);
+
+ int i = remote.set_url(url);
+ self.assert.equal(i, 0);
+
+ remote.free();
+ //TODO: do this using libgit2. Doesn't seem possible yet.
+ string cmd = "git remote rm Test_Remote";
+ int result;
+ ${spawnw result, cmd};
+ }
}
function main[main]() {
using Rosella.Test.test;

0 comments on commit 9e39a10

Please sign in to comment.