Skip to content

Commit

Permalink
Merge pull request #77 from jhunkeler/fix-git-clone-return
Browse files Browse the repository at this point in the history
Fix git_clone return
  • Loading branch information
jhunkeler authored Dec 17, 2024
2 parents 6c0355d + d664bef commit 8186ad8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
39 changes: 32 additions & 7 deletions src/lib/core/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,39 +307,64 @@ int touch(const char *filename) {
}

int git_clone(struct Process *proc, char *url, char *destdir, char *gitref) {
int result = -1;
int result = 0;
char *chdir_to = NULL;
char *program = find_program("git");
if (!program) {
return result;
result = -1;
goto die_quick;
}

static char command[PATH_MAX];
static char command[PATH_MAX] = {0};
sprintf(command, "%s clone -c advice.detachedHead=false --recursive %s", program, url);

if (destdir && access(destdir, F_OK) < 0) {
// Destination directory does not exist
sprintf(command + strlen(command), " %s", destdir);
// Clone the repo
result = shell(proc, command);
if (result) {
goto die_quick;
}
}

if (destdir) {
chdir_to = destdir;
} else {
// Assume the name of the directory to be the basename of the URL
// like it is when executed in a shell session
chdir_to = path_basename(url);
}

pushd(chdir_to);
{
if (!pushd(chdir_to)) {
memset(command, 0, sizeof(command));
sprintf(command, "%s fetch --all", program);
result += shell(proc, command);
result = shell(proc, command);
if (result) {
goto die_pop;
}

if (gitref != NULL) {
memset(command, 0, sizeof(command));
sprintf(command, "%s checkout %s", program, gitref);
result += shell(proc, command);

result = shell(proc, command);
if (result) {
goto die_pop;
}
}
popd();
} else {
result = -1;
goto die_quick;
}
return 0;

die_pop:
// close out last pushd() call
popd();

die_quick:
return result;
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/delivery/delivery_build.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) {
memset(wheeldir, 0, sizeof(wheeldir));

sprintf(srcdir, "%s/%s", ctx->storage.build_sources_dir, ctx->tests[i].name);
git_clone(&proc, ctx->tests[i].repository, srcdir, ctx->tests[i].version);
if (git_clone(&proc, ctx->tests[i].repository, srcdir, ctx->tests[i].version)) {
SYSERROR("Unable to checkout tag '%s' for package '%s' from repository '%s'\n",
ctx->tests[i].version, ctx->tests[i].name, ctx->tests[i].repository);
return NULL;
}

if (ctx->tests[i].repository_remove_tags && strlist_count(ctx->tests[i].repository_remove_tags)) {
filter_repo_tags(srcdir, ctx->tests[i].repository_remove_tags);
Expand Down
2 changes: 0 additions & 2 deletions tests/test_recipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ int main(int argc, char *argv[]) {
STASIS_TEST_FUNC *tests[] = {
test_recipe_clone,
};
mkdir("workspace", 0755);
pushd("workspace");
STASIS_TEST_RUN(tests);
popd();
STASIS_TEST_END_MAIN();
Expand Down

0 comments on commit 8186ad8

Please sign in to comment.