martinvonz / jj

A Git-compatible VCS that is both simple and powerful
https://martinvonz.github.io/jj/
Apache License 2.0
8.23k stars 274 forks source link

FR: Allow renaming of existing workspaces #4342

Open seh opened 2 weeks ago

seh commented 2 weeks ago

Motivation

The jj workspace add accepts a --name flag to specify a name other than the basename of the directory. If I create a workspace without passing the --name, or I do so but later decide that I no longer like that name, I'd like to be able to rename the existing workspace.

The purpose that this workspace serves may change over time, or my preferred way of remembering it may change, but at present I have to create a new workspace in order to get one with the name that I desire.

Proposed Solution

Consider introducing a jj workspace rename command that requires two names: the existing workspace name and the proposed workspace name. jj could treat the two names being equal as acceptable, requiring no further action, or it could reject such an invocation.

jj would also have to ensure that no workspace already exists with the proposed workspace name.

Alternatives Considered

It's possible to use jj workspace forget and then jj workspace add—or even skip the "forgetting" step altogether—to wind up with a workspace with the desired name, assuming that one doesn't mind placing this new workspace in different directory than an existing workspace.

The proposed subcommand may be too specific. I considered whether jj workspace edit might be useful, accepting flags like --new-name to specify how one wishes to edit an existing workspace. However, there aren't enough facets of a workspace today to warrant this generality.

Context

I first asked about this capability gap in the "questions" channel of the "JJ" Discord server.

joyously commented 2 weeks ago

Would this affect the copy/tracking at all?

martinvonz commented 2 weeks ago

Would this affect the copy/tracking at all?

No. It just changes the name/id of the workspace.

kevincliao commented 1 day ago

Thanks for the detailed requirements :)

I just sent a PR that adds support for jj workspace rename <new_workspace_name>. It only supports renaming the current workspace, and not any workspace. The reason for that is because, afaik, jj internally does not store the absolute path to workspaces, so it's only possible to rename the one you're in. Note that you can still do something like jj -R <path_to_the_workspace_to_rename> workspace rename <new_workspace_name>