Skip to content

feat(promote): complete pending promotion files#15338

Draft
Alizter wants to merge 2 commits into
ocaml:mainfrom
Alizter:push-yymmwpnuxoup
Draft

feat(promote): complete pending promotion files#15338
Alizter wants to merge 2 commits into
ocaml:mainfrom
Alizter:push-yymmwpnuxoup

Conversation

@Alizter

@Alizter Alizter commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

dune promote <TAB> now completes against the entries in the build dir's .to-promote db instead of falling back to no completion at all.

Adds a promote_file cmdliner conv in bin/promotion.ml whose completion func takes Common.Builder.term as the cmdliner context, runs Common.init to set up the workspace exactly as the run path does (so --root and --build-dir are honoured rather than hardcoded), and emits sorted cwd-relative paths via Path.reach so candidates display the same way the user would type them.

Adds a dune_complete helper in test/blackbox-tests/setup-script.sh that drives the --__complete protocol and filters the Values group, along with cram coverage for empty/prefix/no-match tokens, the outside-workspace case, --build-dir, and --root (via dune promotion apply, since the dune promote alias currently uses Common.No_build.term and so doesn't accept --root).

@Alizter Alizter force-pushed the push-yymmwpnuxoup branch 2 times, most recently from 2eb5185 to 29ed71c Compare June 26, 2026 12:24
@Alizter Alizter requested a review from ElectreAAS June 26, 2026 12:25
@Alizter Alizter force-pushed the push-yymmwpnuxoup branch 3 times, most recently from 70f6fab to c1b5fe8 Compare June 26, 2026 12:59
@ElectreAAS

Copy link
Copy Markdown
Collaborator

Tested locally on bash and zsh and it doesn't seem to work, is there some additional setup needed to get this working?

@Alizter

Alizter commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator Author

@ElectreAAS There should be no additional setup needed. The usual setup from #14779 should be enough. For dune promote to give you suggestions however, you will need something to promote. Something like misformatting a file and running dune build @fmt should be enough.

@Alizter Alizter force-pushed the push-yymmwpnuxoup branch from c1b5fe8 to e99306b Compare June 29, 2026 09:38
@ElectreAAS

Copy link
Copy Markdown
Collaborator

We tested this today, and a problem that popped up is the following:
dune promote doesn't recognize (and thus complete) all the common flags (whereas dune promotion apply does), which is annoying.
This is more annoying because of a different problem: if the binary called isn't dune (but _boot/dune.exe for us), completion doesn't kick in at all

@ElectreAAS

Copy link
Copy Markdown
Collaborator

dune promote doesn't recognize (and thus complete) all the common flags (whereas dune promotion apply does), which is annoying.

I think I've found the culprit for this: #6160 (comment) :)

@Alizter Alizter force-pushed the push-yymmwpnuxoup branch from e99306b to cf73d01 Compare July 1, 2026 12:35
@Alizter

Alizter commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

This is more annoying because of a different problem: if the binary called isn't dune (but _boot/dune.exe for us), completion doesn't kick in at all

This one actually has an easy fix on bash:

$ eval "$(_boot/dune.exe completion bash)"
$ complete -F _dune_cmdliner _boot/dune.exe

will allow it to work with any binary name you want. We should document this in the man page and work out what needs to be done for the other shells.

@Alizter

Alizter commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

dune promote doesn't recognize (and thus complete) all the common flags (whereas dune promotion apply does), which is annoying.

I think that the bug is really that dune promotion apply even accepts these flags. It should have the same term as dune promote. However it shouldn't affect this PR.

Comment thread bin/promotion.ml Outdated
Comment thread test/blackbox-tests/test-cases/completion/promote.t Outdated
@Alizter Alizter requested a review from ElectreAAS July 6, 2026 11:02
@Alizter Alizter force-pushed the push-yymmwpnuxoup branch from cf73d01 to 5a13ff0 Compare July 6, 2026 11:47
@Alizter Alizter marked this pull request as draft July 6, 2026 11:48
@Alizter Alizter force-pushed the push-yymmwpnuxoup branch from 5a13ff0 to e511dd9 Compare July 6, 2026 11:52
…ands

Promotion subcommands (apply/diff/list/show) don't build anything: they
read the [.to-promote] db and copy files between the build dir and the
source tree. Adopt the canonical shape for "workspace-aware, non-building,
may-fire-RPC" commands used by ~15 other commands (rpc/*, pkg/*, monitor,
merlin, install, etc.):

  let common, config =
    builder
    |> Common.Builder.forbid_builds
    |> Common.Builder.disable_log_file
    |> Common.init

- `forbid_builds` tells `Common.init` to skip the RPC-with-builds server
  setup and suppresses "Entering directory" messages.
- `disable_log_file` skips the trace-file init that would otherwise
  acquire the global build-dir lock and mkdir `_build/` as a side effect
  (which broke tab-completion in workspaces without a `_build/` dir).

Also removes the one-off `Common.Builder.set_no_build` helper, which was
added specifically for `Apply.promote_term` (the alias for `dune promote`)
and had no other callers. The alias now uses `Apply.term` directly, and
both `dune promote` and `dune promotion apply` share the same wide CLI
surface (`--root`, `--build-dir`, `--trace-file`, ...) matching what
`dune promotion apply` already accepted.

Signed-off-by: Ali Caglayan <alizter@gmail.com>
@Alizter Alizter force-pushed the push-yymmwpnuxoup branch from e511dd9 to d842c19 Compare July 6, 2026 15:22
`dune promote <TAB>` now completes against the entries in the build dir's
`.to-promote` db instead of falling back to no completion at all.

Adds a `promote_file` cmdliner conv in `bin/promotion.ml` whose completion
func takes `Common.Builder.term` as the cmdliner context, runs the same
`init_no_build` the runtime does (so `--root`, `--build-dir` etc. are
honoured, and there's no `_build/` mkdir or trace-file rewrite per tab),
and emits sorted cwd-relative paths via `Path.reach` so candidates display
the same way the user would type them.

Adds a `dune_complete` helper in `test/blackbox-tests/setup-script.sh` that
drives the `--__complete` protocol and filters the Values group, along with
cram coverage for empty/prefix/no-match tokens, already-typed positional
args, `--build-dir`, and `--root`.

Signed-off-by: Ali Caglayan <alizter@gmail.com>
@Alizter Alizter force-pushed the push-yymmwpnuxoup branch from d842c19 to 1e9a93e Compare July 6, 2026 15:25
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.

shell completion for dune promote

2 participants