Skip to content

Commit

Permalink
wrap git updating improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
annacrombie committed Nov 14, 2024
1 parent 37d6602 commit 96170e3
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,31 @@ wrap_handle_file(struct wrap *wrap, struct wrap_opts *opts)
wrap->fields[wf_source_filename], wrap->fields[wf_source_url], wrap->fields[wf_source_hash], dest, opts);
}

static bool
is_git_dir(const char *dir)
{
SBUF_manual(git_dir);
path_join(0, &git_dir, dir, ".git");
bool res = fs_dir_exists(git_dir.buf);
sbuf_destroy(&git_dir);
return res;
}

static bool
wrap_handle_git(struct wrap *wrap, struct wrap_opts *opts)
{
if (!wrap_run_cmd((const char *const[]){ "git", "clone", wrap->fields[wf_url], wrap->dest_dir.buf, NULL },
NULL,
NULL)) {
return false;
if (is_git_dir(wrap->dest_dir.buf)) {
if (!wrap_run_cmd((const char *const[]){ "git", "remote", "update", NULL },
wrap->dest_dir.buf,
NULL)) {
return false;
}
} else {
if (!wrap_run_cmd((const char *const[]){ "git", "clone", wrap->fields[wf_url], wrap->dest_dir.buf, NULL },
NULL,
NULL)) {
return false;
}
}

if (!wrap_run_cmd(
Expand Down Expand Up @@ -664,25 +682,15 @@ git_rev_parse(const char *dir, const char *rev, struct sbuf *out)
return true;
}

bool
is_git_dir(const char *dir)
{
SBUF_manual(git_dir);
path_join(0, &git_dir, dir, ".git");
bool res = fs_dir_exists(git_dir.buf);
sbuf_destroy(&git_dir);
return res;
}

bool
static bool
wrap_check_dirty_git(struct wrap *wrap, struct wrap_opts *opts)
{
if (!is_git_dir(wrap->dest_dir.buf)) {
wrap->outdated = true;
return true;
}

wrap->dirty = wrap_run_cmd_status((const char *const[]){ "git", "diff", "-q", 0 }, wrap->dest_dir.buf, 0) != 0;
wrap->dirty = wrap_run_cmd_status((const char *const[]){ "git", "diff", "--quiet", 0 }, wrap->dest_dir.buf, 0) != 0;

SBUF_manual(head_rev);
SBUF_manual(wrap_rev);
Expand Down

0 comments on commit 96170e3

Please sign in to comment.