Skip to content

Commit aae94ff

Browse files
bebarinogitster
authored andcommitted
commit: -F overrides -t
Commit dbd0f5c (Files given on the command line are relative to $cwd, 2008-08-06) introduced parse_options_fix_filename() as a quick fix for filename arguments used in the parse options API. git-commit was still broken. This means git commit -F log -t temp in a subdirectory would make git think the log message should be taken from temp instead of log. This is because parse_options_fix_filename() calls prefix_filename() which uses a single static char buffer to do its work. Making two calls with two char pointers causes the pointers to alias. To prevent aliasing, we duplicate the string returned by parse_options_fix_filename(). Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2131951 commit aae94ff

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

builtin-commit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,11 @@ static int parse_and_validate_options(int argc, const char *argv[],
699699

700700
argc = parse_options(argc, argv, builtin_commit_options, usage, 0);
701701
logfile = parse_options_fix_filename(prefix, logfile);
702+
if (logfile)
703+
logfile = xstrdup(logfile);
702704
template_file = parse_options_fix_filename(prefix, template_file);
705+
if (template_file)
706+
template_file = xstrdup(template_file);
703707

704708
if (force_author && !strchr(force_author, '>'))
705709
force_author = find_author_by_nickname(force_author);

t/t7500-commit.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,14 @@ test_expect_success 'commit message from stdin' '
183183
commit_msg_is "Log with foo word"
184184
'
185185

186+
test_expect_success 'commit -F overrides -t' '
187+
(
188+
cd subdir &&
189+
echo "-F log" > f.log &&
190+
echo "-t template" > t.template &&
191+
git commit --allow-empty -F f.log -t t.template
192+
) &&
193+
commit_msg_is "-F log"
194+
'
195+
186196
test_done

0 commit comments

Comments
 (0)