Skip to content

fix #896: pushd dash family follows GNU option walk - #901

Merged
caomengxuan666 merged 2 commits into
masterfrom
arookieofc/fix-896-pushd-dashes
Oct 20, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
arookieofc/fix-896-pushd-dashes

Conversation

@arookieofc

Copy link
Copy Markdown
Member

Fixes #896 (from #889 CR).

Leading -- now sets skipopt (pushd.def:183-190), lone - is cd $OLDPWD (pushd.def:223-225, cd.def:339-349), option-only lists are silent no-ops (pushd.def:288), and multi-word Dir operands are too many arguments rc 1 via CD_COMPLAINS (cd.def:326-330, config-top.h).

Full matrix probed byte-identical vs WSL GNU bash 5.3.0 script files. New tests/issue896_pushd_dashes_regressions.rs (9 tests); issue509/830/844_848 green; issue754 and executor part_025 each have one pre-existing env failure (missing ls binary / PWD drive-case).

Follow-up noted in commit message: walk-past-+-N (pushd +1 -n silent NOCD rotation, pushd +1 +9 inline range error) stays pre-existing behavior.

Root cause: parse_pushd_operand treated a leading `--` as an ordinary
options skip and `-` as a malformed number, and mapped option-only
argument lists to the no-argument swap.

GNU spec (third_party/bash, 5.3 patch 15):
- pushd.def:183-190 leading `--` sets skipopt, skips the walk entirely;
  the rest goes verbatim to cd_builtin (orig_list).
- pushd.def:214-260 walk: `-n` (NOCD), `--` (break, rest verbatim),
  lone `-` (break as Dir operand), else break.
- pushd.def:288 list==0 after the walk is silent EXECUTION_SUCCESS.
- pushd.def:298 Dir path delegates to cd_builtin; cd.def:326-330
  CD_COMPLAINS (config-top.h) rejects multi-word lists with
  `too many arguments` (no usage), mapped to EXECUTION_FAILURE (:310-315).
- Lone `-` is `cd -`: cd.def:339-349 OLDPWD arm, LCD_PRINTPATH echo of
  the raw value on success only (:371-374).

Behavior (all probed byte-identical vs WSL GNU bash 5.3.0 script files):
- `pushd -- -n` -> `pushd: -n: No such file` rc 1 (was usage rc 2).
- `pushd -` -> OLDPWD echo + stack rc 0; unset OLDPWD -> `OLDPWD not
  set` rc 1; empty OLDPWD -> empty echo + no-op success rc 0.
- `pushd -n` / `pushd -n --` alone -> silent rc 0 (was swap).
- `pushd /tmp extra`, `pushd -- -n extra`, `pushd - -n`,
  `pushd "" extra` -> `pushd: too many arguments` rc 1, no usage.
- `pushd -n -- +1` pushes a literal `+1`; `pushd -- +1`/`-- --`
  are cd failures; `pushd --` alone still swaps.

Tests: tests/issue896_pushd_dashes_regressions.rs (9 tests); re-verified
issue509 (3), issue754 (11/12, one pre-existing ls-missing env
failure), issue830 (9), issue844_848 (12), executor part_025 (12/13,
one pre-existing PWD-case env failure).

Follow-up (out of scope, same walk, pre-existing): `pushd +1 -n`
should be a silent NOCD rotation and `pushd +1 +9` an inline range
error - the walk currently stops at the first +/-N operand.
@github-actions

Copy link
Copy Markdown
Contributor

欢迎!这是你的第一个 PR 🎉 请确认已跑过本地测试套件;CI 通过后维护者会 review。

…dash family

PR #889 fixed rubash#859 (pushd -n silent no-op) while this branch fixed
rubash#896 (full dash family). The #896 superset already contains the #859
behavior; resolution keeps the #896 option walk verbatim and adopts the
merged NoOp spelling. pushd.def:288-291, cd.def:326-330.
@caomengxuan666

Copy link
Copy Markdown
Member

独立评审结论:APPROVE

(独立评审代理,自建 worktree @ 971cfd3 + 53997eb 两分支复核;oracle = WSL GNU bash 5.3.0(1) /usr/local/bin/bash,脚本文件批量探针 + CREATE_NO_WINDOW 运行器。)

票面两形(#896)——双侧逐字节一致

形 GNU 5.3.0(1) 本 PR 一致
pushd -- -n rc 1,pushd: -n: No such file or directory,无 usage 同 ✅
pushd -(OLDPWD=d1) 回显原值 d1,压栈,rc 0 同 ✅
pushd -(unset OLDPWD) rc 1,pushd: OLDPWD not set 同 ✅
pushd -(陈旧 OLDPWD) rc 1,原值名报错、无回显 同 ✅
pushd -(OLDPWD 空串) 空回现行 + 压 cwd,rc 0 同 ✅

对照 vendored bash-5.3 源核过语义:leading -- 置 skipopt(pushd.def:183-190)、裸 - 断出 option walk(:223-225)、list == 0 静默(:288)、cd_builtin 委派(:298)、CD_COMPLAINS(cd.def:326-330,EX_USAGE 2 被 pushd 归一为 rc 1)——实现与源逐条对得上。

矩阵 34 形——stdout 全等,stderr 18/18 消息体全等(仅沙箱根路径掩码)

覆盖:-- 单独 swap、-- --、-n/-n --/-n -n 空栈与有栈静默、NOCD 原样压(-n -- +1/-n -- -n/-n -)、too many arguments ×5(含 "" extra、- -n、-- -n extra、d1 d2)、+q/-x invalid number + usage rc 2(#509 形不回退)、+1 旋转、+9/-1 越界 directory stack empty、null directory、readonly PWD(bindpwd 判 PWD: readonly variable rc 1)、dirs 一致。

回归

已知预存(非本 PR 引入,commit message 已注 follow-up)

pushd +1 -n(GNU 静默 NOCD 旋转 vs 本树旋转并打印)与 pushd +1 +9(GNU walk 内联越界报错 vs 本树忽略余词)——master 二进制与 PR 行为逐字节相同,确认预存。建议按 commit 备注 另立票。

非阻塞观察:Dir 路径(含新 - 解析)不走 CDPATH/cdable_vars,与既有兄弟路径同类预存限制,GNU cd - 相对 OLDPWD 会查 CDPATH;可留待家族票。

结论:APPROVE,不合入(留维护者操作)。

@caomengxuan666
caomengxuan666 merged commit 62a30ab into master Oct 20, 2026
6 checks passed
@caomengxuan666
caomengxuan666 deleted the arookieofc/fix-896-pushd-dashes branch October 21, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pushd 边角两分歧(#889 CR 记录):pushd -- -n GNU cd 失败 rc 1 vs rubash usage rc 2;pushd - 疑似同族

2 participants