examples: additions and fixes#5421
Conversation
|
I will review this after v1.0 is released. Please feel free to ping me after the release if I forget. |
pks-t
left a comment
There was a problem hiding this comment.
Thanks a lot for these examples, I'm always happy to extend what we have. There's a few comments I'd like to address, but I'm happy to merge this in the future.
| const char *comment = argv[2]; | ||
| int error; | ||
|
|
||
| git_oid commit_oid,tree_oid; |
| git_revparse_ext(&parent, &ref, repo, "HEAD"); | ||
| git_repository_index(&index, repo); | ||
| git_index_write_tree(&tree_oid, index); | ||
| git_index_write(index); |
There was a problem hiding this comment.
All of the above commands should be checked for errors.
| (void)repo; /* unused */ | ||
|
|
||
| /* Validate args */ | ||
| if (argc < 3 || strcmp(opt, "-m")!=0) { |
There was a problem hiding this comment.
Please add a space before and after !=
| const git_error *err = git_error_last(); | ||
| if (err) printf("ERROR %d: %s\n", err->klass, err->message); | ||
| else printf("ERROR %d: no detailed info\n", error); | ||
| } |
There was a problem hiding this comment.
You can use check_lg2 in general for any kind of error checking.
| const git_strarray refspecs = { | ||
| &refspec, | ||
| 1, | ||
| }; |
There was a problem hiding this comment.
There's some formatting errors above with regards to whitespace. We also always use /* */ even for single-line comments, same below.
| const git_error *err = git_error_last(); | ||
| if (err) printf("ERROR %d: %s\n", err->klass, err->message); | ||
| else printf("ERROR %d: no detailed info\n", error); | ||
| } |
There was a problem hiding this comment.
If you use check_lg2, then you don't need this block. so please also use it fo r git_remote_lookup and git_push_options_init.
8642b2c to
c73eeed
Compare
|
Thanks for reviewing @pks-t . I believe the issues are resolved now. For |
pks-t
left a comment
There was a problem hiding this comment.
Sorry to be nitpicky, but there's some more style issues I'd like to have fixed before merging. Looks fine to me otherwise :)
| git_reference *ref = NULL; | ||
| git_signature *signature; | ||
|
|
||
| (void)repo; /* unused */ |
There was a problem hiding this comment.
This line can be removed, you use the repo ;)
| } | ||
|
|
||
| error = git_revparse_ext(&parent, &ref, repo, "HEAD"); | ||
| if ( error == GIT_ENOTFOUND) { |
There was a problem hiding this comment.
There's a stray space here in between ( error
|
|
||
| check_lg2(git_tree_lookup(&tree, repo, &tree_oid), "Error looking up tree", NULL); | ||
|
|
||
| git_signature_default(&signature, repo); |
There was a problem hiding this comment.
This also requires error checking.
|
|
||
| check_lg2(git_push_options_init( &options, GIT_PUSH_OPTIONS_VERSION ), "Error initializing push", NULL); | ||
|
|
||
| check_lg2(git_remote_push( remote, &refspecs, &options), "Error pushing", NULL); |
There was a problem hiding this comment.
There's a few more stray spaces in these commands :)
| check_lg2(git_index_write_tree(&tree_oid, index), "Could not write tree", NULL);; | ||
| check_lg2(git_index_write(index), "Could not write index", NULL);; | ||
|
|
||
| git_index_free(index); |
There was a problem hiding this comment.
I'd move this line before the return error to not disturb the program's business logic flowing and make it easier to understand
add example for git commit fix example for git add add example for git push
c73eeed to
dc2beb7
Compare
|
yeah, no problem being nitpicky :-) quality is important, and I feel a bit novice on the code conventions here - so very happy for your guidance :-) Think I got the issues resolved now, but let me know if there are more :-) |
pks-t
left a comment
There was a problem hiding this comment.
Cool, thanks a lot for these examples!
That's on us, though. We don't have a style guide anywhere, so newcomers are left guessing. We should definitely have one, but I've been saying that for a few years now and never just sat down and wrote one. |
|
The push example always fails for me. I tested pushing to remotes on GitHub, GitLab, and a local repo on my desktop. I always get After doing some testing with pushing to a local remote on my desktop, I've isolated the failure: With pushing to both my GitHub and GitLab remotes, it fails in For pushing to both my local desktop copy and to GitLab, the error message is: "the transport has not yet loaded the refs" |
here's the example fixes / additions from my emscripten PR as requested in #5345 (comment)