Skip to content

Commit 27ee189

Browse files
committed
Merge branch 'maint'
* maint: git-am -i: report rewritten title git grep shows the same hit repeatedly for unmerged paths Do check_repository_format() early (re-fix) Do check_repository_format() early Add missing inside_work_tree setting in setup_git_directory_gently
2 parents 3b78959 + f23272f commit 27ee189

File tree

4 files changed

+86
-13
lines changed

4 files changed

+86
-13
lines changed

builtin-grep.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,12 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
343343
memcpy(name + 2, ce->name, len + 1);
344344
}
345345
argv[argc++] = name;
346-
if (argc < MAXARGS)
347-
continue;
348-
status = flush_grep(opt, argc, nr, argv, &kept);
349-
if (0 < status)
350-
hit = 1;
351-
argc = nr + kept;
346+
if (MAXARGS <= argc) {
347+
status = flush_grep(opt, argc, nr, argv, &kept);
348+
if (0 < status)
349+
hit = 1;
350+
argc = nr + kept;
351+
}
352352
if (ce_stage(ce)) {
353353
do {
354354
i++;

git-am.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ It does not apply to blobs recorded in its index."
117117
unset GITHEAD_$his_tree
118118
}
119119

120+
reread_subject () {
121+
git stripspace <"$1" | sed -e 1q
122+
}
123+
120124
prec=4
121125
dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
122126
resolvemsg= resume=
@@ -376,6 +380,7 @@ do
376380
[aA]*) action=yes interactive= ;;
377381
[nN]*) action=skip ;;
378382
[eE]*) git_editor "$dotest/final-commit"
383+
SUBJECT=$(reread_subject "$dotest/final-commit")
379384
action=again ;;
380385
[vV]*) action=again
381386
LESS=-S ${PAGER:-less} "$dotest/patch" ;;

setup.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,22 @@ void setup_work_tree(void)
222222
initialized = 1;
223223
}
224224

225+
static int check_repository_format_gently(int *nongit_ok)
226+
{
227+
git_config(check_repository_format_version);
228+
if (GIT_REPO_VERSION < repository_format_version) {
229+
if (!nongit_ok)
230+
die ("Expected git repo version <= %d, found %d",
231+
GIT_REPO_VERSION, repository_format_version);
232+
warning("Expected git repo version <= %d, found %d",
233+
GIT_REPO_VERSION, repository_format_version);
234+
warning("Please upgrade Git");
235+
*nongit_ok = -1;
236+
return -1;
237+
}
238+
return 0;
239+
}
240+
225241
/*
226242
* We cannot decide in this function whether we are in the work tree or
227243
* not, since the config can only be read _after_ this function was called.
@@ -246,8 +262,15 @@ const char *setup_git_directory_gently(int *nongit_ok)
246262
static char buffer[1024 + 1];
247263
const char *retval;
248264

249-
if (!work_tree_env)
250-
return set_work_tree(gitdirenv);
265+
if (!work_tree_env) {
266+
retval = set_work_tree(gitdirenv);
267+
/* config may override worktree */
268+
if (check_repository_format_gently(nongit_ok))
269+
return NULL;
270+
return retval;
271+
}
272+
if (check_repository_format_gently(nongit_ok))
273+
return NULL;
251274
retval = get_relative_cwd(buffer, sizeof(buffer) - 1,
252275
get_git_work_tree());
253276
if (!retval || !*retval)
@@ -286,6 +309,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
286309
if (!work_tree_env)
287310
inside_work_tree = 0;
288311
setenv(GIT_DIR_ENVIRONMENT, ".", 1);
312+
check_repository_format_gently(nongit_ok);
289313
return NULL;
290314
}
291315
chdir("..");
@@ -306,6 +330,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
306330
if (!work_tree_env)
307331
inside_work_tree = 1;
308332
git_work_tree_cfg = xstrndup(cwd, offset);
333+
if (check_repository_format_gently(nongit_ok))
334+
return NULL;
309335
if (offset == len)
310336
return NULL;
311337

@@ -356,11 +382,7 @@ int check_repository_format_version(const char *var, const char *value)
356382

357383
int check_repository_format(void)
358384
{
359-
git_config(check_repository_format_version);
360-
if (GIT_REPO_VERSION < repository_format_version)
361-
die ("Expected git repo version <= %d, found %d",
362-
GIT_REPO_VERSION, repository_format_version);
363-
return 0;
385+
return check_repository_format_gently(NULL);
364386
}
365387

366388
const char *setup_git_directory(void)

t/t1302-repo-version.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2007 Nguyễn Thái Ngọc Duy
4+
#
5+
6+
test_description='Test repository version check'
7+
8+
. ./test-lib.sh
9+
10+
cat >test.patch <<EOF
11+
diff --git a/test.txt b/test.txt
12+
new file mode 100644
13+
--- /dev/null
14+
+++ b/test.txt
15+
@@ -0,0 +1 @@
16+
+123
17+
EOF
18+
19+
test_create_repo "test"
20+
test_create_repo "test2"
21+
22+
GIT_CONFIG=test2/.git/config git config core.repositoryformatversion 99 || exit 1
23+
24+
test_expect_success 'gitdir selection on normal repos' '
25+
(test "$(git config core.repositoryformatversion)" = 0 &&
26+
cd test &&
27+
test "$(git config core.repositoryformatversion)" = 0)'
28+
29+
# Make sure it would stop at test2, not trash
30+
test_expect_success 'gitdir selection on unsupported repo' '
31+
(cd test2 &&
32+
test "$(git config core.repositoryformatversion)" = 99)'
33+
34+
test_expect_success 'gitdir not required mode' '
35+
(git apply --stat test.patch &&
36+
cd test && git apply --stat ../test.patch &&
37+
cd ../test2 && git apply --stat ../test.patch)'
38+
39+
test_expect_success 'gitdir required mode on normal repos' '
40+
(git apply --check --index test.patch &&
41+
cd test && git apply --check --index ../test.patch)'
42+
43+
test_expect_failure 'gitdir required mode on unsupported repo' '
44+
(cd test2 && git apply --check --index ../test.patch)'
45+
46+
test_done

0 commit comments

Comments
 (0)