1 /*
2 * libgit2 "push" example - shows how to push to remote
3 *
4 * Written by the libgit2 contributors
5 *
6 * To the extent possible under law, the author(s) have dedicated all copyright
7 * and related and neighboring rights to this software to the public domain
8 * worldwide. This software is distributed without any warranty.
9 *
10 * You should have received a copy of the CC0 Public Domain Dedication along
11 * with this software. If not, see
12 * <http://creativecommons.org/publicdomain/zero/1.0/>.
13 */
14
15 #include "common.h"
16
17 /**
18 * This example demonstrates the libgit2 push API to roughly
19 * simulate `git push`.
20 *
21 * This does not have:
22 *
23 * - Robust error handling
24 * - Any of the `git push` options
25 *
26 * This does have:
27 *
28 * - Example of push to origin/master
29 *
30 */
31
32 /** Entry point for this command */
lg2_push(git_repository * repo,int argc,char ** argv)33 int lg2_push(git_repository *repo, int argc, char **argv) {
34 git_push_options options;
35 git_remote* remote = NULL;
36 char *refspec = "refs/heads/master";
37 const git_strarray refspecs = {
38 &refspec,
39 1
40 };
41
42 /* Validate args */
43 if (argc > 1) {
44 printf ("USAGE: %s\n\nsorry, no arguments supported yet\n", argv[0]);
45 return -1;
46 }
47
48 check_lg2(git_remote_lookup(&remote, repo, "origin" ), "Unable to lookup remote", NULL);
49
50 check_lg2(git_push_options_init(&options, GIT_PUSH_OPTIONS_VERSION ), "Error initializing push", NULL);
51
52 check_lg2(git_remote_push(remote, &refspecs, &options), "Error pushing", NULL);
53
54 printf("pushed\n");
55 return 0;
56 }
57