Skip to content

Commit

Permalink
more commands, lg2-1.3.0
Browse files Browse the repository at this point in the history
git reset
checkout: -b (create new branch)
checkout: set upstream
status ahead/behind
libgit2-1.3.0
asyncify: use whenDone instead of finalizers
stash and pop test case
show conflict
conflict resolve
fix all 5 node tests
merge commit when in merge state
  • Loading branch information
petersalomonsen committed Dec 15, 2021
1 parent 5119c56 commit ff744fe
Show file tree
Hide file tree
Showing 24 changed files with 1,247 additions and 161 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Expand Up @@ -5,6 +5,15 @@ on:
pull_request:
branches: [ master ]
jobs:
detectonly:
name: Detect use of .only
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Detect use of .only
run: |
grep -rq --include '*.spec.js' \.only\( . && echo 'You have .only() in your tests!' && exit 1
exit 0
default:
name: "Default"
runs-on: ubuntu-latest
Expand Down
9 changes: 4 additions & 5 deletions emscriptenbuild/post-async.js
Expand Up @@ -25,12 +25,11 @@ FS.chmod = function(path, mode, dontFollow) {
};

if(ENVIRONMENT_IS_WEB) {
Module.oldCallMain = Module.callMain
Module.origCallMain = Module.callMain;
Module.callMain = async (args) => {
await Module.oldCallMain(args);
var runningAsync = typeof Asyncify === 'object' && Asyncify.currData;
if (runningAsync) {
await new Promise((resolve) => { Asyncify.asyncFinalizers.push(() => { resolve();}); });
await Module.origCallMain(args);
if (typeof Asyncify === 'object' && Asyncify.currData) {
await Asyncify.whenDone();
}
};

Expand Down
2 changes: 1 addition & 1 deletion karma.conf-async.js
Expand Up @@ -26,7 +26,7 @@ module.exports = function(config) {
],

proxies: {
'/testrepo.git': 'http://localhost:5000/testrepo.git',
'/testrepo.git': 'http://localhost:8080/testrepo.git',
},

// preprocess matching files before serving them to the browser
Expand Down
4 changes: 2 additions & 2 deletions karma.conf.js
Expand Up @@ -27,7 +27,7 @@ module.exports = function(config) {
],

proxies: {
'/testrepo.git': 'http://localhost:5000/testrepo.git',
'/testrepo.git': 'http://localhost:8080/testrepo.git',
},

// preprocess matching files before serving them to the browser
Expand All @@ -44,7 +44,7 @@ module.exports = function(config) {

// web server port
port: 9876,

browserNoActivityTimeout: 10000,

// enable / disable colors in the output (reporters and logs)
colors: true,
Expand Down
79 changes: 68 additions & 11 deletions libgit2patchedfiles/examples/checkout.c
Expand Up @@ -29,6 +29,7 @@
* The following example demonstrates how to do checkouts with libgit2.
*
* Recognized options are :
* -b: create new branch
* --force: force the checkout to happen.
* --[no-]progress: show checkout progress, on by default.
* --perf: show performance data.
Expand All @@ -43,11 +44,12 @@ typedef struct {
static void print_usage(void)
{
fprintf(stderr, "usage: checkout [options] <branch>\n"
"Options are :\n"
" --git-dir: use the following git repository.\n"
" --force: force the checkout.\n"
" --[no-]progress: show checkout progress.\n"
" --perf: show performance data.\n");
"Options are :\n"
" -b: create new branch"
" --git-dir: use the following git repository.\n"
" --force: force the checkout.\n"
" --[no-]progress: show checkout progress.\n"
" --perf: show performance data.\n");
exit(1);
}

Expand Down Expand Up @@ -104,7 +106,7 @@ static void print_perf_data(const git_checkout_perfdata *perfdata, void *payload
{
(void)payload;
printf("perf: stat: %" PRIuZ " mkdir: %" PRIuZ " chmod: %" PRIuZ "\n",
perfdata->stat_calls, perfdata->mkdir_calls, perfdata->chmod_calls);
perfdata->stat_calls, perfdata->mkdir_calls, perfdata->chmod_calls);
}

/**
Expand Down Expand Up @@ -223,7 +225,7 @@ static int guess_refish(git_annotated_commit **out, git_repository *repo, const
goto next;

break;
next:
next:
free(refname);
if (error < 0 && error != GIT_ENOTFOUND)
break;
Expand All @@ -239,7 +241,7 @@ static int guess_refish(git_annotated_commit **out, git_repository *repo, const

out:
git_reference_free(remote_ref);
git_strarray_free(&remotes);
git_strarray_dispose(&remotes);
return error;
}

Expand All @@ -250,6 +252,13 @@ int lg2_checkout(git_repository *repo, int argc, char **argv)
checkout_options opts;
git_repository_state_t state;
git_annotated_commit *checkout_target = NULL;
git_reference *new_branch_ref = NULL;
git_object *target_obj = NULL;
git_commit *target_commit = NULL;
git_reference *branch_ref = NULL;
git_reference *upstream_ref = NULL;

const char *opt_new_branch;

int err = 0;
const char *path = ".";
Expand All @@ -264,6 +273,24 @@ int lg2_checkout(git_repository *repo, int argc, char **argv)
goto cleanup;
}

if (optional_str_arg(&opt_new_branch, &args, "-b", "")) {
err = git_revparse_single(&target_obj, repo, "HEAD");
if (err != 0) {
fprintf(stderr, "error: %s\n", git_error_last()->message);
goto cleanup;
}
err = git_commit_lookup(&target_commit, repo, git_object_id(target_obj));
if (err != 0) {
fprintf(stderr, "error looking up commit: %s\n", git_error_last()->message);
goto cleanup;
}
err = git_branch_create(&new_branch_ref, repo, opt_new_branch, target_commit, 0);
if (err != 0) {
fprintf(stderr, "error creating branch: %s\n", git_error_last()->message);
goto cleanup;
}
}

if (match_arg_separator(&args)) {
/**
* Try to checkout the given path(s)
Expand All @@ -275,7 +302,7 @@ int lg2_checkout(git_repository *repo, int argc, char **argv)
copts.checkout_strategy = GIT_CHECKOUT_FORCE;

paths.count = args.argc - args.pos;

if (paths.count == 0) {
fprintf(stderr, "error: no paths specified\n");
return GIT_ERROR_INVALID;
Expand All @@ -293,16 +320,46 @@ int lg2_checkout(git_repository *repo, int argc, char **argv)
/**
* Try to resolve a "refish" argument to a target libgit2 can use
*/

const char *branchname;
char upstreamname[1024] = "origin/";

if ((err = resolve_refish(&checkout_target, repo, args.argv[args.pos])) < 0 &&
(err = guess_refish(&checkout_target, repo, args.argv[args.pos])) < 0) {
(err = guess_refish(&checkout_target, repo, args.argv[args.pos])) < 0) {
fprintf(stderr, "failed to resolve %s: %s\n", args.argv[args.pos], git_error_last()->message);
goto cleanup;
}
err = perform_checkout_ref(repo, checkout_target, args.argv[args.pos], &opts);
if (err != 0) {
fprintf(stderr, "failed to checkout %s: %s\n", args.argv[args.pos], git_error_last()->message);
goto cleanup;
}
err = git_repository_head(&branch_ref, repo);
if (!err && git_branch_upstream(&upstream_ref, branch_ref) == GIT_ENOTFOUND) {
branchname = git_reference_shorthand(branch_ref);
strcat(upstreamname, branchname);

err = git_branch_set_upstream(branch_ref,upstreamname);
if (err == GIT_ENOTFOUND) {
// no upstream exists
git_error_clear();
err = 0;
}
if (err != 0) {
fprintf(stderr, "error: %s\n", git_error_last()->message);
goto cleanup;
}
printf("Branch '%s' set up to track remote branch '%s'\n", branchname, upstreamname);
}
}

cleanup:
git_annotated_commit_free(checkout_target);
git_commit_free(target_commit);
git_object_free(target_obj);

git_annotated_commit_free(checkout_target);
git_reference_free(new_branch_ref);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
return err;
}
39 changes: 28 additions & 11 deletions libgit2patchedfiles/examples/commit.c
Expand Up @@ -65,17 +65,34 @@ int lg2_commit(git_repository *repo, int argc, char **argv)

check_lg2(git_signature_default(&signature, repo), "Error creating signature", NULL);

check_lg2(git_commit_create_v(
&commit_oid,
repo,
"HEAD",
signature,
signature,
NULL,
comment,
tree,
parent ? 1 : 0, parent), "Error creating commit", NULL);

if (git_repository_state(repo) == GIT_REPOSITORY_STATE_MERGE) {
git_object * mergehead = NULL;
git_reference * mergeheadref = NULL;

check_lg2(git_revparse_ext(&mergehead, &mergeheadref, repo, "MERGE_HEAD"), "Error looking up MERGE_HEAD", NULL);
check_lg2(git_commit_create_v(
&commit_oid,
repo,
"HEAD",
signature,
signature,
NULL,
comment,
tree,
2, parent, mergehead), "Error creating commit", NULL);
git_repository_state_cleanup(repo);
} else {
check_lg2(git_commit_create_v(
&commit_oid,
repo,
"HEAD",
signature,
signature,
NULL,
comment,
tree,
parent ? 1 : 0, parent), "Error creating commit", NULL);
}
git_index_free(index);
git_signature_free(signature);
git_tree_free(tree);
Expand Down
1 change: 1 addition & 0 deletions libgit2patchedfiles/examples/common.h
Expand Up @@ -74,6 +74,7 @@ extern int lg2_ls_remote(git_repository *repo, int argc, char **argv);
extern int lg2_merge(git_repository *repo, int argc, char **argv);
extern int lg2_push(git_repository *repo, int argc, char **argv);
extern int lg2_remote(git_repository *repo, int argc, char **argv);
extern int lg2_reset(git_repository *repo, int argc, char **argv);
extern int lg2_rev_list(git_repository *repo, int argc, char **argv);
extern int lg2_rev_parse(git_repository *repo, int argc, char **argv);
extern int lg2_show_index(git_repository *repo, int argc, char **argv);
Expand Down
1 change: 1 addition & 0 deletions libgit2patchedfiles/examples/lg2.c
Expand Up @@ -30,6 +30,7 @@ struct {
{ "merge", lg2_merge, 1 },
{ "push", lg2_push, 1 },
{ "remote", lg2_remote, 1 },
{ "reset", lg2_reset, 1 },
{ "rev-list", lg2_rev_list, 1 },
{ "rev-parse", lg2_rev_parse, 1 },
{ "show-index", lg2_show_index, 0 },
Expand Down
8 changes: 7 additions & 1 deletion libgit2patchedfiles/examples/push.c
Expand Up @@ -33,7 +33,12 @@
int lg2_push(git_repository *repo, int argc, char **argv) {
git_push_options options;
git_remote* remote = NULL;
char *refspec = "refs/heads/master";
char *refspec = NULL;
git_reference* head_ref;

git_reference_lookup(&head_ref, repo, "HEAD");
refspec = git_reference_symbolic_target(head_ref);

const git_strarray refspecs = {
&refspec,
1
Expand All @@ -52,5 +57,6 @@ int lg2_push(git_repository *repo, int argc, char **argv) {
check_lg2(git_remote_push(remote, &refspecs, &options), "Error pushing", NULL);

printf("pushed\n");
git_reference_free(head_ref);
return 0;
}
69 changes: 69 additions & 0 deletions libgit2patchedfiles/examples/reset.c
@@ -0,0 +1,69 @@
/*
* libgit2 "reset" example - Reset current HEAD to the specified state
*
* Written by the libgit2 contributors
*
* To the extent possible under law, the author(s) have dedicated all copyright
* and related and neighboring rights to this software to the public domain
* worldwide. This software is distributed without any warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication along
* with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

#include "common.h"

/**
* The following example demonstrates how to reset libgit2.
*
* It will use the repository in the current working directory, and reset to the specified revspec
*
* Recognized options are:
* --hard: reset hard
* --soft: reset soft
*/

int lg2_reset(git_repository *repo, int argc, char **argv)
{
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
git_commit *target_commit = NULL;
git_revspec revspec;
git_reset_t reset_type = GIT_RESET_MIXED;
int err;

err = git_revparse(&revspec, repo, argv[argc - 1]);
if (err != 0)
{
fprintf(stderr, "failed to lookup rev: %s\n", git_error_last()->message);
goto cleanup;
}
err = git_commit_lookup(&target_commit, repo, revspec.from);
if (err != 0)
{
fprintf(stderr, "failed to lookup commit: %s\n", git_error_last()->message);
goto cleanup;
}

if (argc > 1)
{
if (!strcmp(argv[argc - 2], "--hard"))
{
reset_type = GIT_RESET_HARD;
}
else if (!strcmp(argv[argc - 2], "--soft"))
{
reset_type = GIT_RESET_SOFT;
}
}
err = git_reset(repo, target_commit, reset_type, &checkout_opts);
if (err != 0)
{
fprintf(stderr, "reset error: %s\n", git_error_last()->message);
goto cleanup;
}
cleanup:
git_commit_free(target_commit);

return 0;
}

0 comments on commit ff744fe

Please sign in to comment.