3 static int use_remote(git_repository
*repo
, char *name
)
5 git_remote
*remote
= NULL
;
7 const git_remote_head
**refs
;
9 git_remote_callbacks callbacks
= GIT_REMOTE_CALLBACKS_INIT
;
11 /* Find the remote by name */
12 error
= git_remote_lookup(&remote
, repo
, name
);
14 error
= git_remote_create_anonymous(&remote
, repo
, name
);
20 * Connect to the remote and call the printing function for
21 * each of the remote references.
23 callbacks
.credentials
= cred_acquire_cb
;
25 error
= git_remote_connect(remote
, GIT_DIRECTION_FETCH
, &callbacks
, NULL
, NULL
);
30 * Get the list of references on the remote and print out
31 * their name next to what they point to.
33 if (git_remote_ls(&refs
, &refs_len
, remote
) < 0)
36 for (i
= 0; i
< refs_len
; i
++) {
37 char oid
[GIT_OID_HEXSZ
+ 1] = {0};
38 git_oid_fmt(oid
, &refs
[i
]->oid
);
39 printf("%s\t%s\n", oid
, refs
[i
]->name
);
43 git_remote_free(remote
);
47 /** Entry point for this command */
48 int lg2_ls_remote(git_repository
*repo
, int argc
, char **argv
)
53 fprintf(stderr
, "usage: %s ls-remote <remote>\n", argv
[-1]);
57 error
= use_remote(repo
, argv
[1]);