Skip to content

Commit

Permalink
Merge branch 'wc/add-i'
Browse files Browse the repository at this point in the history
* wc/add-i:
  git-add -i: add help text for list-and-choose UI
  add -i: allow prefix highlighting for "Add untracked" as well.
  Highlight keyboard shortcuts in git-add--interactive
  Document all help keys in "git add -i" patch mode.
  Add "--patch" option to git-add--interactive
  add -i: Fix running from a subdirectory
  builtin-add: fix command line building to call interactive
  git-add -i: allow multiple selection in patch subcommand
  Add path-limiting to git-add--interactive
  Teach builtin-add to pass multiple paths to git-add--interactive
  • Loading branch information
Junio C Hamano committed Dec 5, 2007
2 parents 31cbb5d + 7e018be commit ab7d707
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 46 deletions.
11 changes: 10 additions & 1 deletion Documentation/git-add.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ OPTIONS

-i, \--interactive::
Add modified contents in the working tree interactively to
the index.
the index. Optional path arguments may be supplied to limit
operation to a subset of the working tree. See ``Interactive
mode'' for details.

-p, \--patch:
Similar to Interactive mode but the initial command loop is
bypassed and the 'patch' subcommand is invoked using each of
the specified filepatterns before exiting.

-u::
Update only files that git already knows about. This is similar
Expand Down Expand Up @@ -210,6 +217,8 @@ patch::
k - do not decide on this hunk now, and view the previous
undecided hunk
K - do not decide on this hunk now, and view the previous hunk
s - split the current hunk into smaller hunks
? - print help
+
After deciding the fate for all hunks, if there is any hunk
that was chosen, the index is updated with the selected hunks.
Expand Down
50 changes: 39 additions & 11 deletions builtin-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const char * const builtin_add_usage[] = {
"git-add [options] [--] <filepattern>...",
NULL
};

static int patch_interactive = 0, add_interactive = 0;
static int take_worktree_changes;

static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
Expand Down Expand Up @@ -135,11 +135,40 @@ static void refresh(int verbose, const char **pathspec)
free(seen);
}

int interactive_add(void)
static const char **validate_pathspec(int argc, const char **argv, const char *prefix)
{
const char *argv[2] = { "add--interactive", NULL };
const char **pathspec = get_pathspec(prefix, argv);

return run_command_v_opt(argv, RUN_GIT_CMD);
return pathspec;
}

int interactive_add(int argc, const char **argv, const char *prefix)
{
int status, ac;
const char **args;
const char **pathspec = NULL;

if (argc) {
pathspec = validate_pathspec(argc, argv, prefix);
if (!pathspec)
return -1;
}

args = xcalloc(sizeof(const char *), (argc + 4));
ac = 0;
args[ac++] = "add--interactive";
if (patch_interactive)
args[ac++] = "--patch";
args[ac++] = "--";
if (argc) {
memcpy(&(args[ac]), pathspec, sizeof(const char *) * argc);
ac += argc;
}
args[ac] = NULL;

status = run_command_v_opt(args, RUN_GIT_CMD);
free(args);
return status;
}

static struct lock_file lock_file;
Expand All @@ -148,13 +177,13 @@ static const char ignore_error[] =
"The following paths are ignored by one of your .gitignore files:\n";

static int verbose = 0, show_only = 0, ignored_too = 0, refresh_only = 0;
static int add_interactive = 0;

static struct option builtin_add_options[] = {
OPT__DRY_RUN(&show_only),
OPT__VERBOSE(&verbose),
OPT_GROUP(""),
OPT_BOOLEAN('i', "interactive", &add_interactive, "interactive picking"),
OPT_BOOLEAN('p', "patch", &patch_interactive, "interactive patching"),
OPT_BOOLEAN('f', NULL, &ignored_too, "allow adding otherwise ignored files"),
OPT_BOOLEAN('u', NULL, &take_worktree_changes, "update tracked files"),
OPT_BOOLEAN( 0 , "refresh", &refresh_only, "don't add, only refresh the index"),
Expand All @@ -163,17 +192,16 @@ static struct option builtin_add_options[] = {

int cmd_add(int argc, const char **argv, const char *prefix)
{
int i, newfd, orig_argc = argc;
int i, newfd;
const char **pathspec;
struct dir_struct dir;

argc = parse_options(argc, argv, builtin_add_options,
builtin_add_usage, 0);
if (add_interactive) {
if (add_interactive != 1 || orig_argc != 2)
die("add --interactive does not take any parameters");
exit(interactive_add());
}
if (patch_interactive)
add_interactive = 1;
if (add_interactive)
exit(interactive_add(argc, argv, prefix));

git_config(git_default_config);

Expand Down
12 changes: 6 additions & 6 deletions builtin-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,24 @@ static void add_remove_files(struct path_list *list)
}
}

static char *prepare_index(const char **files, const char *prefix)
static char *prepare_index(int argc, const char **argv, const char *prefix)
{
int fd;
struct tree *tree;
struct path_list partial;
const char **pathspec = NULL;

if (interactive) {
interactive_add();
interactive_add(argc, argv, prefix);
commit_style = COMMIT_AS_IS;
return get_index_file();
}

if (read_cache() < 0)
die("index file corrupt");

if (*files)
pathspec = get_pathspec(prefix, files);
if (*argv)
pathspec = get_pathspec(prefix, argv);

/*
* Non partial, non as-is commit.
Expand Down Expand Up @@ -603,7 +603,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)

argc = parse_and_validate_options(argc, argv, builtin_status_usage);

index_file = prepare_index(argv, prefix);
index_file = prepare_index(argc, argv, prefix);

commitable = run_status(stdout, index_file, prefix);

Expand Down Expand Up @@ -703,7 +703,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)

argc = parse_and_validate_options(argc, argv, builtin_commit_usage);

index_file = prepare_index(argv, prefix);
index_file = prepare_index(argc, argv, prefix);

if (!no_verify && run_hook(index_file, "pre-commit", NULL)) {
rollback_index_files();
Expand Down
2 changes: 1 addition & 1 deletion commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,

int in_merge_bases(struct commit *, struct commit **, int);

extern int interactive_add(void);
extern int interactive_add(int argc, const char **argv, const char *prefix);
extern int rerere(void);

static inline int single_parent(struct commit *commit)
Expand Down
Loading

0 comments on commit ab7d707

Please sign in to comment.