summaryrefslogtreecommitdiff
path: root/builtin-add.c
diff options
context:
space:
mode:
authorAlexandre Julliard <julliard@winehq.org>2007-08-11 23:59:01 +0200
committerJunio C Hamano <gitster@pobox.com>2007-08-13 12:58:38 -0700
commitd616813d75b888b7c29bbad19808fe5cffa5380c (patch)
tree822ae0e97f9ae00643bf9aee04f29af684bbd2a1 /builtin-add.c
parent77b258f436874bdd1caecd4b3c9c63e3d49bd147 (diff)
downloadgit-d616813d75b888b7c29bbad19808fe5cffa5380c.tar.gz
git-add: Add support for --refresh option.
This allows to refresh only a subset of the project files, based on the specified pathspecs. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-add.c')
-rw-r--r--builtin-add.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/builtin-add.c b/builtin-add.c
index de5c108f8f..82c806acf0 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -123,6 +123,23 @@ static void update(int verbose, const char **files)
run_diff_files(&rev, 0);
}
+static void refresh(int verbose, const char **pathspec)
+{
+ char *seen;
+ int i, specs;
+
+ for (specs = 0; pathspec[specs]; specs++)
+ /* nothing */;
+ seen = xcalloc(specs, 1);
+ if (read_cache() < 0)
+ die("index file corrupt");
+ refresh_index(&the_index, verbose ? 0 : REFRESH_QUIET, pathspec, seen);
+ for (i = 0; i < specs; i++) {
+ if (!seen[i])
+ die("pathspec '%s' did not match any files", pathspec[i]);
+ }
+}
+
static int git_add_config(const char *var, const char *value)
{
if (!strcmp(var, "core.excludesfile")) {
@@ -143,7 +160,7 @@ static const char ignore_warning[] =
int cmd_add(int argc, const char **argv, const char *prefix)
{
int i, newfd;
- int verbose = 0, show_only = 0, ignored_too = 0;
+ int verbose = 0, show_only = 0, ignored_too = 0, refresh_only = 0;
const char **pathspec;
struct dir_struct dir;
int add_interactive = 0;
@@ -191,6 +208,10 @@ int cmd_add(int argc, const char **argv, const char *prefix)
take_worktree_changes = 1;
continue;
}
+ if (!strcmp(arg, "--refresh")) {
+ refresh_only = 1;
+ continue;
+ }
usage(builtin_add_usage);
}
@@ -206,6 +227,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
}
pathspec = get_pathspec(prefix, argv + i);
+ if (refresh_only) {
+ refresh(verbose, pathspec);
+ goto finish;
+ }
+
fill_directory(&dir, pathspec, ignored_too);
if (show_only) {