2006-05-17 20:33:32 +04:00
|
|
|
/*
|
|
|
|
* "git add" builtin command
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Linus Torvalds
|
|
|
|
*/
|
|
|
|
#include "cache.h"
|
|
|
|
#include "builtin.h"
|
|
|
|
#include "dir.h"
|
git-add --interactive
A script to be driven when the user says "git add --interactive"
is introduced.
When it is run, first it runs its internal 'status' command to
show the current status, and then goes into its internactive
command loop.
The command loop shows the list of subcommands available, and
gives a prompt "What now> ". In general, when the prompt ends
with a single '>', you can pick only one of the choices given
and type return, like this:
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now> 1
You also could say "s" or "sta" or "status" above as long as the
choice is unique.
The main command loop has 6 subcommands (plus help and quit).
* 'status' shows the change between HEAD and index (i.e. what
will be committed if you say "git commit"), and between index
and working tree files (i.e. what you could stage further
before "git commit" using "git-add") for each path. A sample
output looks like this:
staged unstaged path
1: binary nothing foo.png
2: +403/-35 +1/-1 git-add--interactive.perl
It shows that foo.png has differences from HEAD (but that is
binary so line count cannot be shown) and there is no
difference between indexed copy and the working tree
version (if the working tree version were also different,
'binary' would have been shown in place of 'nothing'). The
other file, git-add--interactive.perl, has 403 lines added
and 35 lines deleted if you commit what is in the index, but
working tree file has further modifications (one addition and
one deletion).
* 'update' shows the status information and gives prompt
"Update>>". When the prompt ends with double '>>', you can
make more than one selection, concatenated with whitespace or
comma. Also you can say ranges. E.g. "2-5 7,9" to choose
2,3,4,5,7,9 from the list. You can say '*' to choose
everything.
What you chose are then highlighted with '*', like this:
staged unstaged path
1: binary nothing foo.png
* 2: +403/-35 +1/-1 git-add--interactive.perl
To remove selection, prefix the input with - like this:
Update>> -2
After making the selection, answer with an empty line to
stage the contents of working tree files for selected paths
in the index.
* 'revert' has a very similar UI to 'update', and the staged
information for selected paths are reverted to that of the
HEAD version. Reverting new paths makes them untracked.
* 'add untracked' has a very similar UI to 'update' and
'revert', and lets you add untracked paths to the index.
* 'patch' lets you choose one path out of 'status' like
selection. After choosing the path, it presents diff between
the index and the working tree file and asks you if you want
to stage the change of each hunk. You can say:
y - add the change from that hunk to index
n - do not add the change from that hunk to index
a - add the change from that hunk and all the rest to index
d - do not the change from that hunk nor any of the rest to index
j - do not decide on this hunk now, and view the next
undecided hunk
J - do not decide on this hunk now, and view the next hunk
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
After deciding the fate for all hunks, if there is any hunk
that was chosen, the index is updated with the selected hunks.
* 'diff' lets you review what will be committed (i.e. between
HEAD and index).
This is still rough, but does everything except a few things I
think are needed.
* 'patch' should be able to allow splitting a hunk into
multiple hunks.
* 'patch' does not adjust the line offsets @@ -k,l +m,n @@
in the hunk header. This does not have major problem in
practice, but it _should_ do the adjustment.
* It does not have any explicit support for a merge in
progress; it may not work at all.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-11 07:55:50 +03:00
|
|
|
#include "exec_cmd.h"
|
2006-05-20 12:28:49 +04:00
|
|
|
#include "cache-tree.h"
|
2007-04-20 12:39:39 +04:00
|
|
|
#include "diff.h"
|
|
|
|
#include "diffcore.h"
|
|
|
|
#include "commit.h"
|
|
|
|
#include "revision.h"
|
2006-05-17 20:33:32 +04:00
|
|
|
|
|
|
|
static const char builtin_add_usage[] =
|
2007-04-20 12:39:39 +04:00
|
|
|
"git-add [-n] [-v] [-f] [--interactive | -i] [-u] [--] <filepattern>...";
|
2006-05-17 20:33:32 +04:00
|
|
|
|
2007-05-12 10:42:00 +04:00
|
|
|
static int take_worktree_changes;
|
2007-02-28 06:31:10 +03:00
|
|
|
static const char *excludes_file;
|
|
|
|
|
2006-05-17 20:33:32 +04:00
|
|
|
static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
|
|
|
|
{
|
2006-05-18 00:23:19 +04:00
|
|
|
char *seen;
|
|
|
|
int i, specs;
|
2006-05-17 20:33:32 +04:00
|
|
|
struct dir_entry **src, **dst;
|
|
|
|
|
2006-05-18 00:23:19 +04:00
|
|
|
for (specs = 0; pathspec[specs]; specs++)
|
|
|
|
/* nothing */;
|
2006-07-25 11:30:18 +04:00
|
|
|
seen = xcalloc(specs, 1);
|
2006-05-18 00:23:19 +04:00
|
|
|
|
2006-05-17 20:33:32 +04:00
|
|
|
src = dst = dir->entries;
|
|
|
|
i = dir->nr;
|
|
|
|
while (--i >= 0) {
|
|
|
|
struct dir_entry *entry = *src++;
|
2006-12-29 22:01:31 +03:00
|
|
|
if (match_pathspec(pathspec, entry->name, entry->len,
|
|
|
|
prefix, seen))
|
|
|
|
*dst++ = entry;
|
2006-05-17 20:33:32 +04:00
|
|
|
}
|
|
|
|
dir->nr = dst - dir->entries;
|
2006-05-18 00:23:19 +04:00
|
|
|
|
|
|
|
for (i = 0; i < specs; i++) {
|
|
|
|
struct stat st;
|
|
|
|
const char *match;
|
|
|
|
if (seen[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
match = pathspec[i];
|
2006-12-29 22:01:31 +03:00
|
|
|
if (!match[0])
|
2006-05-18 00:23:19 +04:00
|
|
|
continue;
|
2006-12-29 22:01:31 +03:00
|
|
|
|
|
|
|
/* Existing file? We must have ignored it */
|
|
|
|
if (!lstat(match, &st)) {
|
|
|
|
struct dir_entry *ent;
|
|
|
|
|
|
|
|
ent = dir_add_name(dir, match, strlen(match));
|
|
|
|
ent->ignored = 1;
|
|
|
|
if (S_ISDIR(st.st_mode))
|
|
|
|
ent->ignored_dir = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2006-05-18 00:23:19 +04:00
|
|
|
die("pathspec '%s' did not match any files", match);
|
|
|
|
}
|
2006-05-17 20:33:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_directory(struct dir_struct *dir, const char **pathspec)
|
|
|
|
{
|
|
|
|
const char *path, *base;
|
|
|
|
int baselen;
|
|
|
|
|
|
|
|
/* Set up the default git porcelain excludes */
|
|
|
|
memset(dir, 0, sizeof(*dir));
|
|
|
|
dir->exclude_per_dir = ".gitignore";
|
|
|
|
path = git_path("info/exclude");
|
|
|
|
if (!access(path, R_OK))
|
|
|
|
add_excludes_from_file(dir, path);
|
2007-02-28 06:31:10 +03:00
|
|
|
if (!access(excludes_file, R_OK))
|
|
|
|
add_excludes_from_file(dir, excludes_file);
|
2006-05-17 20:33:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate common prefix for the pathspec, and
|
|
|
|
* use that to optimize the directory walk
|
|
|
|
*/
|
|
|
|
baselen = common_prefix(pathspec);
|
|
|
|
path = ".";
|
|
|
|
base = "";
|
|
|
|
if (baselen) {
|
|
|
|
char *common = xmalloc(baselen + 1);
|
|
|
|
memcpy(common, *pathspec, baselen);
|
|
|
|
common[baselen] = 0;
|
|
|
|
path = base = common;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the directory and prune it */
|
Optimize directory listing with pathspec limiter.
The way things are set up, you can now pass a "pathspec" to the
"read_directory()" function. If you pass NULL, it acts exactly
like it used to do (read everything). If you pass a non-NULL
pointer, it will simplify it into a "these are the prefixes
without any special characters", and stop any readdir() early if
the path in question doesn't match any of the prefixes.
NOTE! This does *not* obviate the need for the caller to do the *exact*
pathspec match later. It's a first-level filter on "read_directory()", but
it does not do the full pathspec thing. Maybe it should. But in the
meantime, builtin-add.c really does need to do first
read_directory(dir, .., pathspec);
if (pathspec)
prune_directory(dir, pathspec, baselen);
ie the "prune_directory()" part will do the *exact* pathspec pruning,
while the "read_directory()" will use the pathspec just to do some quick
high-level pruning of the directories it will recurse into.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-03-31 07:39:30 +04:00
|
|
|
read_directory(dir, path, base, baselen, pathspec);
|
2006-05-17 20:33:32 +04:00
|
|
|
if (pathspec)
|
|
|
|
prune_directory(dir, pathspec, baselen);
|
|
|
|
}
|
|
|
|
|
2007-04-20 12:39:39 +04:00
|
|
|
static void update_callback(struct diff_queue_struct *q,
|
|
|
|
struct diff_options *opt, void *cbdata)
|
|
|
|
{
|
|
|
|
int i, verbose;
|
|
|
|
|
|
|
|
verbose = *((int *)cbdata);
|
|
|
|
for (i = 0; i < q->nr; i++) {
|
|
|
|
struct diff_filepair *p = q->queue[i];
|
|
|
|
const char *path = p->one->path;
|
|
|
|
switch (p->status) {
|
|
|
|
default:
|
|
|
|
die("unexpacted diff status %c", p->status);
|
|
|
|
case DIFF_STATUS_UNMERGED:
|
|
|
|
case DIFF_STATUS_MODIFIED:
|
|
|
|
add_file_to_cache(path, verbose);
|
|
|
|
break;
|
|
|
|
case DIFF_STATUS_DELETED:
|
|
|
|
remove_file_from_cache(path);
|
2007-08-16 01:12:14 +04:00
|
|
|
cache_tree_invalidate_path(active_cache_tree, path);
|
2007-04-20 12:39:39 +04:00
|
|
|
if (verbose)
|
|
|
|
printf("remove '%s'\n", path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-12 10:42:00 +04:00
|
|
|
static void update(int verbose, const char **files)
|
2007-04-20 12:39:39 +04:00
|
|
|
{
|
|
|
|
struct rev_info rev;
|
|
|
|
init_revisions(&rev, "");
|
|
|
|
setup_revisions(0, NULL, &rev, NULL);
|
2007-05-12 10:42:00 +04:00
|
|
|
rev.prune_data = get_pathspec(rev.prefix, files);
|
2007-04-20 12:39:39 +04:00
|
|
|
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
|
|
|
|
rev.diffopt.format_callback = update_callback;
|
|
|
|
rev.diffopt.format_callback_data = &verbose;
|
|
|
|
if (read_cache() < 0)
|
|
|
|
die("index file corrupt");
|
|
|
|
run_diff_files(&rev, 0);
|
|
|
|
}
|
|
|
|
|
2007-02-28 06:31:10 +03:00
|
|
|
static int git_add_config(const char *var, const char *value)
|
|
|
|
{
|
|
|
|
if (!strcmp(var, "core.excludesfile")) {
|
|
|
|
if (!value)
|
|
|
|
die("core.excludesfile without value");
|
|
|
|
excludes_file = xstrdup(value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return git_default_config(var, value);
|
|
|
|
}
|
|
|
|
|
2006-06-06 23:51:49 +04:00
|
|
|
static struct lock_file lock_file;
|
2006-05-17 20:33:32 +04:00
|
|
|
|
2006-12-26 04:46:38 +03:00
|
|
|
static const char ignore_warning[] =
|
|
|
|
"The following paths are ignored by one of your .gitignore files:\n";
|
|
|
|
|
2006-07-29 09:44:25 +04:00
|
|
|
int cmd_add(int argc, const char **argv, const char *prefix)
|
2006-05-17 20:33:32 +04:00
|
|
|
{
|
|
|
|
int i, newfd;
|
2006-12-26 04:46:38 +03:00
|
|
|
int verbose = 0, show_only = 0, ignored_too = 0;
|
2006-05-17 20:33:32 +04:00
|
|
|
const char **pathspec;
|
|
|
|
struct dir_struct dir;
|
git-add --interactive
A script to be driven when the user says "git add --interactive"
is introduced.
When it is run, first it runs its internal 'status' command to
show the current status, and then goes into its internactive
command loop.
The command loop shows the list of subcommands available, and
gives a prompt "What now> ". In general, when the prompt ends
with a single '>', you can pick only one of the choices given
and type return, like this:
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now> 1
You also could say "s" or "sta" or "status" above as long as the
choice is unique.
The main command loop has 6 subcommands (plus help and quit).
* 'status' shows the change between HEAD and index (i.e. what
will be committed if you say "git commit"), and between index
and working tree files (i.e. what you could stage further
before "git commit" using "git-add") for each path. A sample
output looks like this:
staged unstaged path
1: binary nothing foo.png
2: +403/-35 +1/-1 git-add--interactive.perl
It shows that foo.png has differences from HEAD (but that is
binary so line count cannot be shown) and there is no
difference between indexed copy and the working tree
version (if the working tree version were also different,
'binary' would have been shown in place of 'nothing'). The
other file, git-add--interactive.perl, has 403 lines added
and 35 lines deleted if you commit what is in the index, but
working tree file has further modifications (one addition and
one deletion).
* 'update' shows the status information and gives prompt
"Update>>". When the prompt ends with double '>>', you can
make more than one selection, concatenated with whitespace or
comma. Also you can say ranges. E.g. "2-5 7,9" to choose
2,3,4,5,7,9 from the list. You can say '*' to choose
everything.
What you chose are then highlighted with '*', like this:
staged unstaged path
1: binary nothing foo.png
* 2: +403/-35 +1/-1 git-add--interactive.perl
To remove selection, prefix the input with - like this:
Update>> -2
After making the selection, answer with an empty line to
stage the contents of working tree files for selected paths
in the index.
* 'revert' has a very similar UI to 'update', and the staged
information for selected paths are reverted to that of the
HEAD version. Reverting new paths makes them untracked.
* 'add untracked' has a very similar UI to 'update' and
'revert', and lets you add untracked paths to the index.
* 'patch' lets you choose one path out of 'status' like
selection. After choosing the path, it presents diff between
the index and the working tree file and asks you if you want
to stage the change of each hunk. You can say:
y - add the change from that hunk to index
n - do not add the change from that hunk to index
a - add the change from that hunk and all the rest to index
d - do not the change from that hunk nor any of the rest to index
j - do not decide on this hunk now, and view the next
undecided hunk
J - do not decide on this hunk now, and view the next hunk
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
After deciding the fate for all hunks, if there is any hunk
that was chosen, the index is updated with the selected hunks.
* 'diff' lets you review what will be committed (i.e. between
HEAD and index).
This is still rough, but does everything except a few things I
think are needed.
* 'patch' should be able to allow splitting a hunk into
multiple hunks.
* 'patch' does not adjust the line offsets @@ -k,l +m,n @@
in the hunk header. This does not have major problem in
practice, but it _should_ do the adjustment.
* It does not have any explicit support for a merge in
progress; it may not work at all.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-11 07:55:50 +03:00
|
|
|
int add_interactive = 0;
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
2007-01-17 21:52:36 +03:00
|
|
|
if (!strcmp("--interactive", argv[i]) ||
|
|
|
|
!strcmp("-i", argv[i]))
|
git-add --interactive
A script to be driven when the user says "git add --interactive"
is introduced.
When it is run, first it runs its internal 'status' command to
show the current status, and then goes into its internactive
command loop.
The command loop shows the list of subcommands available, and
gives a prompt "What now> ". In general, when the prompt ends
with a single '>', you can pick only one of the choices given
and type return, like this:
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now> 1
You also could say "s" or "sta" or "status" above as long as the
choice is unique.
The main command loop has 6 subcommands (plus help and quit).
* 'status' shows the change between HEAD and index (i.e. what
will be committed if you say "git commit"), and between index
and working tree files (i.e. what you could stage further
before "git commit" using "git-add") for each path. A sample
output looks like this:
staged unstaged path
1: binary nothing foo.png
2: +403/-35 +1/-1 git-add--interactive.perl
It shows that foo.png has differences from HEAD (but that is
binary so line count cannot be shown) and there is no
difference between indexed copy and the working tree
version (if the working tree version were also different,
'binary' would have been shown in place of 'nothing'). The
other file, git-add--interactive.perl, has 403 lines added
and 35 lines deleted if you commit what is in the index, but
working tree file has further modifications (one addition and
one deletion).
* 'update' shows the status information and gives prompt
"Update>>". When the prompt ends with double '>>', you can
make more than one selection, concatenated with whitespace or
comma. Also you can say ranges. E.g. "2-5 7,9" to choose
2,3,4,5,7,9 from the list. You can say '*' to choose
everything.
What you chose are then highlighted with '*', like this:
staged unstaged path
1: binary nothing foo.png
* 2: +403/-35 +1/-1 git-add--interactive.perl
To remove selection, prefix the input with - like this:
Update>> -2
After making the selection, answer with an empty line to
stage the contents of working tree files for selected paths
in the index.
* 'revert' has a very similar UI to 'update', and the staged
information for selected paths are reverted to that of the
HEAD version. Reverting new paths makes them untracked.
* 'add untracked' has a very similar UI to 'update' and
'revert', and lets you add untracked paths to the index.
* 'patch' lets you choose one path out of 'status' like
selection. After choosing the path, it presents diff between
the index and the working tree file and asks you if you want
to stage the change of each hunk. You can say:
y - add the change from that hunk to index
n - do not add the change from that hunk to index
a - add the change from that hunk and all the rest to index
d - do not the change from that hunk nor any of the rest to index
j - do not decide on this hunk now, and view the next
undecided hunk
J - do not decide on this hunk now, and view the next hunk
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
After deciding the fate for all hunks, if there is any hunk
that was chosen, the index is updated with the selected hunks.
* 'diff' lets you review what will be committed (i.e. between
HEAD and index).
This is still rough, but does everything except a few things I
think are needed.
* 'patch' should be able to allow splitting a hunk into
multiple hunks.
* 'patch' does not adjust the line offsets @@ -k,l +m,n @@
in the hunk header. This does not have major problem in
practice, but it _should_ do the adjustment.
* It does not have any explicit support for a merge in
progress; it may not work at all.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-11 07:55:50 +03:00
|
|
|
add_interactive++;
|
|
|
|
}
|
|
|
|
if (add_interactive) {
|
|
|
|
const char *args[] = { "add--interactive", NULL };
|
|
|
|
|
|
|
|
if (add_interactive != 1 || argc != 2)
|
|
|
|
die("add --interactive does not take any parameters");
|
|
|
|
execv_git_cmd(args);
|
|
|
|
exit(1);
|
|
|
|
}
|
2006-05-17 20:33:32 +04:00
|
|
|
|
2007-02-28 06:31:10 +03:00
|
|
|
git_config(git_add_config);
|
2006-05-17 20:33:32 +04:00
|
|
|
|
_GIT_INDEX_OUTPUT: allow plumbing to output to an alternative index file.
When defined, this allows plumbing commands that update the
index (add, apply, checkout-index, merge-recursive, mv,
read-tree, rm, update-index, and write-tree) to write their
resulting index to an alternative index file while holding a
lock to the original index file. With this, git-commit that
jumps the index does not have to make an extra copy of the index
file, and more importantly, it can do the update while holding
the lock on the index.
However, I think the interface to let an environment variable
specify the output is a mistake, as shown in the documentation.
If a curious user has the environment variable set to something
other than the file GIT_INDEX_FILE points at, almost everything
will break. This should instead be a command line parameter to
tell these plumbing commands to write the result in the named
file, to prevent stupid mistakes.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-01 10:09:02 +04:00
|
|
|
newfd = hold_locked_index(&lock_file, 1);
|
2006-05-17 20:33:32 +04:00
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
const char *arg = argv[i];
|
|
|
|
|
|
|
|
if (arg[0] != '-')
|
|
|
|
break;
|
|
|
|
if (!strcmp(arg, "--")) {
|
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!strcmp(arg, "-n")) {
|
|
|
|
show_only = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2006-12-26 04:46:38 +03:00
|
|
|
if (!strcmp(arg, "-f")) {
|
|
|
|
ignored_too = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2006-05-17 20:33:32 +04:00
|
|
|
if (!strcmp(arg, "-v")) {
|
|
|
|
verbose = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2007-04-20 12:39:39 +04:00
|
|
|
if (!strcmp(arg, "-u")) {
|
2007-05-12 10:42:00 +04:00
|
|
|
take_worktree_changes = 1;
|
2007-04-20 12:39:39 +04:00
|
|
|
continue;
|
|
|
|
}
|
2006-08-03 19:48:41 +04:00
|
|
|
usage(builtin_add_usage);
|
2006-05-17 20:33:32 +04:00
|
|
|
}
|
2007-04-20 12:39:39 +04:00
|
|
|
|
2007-05-12 10:42:00 +04:00
|
|
|
if (take_worktree_changes) {
|
|
|
|
update(verbose, argv + i);
|
2007-04-20 12:39:39 +04:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2006-12-21 00:06:46 +03:00
|
|
|
if (argc <= i) {
|
|
|
|
fprintf(stderr, "Nothing specified, nothing added.\n");
|
|
|
|
fprintf(stderr, "Maybe you wanted to say 'git add .'?\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2006-05-17 20:33:32 +04:00
|
|
|
pathspec = get_pathspec(prefix, argv + i);
|
|
|
|
|
|
|
|
fill_directory(&dir, pathspec);
|
|
|
|
|
|
|
|
if (show_only) {
|
|
|
|
const char *sep = "", *eof = "";
|
|
|
|
for (i = 0; i < dir.nr; i++) {
|
2006-12-29 22:01:31 +03:00
|
|
|
if (!ignored_too && dir.entries[i]->ignored)
|
2006-12-26 04:46:38 +03:00
|
|
|
continue;
|
2006-05-17 20:33:32 +04:00
|
|
|
printf("%s%s", sep, dir.entries[i]->name);
|
|
|
|
sep = " ";
|
|
|
|
eof = "\n";
|
|
|
|
}
|
|
|
|
fputs(eof, stdout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-04 19:13:39 +03:00
|
|
|
if (read_cache() < 0)
|
|
|
|
die("index file corrupt");
|
|
|
|
|
2006-12-26 04:46:38 +03:00
|
|
|
if (!ignored_too) {
|
2006-12-29 22:01:31 +03:00
|
|
|
int has_ignored = 0;
|
|
|
|
for (i = 0; i < dir.nr; i++)
|
|
|
|
if (dir.entries[i]->ignored)
|
|
|
|
has_ignored = 1;
|
|
|
|
if (has_ignored) {
|
2006-12-26 04:46:38 +03:00
|
|
|
fprintf(stderr, ignore_warning);
|
2006-12-29 22:01:31 +03:00
|
|
|
for (i = 0; i < dir.nr; i++) {
|
|
|
|
if (!dir.entries[i]->ignored)
|
2006-12-26 04:46:38 +03:00
|
|
|
continue;
|
2006-12-29 22:01:31 +03:00
|
|
|
fprintf(stderr, "%s", dir.entries[i]->name);
|
|
|
|
if (dir.entries[i]->ignored_dir)
|
|
|
|
fprintf(stderr, " (directory)");
|
|
|
|
fputc('\n', stderr);
|
2006-12-26 04:46:38 +03:00
|
|
|
}
|
|
|
|
fprintf(stderr,
|
|
|
|
"Use -f if you really want to add them.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-17 20:33:32 +04:00
|
|
|
for (i = 0; i < dir.nr; i++)
|
2007-04-02 09:14:40 +04:00
|
|
|
add_file_to_cache(dir.entries[i]->name, verbose);
|
2006-05-17 20:33:32 +04:00
|
|
|
|
2007-04-20 12:39:39 +04:00
|
|
|
finish:
|
2006-05-17 20:33:32 +04:00
|
|
|
if (active_cache_changed) {
|
|
|
|
if (write_cache(newfd, active_cache, active_nr) ||
|
_GIT_INDEX_OUTPUT: allow plumbing to output to an alternative index file.
When defined, this allows plumbing commands that update the
index (add, apply, checkout-index, merge-recursive, mv,
read-tree, rm, update-index, and write-tree) to write their
resulting index to an alternative index file while holding a
lock to the original index file. With this, git-commit that
jumps the index does not have to make an extra copy of the index
file, and more importantly, it can do the update while holding
the lock on the index.
However, I think the interface to let an environment variable
specify the output is a mistake, as shown in the documentation.
If a curious user has the environment variable set to something
other than the file GIT_INDEX_FILE points at, almost everything
will break. This should instead be a command line parameter to
tell these plumbing commands to write the result in the named
file, to prevent stupid mistakes.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-01 10:09:02 +04:00
|
|
|
close(newfd) || commit_locked_index(&lock_file))
|
2006-05-17 20:33:32 +04:00
|
|
|
die("Unable to write new index file");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|