unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 272 forks source link

deleting the last branch in a project makes things awkward #4181

Open ceedubs opened 1 year ago

ceedubs commented 1 year ago

If you have only one branch in a project (let's say project foo and branch main) and you delete it, it's unclear how to continue to use the project.

If you try switch foo then it says that foo/main doesn't exist.

If you try branch foo/main then it will create main from your current namespace, which is likely the root of your codebase (and in my case takes ages to subsequently delete.branch).

.> project.create foo

  πŸŽ‰ I've created the project foo.

  I'll now fetch the latest version of the base Unison library...
updateRoot: 531 ms (cpu), 548 ms (system)

  🎨 Type `ui` to explore this project's code in your browser.
  πŸ”­ Discover libraries at https://share.unison-lang.org
  πŸ“– Use `help-topic projects` to learn more about projects.

  Write your first Unison code with UCM:

    1. Open scratch.u.
    2. Write some Unison code and save the file.
    3. In UCM, type `add` to save it to your new project.

  πŸŽ‰ πŸ₯³ Happy coding!
InputPattern: 619 ms (cpu), 1.78 s (system)
foo/main> branch.delete main
updateRoot: 259 ms (cpu), 270 ms (system)
InputPattern: 265 ms (cpu), 299 ms (system)
.> switch foo

  foo/main does not exist.
InputPattern: 1.82 ms (cpu), 4.56 ms (system)
.> branch foo/main
updateRoot: 16.3 ms (cpu), 27.4 ms (system)

  Done. I've created the foo/main branch from the namespace ..
InputPattern: 21.0 ms (cpu), 55.8 ms (system)
mitchellwrosen commented 1 year ago

Indeed it is awkward, but we had decided (for now) that we ought not to disallow a technically-valid state.

ceedubs commented 1 year ago

@mitchellwrosen once in this state, how would one create an empty main branch for their technically-valid project?

With some digging I found that there was a branch.empty command, but it doesn't seem that I can use it:

.> branch.empty /httpserver/main

  branch.empty (or branch.create-empty, create.empty-branch)
  Create a new empty branch.

I also think that the behavior of branch.create from a (root) namespace (not within the project) forking the root namespace into the new branch is probably never want people want/expect. But maybe that would be less of a problem if it didn't take minutes to delete the branch afterwards.

mitchellwrosen commented 1 year ago

@mitchellwrosen once in this state, how would one create an empty main branch for their technically-valid project?

Hrm... I suppose today it would have to be like

.> cd asdfkjasdf
.asdfkjasdf> branch.create-empty foo/main

:sweat_smile:

I also think that the behavior of branch.create from a (root) namespace (not within the project) forking the root namespace into the new branch is probably never want people want/expect. But maybe that would be less of a problem if it didn't take minutes to delete the branch afterwards.

Yeah, agreed. Though we are somewhat unkeen on adding too many code paths that treat the root namespace differently than all others, because we want to refactor away from having all code loaded into one namespace in the first place.