Skip to content

Commit 9bf5142

Browse files
committed
Do not auto-create .taskrc when stdout is not a TTY
This avoids prompting or automatically creating such a file, both of which are unexpected when performing command-line completion. Fixes #3751.
1 parent f6824e9 commit 9bf5142

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Context.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,13 @@ void Context::staticInitialization() {
11731173
void Context::createDefaultConfig() {
11741174
// Do we need to create a default rc?
11751175
if (rc_file._data != "" && !rc_file.exists()) {
1176+
// If stdout is not a file, we are probably executing in a completion context and should not
1177+
// prompt (as the user won't see it) or modify the config (as completion functions are typically
1178+
// read-only).
1179+
if (!isatty(STDOUT_FILENO)) {
1180+
throw std::string("Cannot proceed without rc file.");
1181+
}
1182+
11761183
if (config.getBoolean("confirmation") &&
11771184
!confirm(format("A configuration file could not be found in {1}\n\nWould you like a sample "
11781185
"{2} created, so Taskwarrior can proceed?",

0 commit comments

Comments
 (0)