Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Running jj workspace forget on the main workspace should make another workspace the main one. #5271

Open
umnikos opened this issue Jan 5, 2025 · 6 comments
Labels
enhancement New feature or request

Comments

@umnikos
Copy link
Contributor

umnikos commented Jan 5, 2025

Problem

It is hard to keep track of which workspace is the "main" one (the one with the git store in it). As far as I know there is no command that outputs which workspace is the main one, and jj workspace forget will let you forget the main workspace with no warning. All of this makes it easy to accidentally delete your git store (@chriskrycho can testify to that).

Proposed solution

jj workspace forget-ting the main workspace should first move its git store to another non-forgotten workspace (if there's any) before proceeding with the forgetting. Additionally a command that outputs which workspace is the main one or a command to set which workspace should become the default one would help.

Alternative solutions

The only alternative I can think of is to keep the git directory outside all of the workspaces, but I cannot think of a convenient location.

@PhilipMetzger PhilipMetzger added the enhancement New feature or request label Jan 5, 2025
@arxanas
Copy link
Contributor

arxanas commented Jan 5, 2025

What is the current behavior of forgetting the main workspace? It deletes the colocated .git directory (if present), but not the .jj directory? If so, perhaps it should "uncolocate" the Git repository in that case?

@yuja
Copy link
Contributor

yuja commented Jan 6, 2025

What is the current behavior of forgetting the main workspace?

It disassociates the current (or main) working copy from the repo. Nothing should be deleted, but the result would be a bit surprising. We can at least show a warning (with hint to jj undo.)

first move its git store to another non-forgotten workspace (if there's any) before proceeding with the forgetting.

I wouldn't expect the "main" workspace carries to random place by jj workspace forget. I also don't think it's technically possible because there may be other workspaces pointing to the current main repo directory.

fwiw, it might be better to force user to explicitly specify the workspace to forget (with @ or . as a short for the current workspace.)

@arxanas
Copy link
Contributor

arxanas commented Jan 7, 2025

All of this makes it easy to accidentally delete your git store (@chriskrycho can testify to that).

@umnikos Can you clarify how it makes it easy to accidentally delete your git store? I didn't follow.

@umnikos
Copy link
Contributor Author

umnikos commented Jan 7, 2025

@umnikos Can you clarify how it makes it easy to accidentally delete your git store? I didn't follow.

@arxanas example:

  1. The user has two workspaces, A and B. B is the main one, but the user thinks A is the main one
  2. The user wants to bring their setup back down to a single workspace
  3. They type jj workspace forget B. The command succeeds
  4. They delete workspace B
  5. Workspace A is now broken, as it was workspace B that contained the git store
~/Desktop/jj/A $ jj workspace list
A: mpluvnwn de0b4886 (empty) hi
B: qrwusylt b7d95ca3 (empty) hiii
~/Desktop/jj/A $ jj workspace forget B
~/Desktop/jj/A $ jj workspace list
A: mpluvnwn de0b4886 (empty) hi
~/Desktop/jj/A $ rm -r ../B
~/Desktop/jj/A $ jj status
Error: Cannot access /var/home/umnikos/Desktop/jj/B/.jj/repo
Caused by: No such file or directory (os error 2)
~/Desktop/jj/A $ 

@arxanas
Copy link
Contributor

arxanas commented Jan 7, 2025

I see, so it doesn't delete the Git store directly, but only enables it in certain workflows. Some other ideas:

  • Add or change a command so that it does delete the workspace for you, and then refuse to do so for the main workspace.
    • Presumably in most situations where you want to forget the workspace, you would also want to delete it? It could simplify that workflow incidentally.
    • I suppose we already have a forget/delete distinction for bookmarks, so maybe it's intuitive for some users?
  • Show a warning when forgetting the main workspace, as it may be a prelude to disaster.
    • Note that there is probably a legitimate reason to remove the working copy for the main workspace, like if you want to effectively transition to a "bare repo" kind of workflow, but the warning will probably not hurt in that case.

@martinvonz
Copy link
Member

Add or change a command so that it does delete the workspace for you, and then refuse to do so for the main workspace.

Makes sense. The main risk I see is that it would delete ignored files (which we don't normally delete).

Show a warning when forgetting the main workspace, as it may be a prelude to disaster.

That's also what Yuya suggested above. I agree with adding it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants