Skip to content

Commit cae3bcc

Browse files
committed
cp: -b doesn't ignore "version control" env
1 parent d56c7bb commit cae3bcc

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/uucore/src/lib/features/backup_control.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,13 @@ pub fn determine_backup_mode(matches: &ArgMatches) -> UResult<BackupMode> {
354354
}
355355
} else if matches.get_flag(arguments::OPT_BACKUP_NO_ARG) {
356356
// the short form of this option, -b does not accept any argument.
357-
// Using -b is equivalent to using --backup=existing.
358-
Ok(BackupMode::ExistingBackup)
357+
// if VERSION_CONTROL is not set then using -b is equivalent to
358+
// using --backup=existing.
359+
if let Ok(method) = env::var("VERSION_CONTROL") {
360+
match_method(&method, "$VERSION_CONTROL")
361+
} else {
362+
Ok(BackupMode::ExistingBackup)
363+
}
359364
} else {
360365
// No option was present at all
361366
Ok(BackupMode::NoBackup)
@@ -578,16 +583,16 @@ mod tests {
578583
assert_eq!(result, BackupMode::SimpleBackup);
579584
}
580585

581-
// -b ignores the "VERSION_CONTROL" environment variable
586+
// -b doesn't ignores the "VERSION_CONTROL" environment variable
582587
#[test]
583-
fn test_backup_mode_short_only_ignore_env() {
588+
fn test_backup_mode_short_doesnt_ignore_env() {
584589
let _dummy = TEST_MUTEX.lock().unwrap();
585-
env::set_var(ENV_VERSION_CONTROL, "none");
590+
env::set_var(ENV_VERSION_CONTROL, "numbered");
586591
let matches = make_app().get_matches_from(vec!["command", "-b"]);
587592

588593
let result = determine_backup_mode(&matches).unwrap();
589594

590-
assert_eq!(result, BackupMode::ExistingBackup);
595+
assert_eq!(result, BackupMode::NumberedBackup);
591596
env::remove_var(ENV_VERSION_CONTROL);
592597
}
593598

0 commit comments

Comments
 (0)