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 * This example demonstrates the libgit2 push API to roughly 16 * simulate `git push`. 17 * 18 * This does not have: 19 * 20 * - Robust error handling 21 * - Any of the `git push` options 22 * 23 * This does have: 24 * 25 * - Example of push to origin/master 26 * 27 */ 28 module libgit2_d.example.push; 29 30 31 private static import core.stdc.stdio; 32 private static import libgit2_d.example.common; 33 private static import libgit2_d.remote; 34 private static import libgit2_d.strarray; 35 private static import libgit2_d.types; 36 37 package: 38 39 /** 40 * Entry point for this command 41 */ 42 extern (C) 43 nothrow @nogc 44 public int lg2_push(libgit2_d.types.git_repository* repo, int argc, char** argv) 45 46 do 47 { 48 /* Validate args */ 49 if (argc > 1) { 50 core.stdc.stdio.printf("USAGE: %s\n\nsorry, no arguments supported yet\n", argv[0]); 51 52 return -1; 53 } 54 55 libgit2_d.types.git_remote* remote = null; 56 libgit2_d.example.common.check_lg2(libgit2_d.remote.git_remote_lookup(&remote, repo, "origin"), "Unable to lookup remote", null); 57 58 libgit2_d.remote.git_push_options options; 59 libgit2_d.example.common.check_lg2(libgit2_d.remote.git_push_options_init(&options, libgit2_d.remote.GIT_PUSH_OPTIONS_VERSION), "Error initializing push", null); 60 61 const (char)* refspec = "refs/heads/master"; 62 const libgit2_d.strarray.git_strarray refspecs = {&refspec, 1}; 63 libgit2_d.example.common.check_lg2(libgit2_d.remote.git_remote_push(remote, &refspecs, &options), "Error pushing", null); 64 65 core.stdc.stdio.printf("pushed\n"); 66 67 return 0; 68 }