pcottle/learnGitBranching · error · GitError

-r is incompatible with -d

Error message

-r is incompatible with -d

What it means

When `hg branch` is given both -d (delete) and -r (rev), the mercurial command shim throws intl.todo('-r is incompatible with -d'). Deletion of a branch cannot be combined with a revision selector in the delegated git model, so the pair is rejected up-front.

Source

Thrown at src/js/mercurial/commands.js:113

      '-r',
      '-f',
      '-d'
    ],
    delegate: function(engine, command) {
      var options = command.getOptionsMap();
      var generalArgs = command.getGeneralArgs();
      var branchName;
      var rev;

      var delegate = {vcs: 'git'};

      if (options['-m'] && options['-d']) {
        throw new GitError({
          msg: intl.todo('-m and -d are incompatible')
        });
      }
      if (options['-d'] && options['-r']) {
        throw new GitError({
          msg: intl.todo('-r is incompatible with -d')
        });
      }
      if (options['-m'] && options['-r']) {
        throw new GitError({
          msg: intl.todo('-r is incompatible with -m')
        });
      }
      if (generalArgs.length + (options['-r'] ? options['-r'].length : 0) +
          (options['-d'] ? options['-d'].length : 0) === 0) {
        delegate.name = 'branch';
        return delegate;
      }

      if (options['-d']) {
        options['-D'] = options['-d'];
        delete options['-d'];
        delegate.name = 'branch';

View on GitHub (pinned to 5b09d0ff96)

Solutions

  1. Drop -r when using -d; delete by branch name instead
  2. Validate the option combination before submitting the command

Example fix

// before
hg branch -d -r .
// after
hg branch -d branchname
Defensive patterns

Strategy: validation

Validate before calling

if (options['-d'] && options['-r']) { reject('drop -r when using -d'); }

Try / catch

try { exec(cmd); } catch (e) { if (e instanceof GitError) { showMsg(e.msg); } else throw e; }

Prevention

When it happens

Trigger: Executing `hg branch` (or the branch-shim path) with both -d and -r present in the options map.

Common situations: Transcribing real-hg command lines that permit -r with some subcommands; option-combining scripts that don't enforce exclusivity.

Related errors


AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27). Data as JSON: /api/errors/ad95e36ccb326811. Report an issue: GitHub.