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 * <https://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 * License: $(LINK2 https://creativecommons.org/publicdomain/zero/1.0/, CC0 1.0 Universal) 28 */ 29 module libgit2.example.push; 30 31 32 private static import core.stdc.stdio; 33 private static import libgit2.example.common; 34 private static import libgit2.remote; 35 private static import libgit2.strarray; 36 private static import libgit2.types; 37 38 /** 39 * Entry point for this command 40 */ 41 extern (C) 42 nothrow @nogc 43 public int lg2_push(libgit2.types.git_repository* repo, int argc, char** argv) 44 45 do 46 { 47 /* Validate args */ 48 if (argc > 1) { 49 core.stdc.stdio.printf("USAGE: %s\n\nsorry, no arguments supported yet\n", argv[0]); 50 51 return -1; 52 } 53 54 libgit2.types.git_remote* remote = null; 55 libgit2.example.common.check_lg2(libgit2.remote.git_remote_lookup(&remote, repo, "origin"), "Unable to lookup remote", null); 56 57 libgit2.remote.git_push_options options; 58 libgit2.example.common.check_lg2(libgit2.remote.git_push_options_init(&options, libgit2.remote.GIT_PUSH_OPTIONS_VERSION), "Error initializing push", null); 59 60 const (char)* refspec = "refs/heads/master"; 61 const libgit2.strarray.git_strarray refspecs = {&refspec, 1}; 62 libgit2.example.common.check_lg2(libgit2.remote.git_remote_push(remote, &refspecs, &options), "Error pushing", null); 63 64 core.stdc.stdio.printf("pushed\n"); 65 66 return 0; 67 }