4 * Based on git-pull.sh by Junio C Hamano
6 * Fetch one or more remote refs and merge it/them into the current HEAD.
10 #include "parse-options.h"
12 #include "run-command.h"
14 static const char * const pull_usage
[] = {
15 N_("git pull [options] [<repository> [<refspec>...]]"),
19 static struct option pull_options
[] = {
24 * Parses argv into [<repo> [<refspecs>...]], returning their values in `repo`
25 * as a string and `refspecs` as a null-terminated array of strings. If `repo`
26 * is not provided in argv, it is set to NULL.
28 static void parse_repo_refspecs(int argc
, const char **argv
, const char **repo
,
29 const char ***refspecs
)
40 * Runs git-fetch, returning its exit status. `repo` and `refspecs` are the
41 * repository and refspecs to fetch, or NULL if they are not provided.
43 static int run_fetch(const char *repo
, const char **refspecs
)
45 struct argv_array args
= ARGV_ARRAY_INIT
;
48 argv_array_pushl(&args
, "fetch", "--update-head-ok", NULL
);
50 argv_array_push(&args
, repo
);
51 argv_array_pushv(&args
, refspecs
);
53 die("BUG: refspecs without repo?");
54 ret
= run_command_v_opt(args
.argv
, RUN_GIT_CMD
);
55 argv_array_clear(&args
);
60 * Runs git-merge, returning its exit status.
62 static int run_merge(void)
65 struct argv_array args
= ARGV_ARRAY_INIT
;
67 argv_array_pushl(&args
, "merge", NULL
);
68 argv_array_push(&args
, "FETCH_HEAD");
69 ret
= run_command_v_opt(args
.argv
, RUN_GIT_CMD
);
70 argv_array_clear(&args
);
74 int cmd_pull(int argc
, const char **argv
, const char *prefix
)
76 const char *repo
, **refspecs
;
78 if (!getenv("_GIT_USE_BUILTIN_PULL")) {
79 const char *path
= mkpath("%s/git-pull", git_exec_path());
81 if (sane_execvp(path
, (char **)argv
) < 0)
82 die_errno("could not exec %s", path
);
85 argc
= parse_options(argc
, argv
, prefix
, pull_options
, pull_usage
, 0);
87 parse_repo_refspecs(argc
, argv
, &repo
, &refspecs
);
89 if (run_fetch(repo
, refspecs
))