#include "dir.h"
#include "gettext.h"
#include "pathspec.h"
-#include "run-command.h"
#include "object-file.h"
#include "odb.h"
#include "odb/transaction.h"
#include "diff.h"
#include "read-cache.h"
#include "revision.h"
-#include "strvec.h"
#include "submodule.h"
#include "add-interactive.h"
+#include "apply.h"
static const char * const builtin_add_usage[] = {
N_("git add [<options>] [--] <pathspec>..."),
const char *prefix)
{
char *file = repo_git_path(repo, "ADD_EDIT.patch");
- struct child_process child = CHILD_PROCESS_INIT;
+ struct apply_state state;
+ const char *apply_argv[2];
struct rev_info rev;
int out;
struct stat st;
if (!st.st_size)
die(_("empty patch. aborted"));
- child.git_cmd = 1;
- strvec_pushl(&child.args, "apply", "--recount", "--cached", file,
- NULL);
- if (run_command(&child))
+ apply_argv[0] = file;
+ apply_argv[1] = NULL;
+ if (init_apply_state(&state, repo, NULL))
+ die(_("could not initialize apply state"));
+ state.cached = 1;
+ if (check_apply_state(&state, 0))
+ die(_("could not check apply state"));
+ if (apply_all_patches(&state, 1, apply_argv, APPLY_OPT_RECOUNT))
die(_("could not apply '%s'"), file);
+ clear_apply_state(&state);
unlink(file);
free(file);
test_must_fail env GIT_EDITOR=false git add -e &&
test_expect_code 1 git diff --exit-code
'
+test_expect_success 'add -e works from a subdirectory' '
+ git reset --hard &&
+ echo change >>file &&
+ mkdir -p subdir &&
+ (
+ cd subdir &&
+ GIT_EDITOR=cat git add -e ../file
+ ) &&
+ git diff --cached | grep -q "^+change"
+'
test_done