Repository: uutils/coreutils (language: rust)

Issue:
chroot: rejects multiple instances of --groups option but shouldn't
Environment: Ubuntu 20.04, uutils `main` branch (git commit 88cdf16fd7be8a4544fcb5860e504c101709124c), GNU coreutils v8.30.

Steps to reproduce:
```
sudo chroot --groups='invalid ignored' --groups='' / id -G
```

What happens now: the argument parsing in uutils `chroot` complains that the argument cannot be used multiple time:
```
error: the argument '--groups <GROUP1,GROUP2...>' cannot be used multiple times

Usage: ./target/debug/chroot [OPTION]... NEWROOT [COMMAND [ARG]...]

For more information, try '--help'.
```

What I expected to happen: GNU `chroot` takes only the last instance of `--groups` and successfully outputs the result of `id -G`:
```
0
```

Notes: this is causing a failure in the GNU test file `tests/chroot/chroot-credentials.sh`.


Discussion / hints:
Related to https://github.com/uutils/coreutils/issues/5998

Fix patch:
diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs
index f348d0c554b..4ea5db65348 100644
--- a/src/uu/chroot/src/chroot.rs
+++ b/src/uu/chroot/src/chroot.rs
@@ -254,6 +254,7 @@ pub fn uu_app() -> Command {
         .arg(
             Arg::new(options::GROUPS)
                 .long(options::GROUPS)
+                .overrides_with(options::GROUPS)
                 .help("Comma-separated list of groups to switch to")
                 .value_name("GROUP1,GROUP2..."),
         )


Test patch:
diff --git a/tests/by-util/test_chroot.rs b/tests/by-util/test_chroot.rs
index 711dd09435d..022822c6b36 100644
--- a/tests/by-util/test_chroot.rs
+++ b/tests/by-util/test_chroot.rs
@@ -53,6 +53,22 @@ fn test_no_such_directory() {
         .code_is(125);
 }
 
+#[test]
+fn test_multiple_group_args() {
+    let ts = TestScenario::new(util_name!());
+    let at = &ts.fixtures;
+    at.mkdir("id");
+
+    if let Ok(result) = run_ucmd_as_root(
+        &ts,
+        &["--groups='invalid ignored'", "--groups=''", "/", "id", "-G"],
+    ) {
+        result.success().stdout_is("0");
+    } else {
+        print!("Test skipped; requires root user");
+    }
+}
+
 #[test]
 fn test_invalid_user_spec() {
     let ts = TestScenario::new(util_name!());