Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/shell/builtin/mv.zig
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ pub fn parseFlag(this: *Mv, flag: []const u8) union(enum) { continue_parsing, do
if (flag[0] != '-') return .done;

const small_flags = flag[1..];
for (small_flags) |char| {
for (small_flags, 0..) |char, i| {
switch (char) {
'f' => {
this.opts.force_overwrite = true;
Expand All @@ -471,7 +471,7 @@ pub fn parseFlag(this: *Mv, flag: []const u8) union(enum) { continue_parsing, do
this.opts.verbose_output = true;
},
else => {
return .{ .illegal_option = "-" };
return .{ .illegal_option = small_flags[i..][0..1] };
},
}
}
Expand Down
27 changes: 27 additions & 0 deletions test/regression/issue/26749.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { $ } from "bun";
import { expect, test } from "bun:test";

// https://github.com/oven-sh/bun/issues/26749
// mv command should report the correct illegal option character in error messages

const cases: [string, string][] = [
["-T", "T"],
["-X", "X"],
["-fX", "X"],
["-vZ", "Z"],
];

test.each(cases)("mv reports correct illegal option for %s", async (flag, expectedChar) => {
$.throws(true);
try {
await Bun.$`mv ${flag} ./a ./b`;
expect.unreachable("should have thrown");
} catch (e: unknown) {
const err = e as Bun.$.ShellError;
const stderr = new TextDecoder().decode(err.stderr);
expect(stderr).toContain(`mv: illegal option -- ${expectedChar}`);
expect(err.exitCode).not.toBe(0);
} finally {
$.nothrow();
}
});