From: Jeff King <peff@peff.net>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org, jnareb@gmail.com, cworth@cworth.org
Subject: [PATCH] git-add: allow path limiting with -u
Date: Sat, 12 May 2007 02:42:00 -0400 [thread overview]
Message-ID: <20070512064159.GA7471@coredump.intra.peff.net> (raw)
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>
---
This turned out to be quite easy to implement. Patch is slightly larger
than necessary due to removing _all_ from the variable names, but I
think that better expresses the new functionality.
I'm not sure that the documentation needs updated at all; I had just
assumed after reading it that 'git-add -u foo' would DWIM.
builtin-add.c | 13 ++++++-------
t/t2200-add-update.sh | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 7 deletions(-)
create mode 100755 t/t2200-add-update.sh
diff --git a/builtin-add.c b/builtin-add.c
index 5e6748f..1591171 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -16,7 +16,7 @@
static const char builtin_add_usage[] =
"git-add [-n] [-v] [-f] [--interactive | -i] [-u] [--] <filepattern>...";
-static int take_all_worktree_changes;
+static int take_worktree_changes;
static const char *excludes_file;
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,
}
}
-static void update_all(int verbose)
+static void update(int verbose, const char **files)
{
struct rev_info rev;
init_revisions(&rev, "");
setup_revisions(0, NULL, &rev, NULL);
+ rev.prune_data = get_pathspec(rev.prefix, files);
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = update_callback;
rev.diffopt.format_callback_data = &verbose;
@@ -200,16 +201,14 @@ int cmd_add(int argc, const char **argv, const char *prefix)
continue;
}
if (!strcmp(arg, "-u")) {
- take_all_worktree_changes = 1;
+ take_worktree_changes = 1;
continue;
}
usage(builtin_add_usage);
}
- if (take_all_worktree_changes) {
- if (i < argc)
- die("-u and explicit paths are incompatible");
- update_all(verbose);
+ if (take_worktree_changes) {
+ update(verbose, argv + i);
goto finish;
}
diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
new file mode 100755
index 0000000..83005e7
--- /dev/null
+++ b/t/t2200-add-update.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+test_description='git-add -u with path limiting
+
+This test creates a working tree state with three files:
+
+ top (previously committed, modified)
+ dir/sub (previously committed, modified)
+ dir/other (untracked)
+
+and issues a git-add -u with path limiting on "dir" to add
+only the updates to dir/sub.'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+echo initial >top &&
+mkdir dir &&
+echo initial >dir/sub &&
+git-add dir/sub top &&
+git-commit -m initial &&
+echo changed >top &&
+echo changed >dir/sub &&
+echo other >dir/other
+'
+
+test_expect_success 'update' 'git-add -u dir'
+
+test_expect_success 'update touched correct path' \
+ 'test "`git-diff-files --name-status dir/sub`" = ""'
+
+test_expect_success 'update did not touch other tracked files' \
+ 'test "`git-diff-files --name-status top`" = "M top"'
+
+test_expect_success 'update did not touch untracked files' \
+ 'test "`git-diff-files --name-status dir/other`" = ""'
+
+test_done
--
1.5.2.rc3.709.g07945-dirty
next reply other threads:[~2007-05-12 6:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-12 6:42 Jeff King [this message]
2007-05-12 7:13 ` [PATCH] git-add: allow path limiting with -u Junio C Hamano
2007-05-13 10:35 ` Jakub Narebski
2007-05-14 0:39 ` Jeff King
2007-05-14 0:50 ` Jakub Narebski
2007-05-14 0:49 ` Jeff King
2007-05-14 1:26 ` Junio C Hamano
2007-05-14 0:42 ` Jeff King
2007-05-14 1:29 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070512064159.GA7471@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=cworth@cworth.org \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.com \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).