Skip to content

Commit ed342fd

Browse files
bebarinogitster
authored andcommitted
add: allow configurations to be overriden by command line
Don't call git_config after parsing the command line options, otherwise the config settings will override any settings made by the command line. This can be seen by setting add.ignore_errors and then specifying --no-ignore-errors when using git-add. Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90dce51 commit ed342fd

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

builtin-add.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ int cmd_add(int argc, const char **argv, const char *prefix)
247247
int add_new_files;
248248
int require_pathspec;
249249

250+
git_config(add_config, NULL);
251+
250252
argc = parse_options(argc, argv, builtin_add_options,
251253
builtin_add_usage, 0);
252254
if (patch_interactive)
253255
add_interactive = 1;
254256
if (add_interactive)
255257
exit(interactive_add(argc, argv, prefix));
256258

257-
git_config(add_config, NULL);
258-
259259
if (addremove && take_worktree_changes)
260260
die("-A and -u are mutually incompatible");
261261
if (addremove && !argc) {

t/t3700-add.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ test_expect_success 'git add (add.ignore-errors = false)' '
221221
test_must_fail git add --verbose . &&
222222
! ( git ls-files foo1 | grep foo1 )
223223
'
224+
rm -f foo2
225+
226+
test_expect_success '--no-ignore-errors overrides config' '
227+
git config add.ignore-errors 1 &&
228+
git reset --hard &&
229+
date >foo1 &&
230+
date >foo2 &&
231+
chmod 0 foo2 &&
232+
test_must_fail git add --verbose --no-ignore-errors . &&
233+
! ( git ls-files foo1 | grep foo1 ) &&
234+
git config add.ignore-errors 0
235+
'
236+
rm -f foo2
224237

225238
test_expect_success 'git add '\''fo\[ou\]bar'\'' ignores foobar' '
226239
git reset --hard &&

0 commit comments

Comments
 (0)