#10515

forgotten workspaces should not be implicitly auto-added

Opendrieberopened 2d ago

Description

Steps to Reproduce the Problem

$ mkdir myrepo
$ cd myrepo
$ jj git init
Initialized repo in "."

$ jj describe -m foo
Working copy  (@) now at: olonxppu 09b705f1699f3c (empty) foo
Parent commit (@-)      : zzzzzzzz 00000000000000 (empty) (no description set)

$ jj workspace list
default: . olonxppu 09b705f1699f3c (empty) foo

$ jj workspace add ../ws1
Created Git worktree for the new workspace.
Created workspace in "../ws1"
Working copy  (@) now at: tnyuktkm 51ed44efd5f3ff (empty) (no description set)
Parent commit (@-)      : zzzzzzzz 00000000000000 (empty) (no description set)

$ jj workspace list
default: . olonxppu 09b705f1699f3c (empty) foo
ws1: ../ws1 tnyuktkm 51ed44efd5f3ff (empty) (no description set)

### Forget the workspace:

$ jj workspace forget ws1
Removed Git worktree for "/exp2/ws1".

$ jj workspace list
default: . olonxppu 09b705f1699f3c (empty) foo

### cd to the forgotten workspace

$ cd ../ws1

$ jj workspace list
default: ../myrepo olonxppu 09b705f1699f3c (empty) foo

### jj log in the forgotten workspace succeeds... It is debatable whether this should instead fail.

$ jj log
◆  olonxppu bob@gmail.com 2026-10-28 11:25:43.000 -07:00 09b705f1699f3c
│  (empty) foo
◆  zzzzzzzz root() 00000000000000

### workspace ws1 was forgotten so it does not show up in workspace list, as expected

$ jj workspace list
default: ../myrepo olonxppu 09b705f1699f3c (empty) foo

### `jj new -r @` inside the forgotten workspace fails

$ jj new
Error: Workspace `ws1` doesn't have a working-copy commit

### BUG BUG BUG: `jj new -r o` inside the forgotten workspace does work AND it
### implicitly re-adds the forgotten workspace

$ jj new -r o
Working copy  (@) now at: sttwwysu 54e576408de5bc (empty) (no description set)
Parent commit (@-)      : olonxppu 09b705f1699f3c (empty) foo

### This shows that ws1 was implicitly re-added to the repo.

$ jj workspace list
default: ../myrepo olonxppu 09b705f1699f3c (empty) foo
ws1: . sttwwysu 54e576408de5bc (empty) (no description set)

$ cd ../myrepo

$ jj workspace list
default: . olonxppu 09b705f1699f3c (empty) foo
ws1: ../ws1 sttwwysu 54e576408de5bc (empty) (no description set)

Expected Behavior

A forgotten workspace should never be implicitly re-added to a repo. Instead, there should be a command to explicitly re-add it. As workspace management becomes more mature in jj this bug becomes more important.

Related: as mentioned in the repro steps above jj log succeeds in the forgotten workspace... I would argue it should instead fail. I wonder if this could lead to some sort of security issue? config issue? unnecessary complexity?

Actual Behavior

The workspace gets implicitly re-added to the repo (internally it gets re-registered with the WorkspaceStore).

Specifications

  • Version: 0.46

Activity

2
PhilipMetzger2d ago

cc @martinvonz and @joshka since that came up a while ago.

drieber1d ago

There was a discussion about this on discord around this message: https://discord.com/channels/968932220549103686/969291218347524238/1543024166297673778