git-add: allow path limiting with -u
Rather than updating all working tree paths, we limit ourselves to paths listed on the command line. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jeff King committed
May 12, 2007 at 02:42 UTC
93c44d493b8c98b9bb74e4f78aa90ee20a01f078
2 files changed
+44
-7
builtin-add.c
+6
-7
@@ -16,7 +16,7 @@
16
static const char builtin_add_usage[] =
17
"git-add [-n] [-v] [-f] [--interactive | -i] [-u] [--] <filepattern>...";
18
19
-static int take_all_worktree_changes;
19
+static int take_worktree_changes;
20
static const char *excludes_file;
21
22
static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
@@ -122,11 +122,12 @@ static void update_callback(struct diff_queue_struct *q,
122
}
123
}
124
125
-static void update_all(int verbose)
125
+static void update(int verbose, const char **files)
126
{
127
struct rev_info rev;
128
init_revisions(&rev, "");
129
setup_revisions(0, NULL, &rev, NULL);
130
+ rev.prune_data = get_pathspec(rev.prefix, files);
131
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
132
rev.diffopt.format_callback = update_callback;
133
rev.diffopt.format_callback_data = &verbose;
@@ -200,16 +201,14 @@ int cmd_add(int argc, const char **argv, const char *prefix)
201
continue;
202
}
203
if (!strcmp(arg, "-u")) {
203
- take_all_worktree_changes = 1;
204
+ take_worktree_changes = 1;
205
continue;
206
}
207
usage(builtin_add_usage);
208
}
209
209
- if (take_all_worktree_changes) {
210
- if (i < argc)
211
- die("-u and explicit paths are incompatible");
212
- update_all(verbose);
210
+ if (take_worktree_changes) {
211
+ update(verbose, argv + i);
212
goto finish;
213
}
214
t/t2200-add-update.sh
new
+38
@@ -0,0 +1,38 @@
1
+#!/bin/sh
2
+
3
+test_description='git-add -u with path limiting
4
+
5
+This test creates a working tree state with three files:
6
+
7
+ top (previously committed, modified)
8
+ dir/sub (previously committed, modified)
9
+ dir/other (untracked)
10
+
11
+and issues a git-add -u with path limiting on "dir" to add
12
+only the updates to dir/sub.'
13
+
14
+. ./test-lib.sh
15
+
16
+test_expect_success 'setup' '
17
+echo initial >top &&
18
+mkdir dir &&
19
+echo initial >dir/sub &&
20
+git-add dir/sub top &&
21
+git-commit -m initial &&
22
+echo changed >top &&
23
+echo changed >dir/sub &&
24
+echo other >dir/other
25
+'
26
+
27
+test_expect_success 'update' 'git-add -u dir'
28
+
29
+test_expect_success 'update touched correct path' \
30
+ 'test "`git-diff-files --name-status dir/sub`" = ""'
31
+
32
+test_expect_success 'update did not touch other tracked files' \
33
+ 'test "`git-diff-files --name-status top`" = "M top"'
34
+
35
+test_expect_success 'update did not touch untracked files' \
36
+ 'test "`git-diff-files --name-status dir/other`" = ""'
37
+
38
+test_done