Fossil Forum

'branch current' returns nothing immediately after 'open --empty'

'branch current' returns nothing immediately after 'open --empty'

'branch current' returns nothing immediately after 'open --empty'

(1) By anonymous on 2019-08-27 09:53:48 [source]

Fossil command branch current returns nothing immediately after command open --empty, even though commands timeline and branch ls both mention trunk.

Command update appears to 'correct' the problem.

To reproduce, follow the steps outlined below. (Shell commands, as opposed to Fossil commands, appear between square brackets).

fossil> [ pwd ]
fossil> new foo.fossil
project-id: 6c74694c86eab2f905adcf6ff2400c5e976bf6c4
server-id:  e0dbda9182536ff76f90e4dd804b35f1f5bcf708
admin-user: sebyte (initial password is "573f58")
fossil> [ mkdir foo ]
fossil> [ cd ~/workspace/foo/ ]
fossil> open /home/sebyte/workspace/foo.fossil --empty
project-name: <unnamed>
repository:   /home/sebyte/workspace/foo.fossil
local-root:   /home/sebyte/workspace/foo/
config-db:    /home/sebyte/.fossil
project-code: 6c74694c86eab2f905adcf6ff2400c5e976bf6c4
check-ins:    1
fossil> timeline
=== 2019-08-27 ===
09:15:11 [ee330df546] initial empty check-in (user: sebyte tags: trunk)
+++ no more data (1) +++
fossil> branch ls
fossil> branch current

fossil> update
checkout:     ee330df546cf45f30acb9f572f8c5f56eb04524a 2019-08-27 09:15:11 UTC
tags:         trunk
comment:      initial empty check-in (user: sebyte)
changes:      None. Already up-to-date
fossil> branch current
fossil> version
This is fossil version 2.10 [3e183bfad8] 2019-08-21 19:18:06 UTC

Note the blank line following the first branch current.

(2) By sebyte on 2019-08-27 10:53:11 in reply to 1 [link] [source]

To clarify, the problem only occurs when the --empty flag is passed to open.

(3.1) By Stephan Beal (stephan) on 2019-08-27 11:22:53 edited from 3.0 in reply to 2 [link] [source]

When you create a repo with that flag, the repo is really empty, meaning no tags. Normally fossil creates an empty commit with a branch of "trunk", but using that flag means that you have no branches. i.e. this is the expected behavior.

Edit: nevermind - i'm confusing the "new --empty" flag. i have no idea what "open --empty" is supposed to do :/.

(5) By sebyte on 2019-08-27 12:40:39 in reply to 3.1 [link] [source]

Excerpt from help open:

  --empty    Initialize checkout as being empty, but still connected
             with the local repository. If you commit this checkout,
             it will become a new "initial" commit in the repository.

As you said, "[n]ormally fossil creates an empty commit with a branch of trunk", so branch current immediately after open --empty should say trunk, just as it does immediately after open without the --empty flag.

(4) By Florian Balmer (florian.balmer) on 2019-08-27 12:38:05 in reply to 1 [link] [source]

I think the behavior is expected.

fossil open --empty creates an empty check-out, not connected to any parents, the same as fossil init --empty would do (the --empty option was removed from the init command). This is useful to start a new (parallel) development line. Due to missing common ancestors, parallel lines can't be merged (unless the reparent command is used to link the parallel lines to the same common ancestor). Tags or branch names appearing in more than one line always resolve to the most recent of the tagged check-ins, i.e. it's important to note that they can cause switching to other parallel lines, if tags or branch names are reused on more than one line.

The special name current is a symbolic link pointing to the current check-out, thus to nothing if the repository was opened with --empty. In this case, fossil info current does not output any information about the current checkout (not found: current), and fossil branch current does not output any branch name.

However, fossil branch ls lists the branche names already in the repository, i.e. from the starting point created by fossil init (or, see below, fossil open --empty; fossil commit). And fossil timeline just displays the branch name of the initial empty check-in, which is trunk, but without the indicator that this is the current check-out (i.e. no *CURRENT*).

To have a valid current check-out for repositories opened with --empty, fossil commit needs to be called first to create a check-in, and automatically select it as the current check-out. The branch name for this check-in defaults to the value of the main-branch setting (or trunk if clear), if not specified by fossil commit --branch. Note that this check-in does not need to be empty, and does not need to have the branch name trunk.

Not sure why fossil update takes you to the initial empty check-in -- I can't reproduce this with my tests.

(6) By Florian Balmer (florian.balmer) on 2019-08-27 12:49:05 in reply to 4 [link] [source]

Not sure why fossil update takes you to the initial empty check-in -- I can't reproduce this with my tests.

Ok, now I can, if there's nothing else in the repository but the initial empty check-in created by fossil init. It seems that update simply picks the most recent check-in with the default branch name, if the current symlink does not refer to any check-in?

(7) By sebyte on 2019-09-04 08:53:26 in reply to 4 [link] [source]

Thank you for this explanation Florian. I now have a much better understanding of what open --empty does, which strikes me as quite extraordinary. Do any other VCSes offer such a facility?

(8) By Florian Balmer (florian.balmer) on 2019-09-04 10:39:31 in reply to 7 [link] [source]

Do any other VCSes offer such a facility?

I don't know, I haven't dealt with or read about other VCS deeply enough.