Fossil Forum

Is there an option for a "no commit enabled" checkout?
Login

Is there an option for a "no commit enabled" checkout?

Is there an option for a "no commit enabled" checkout?

(1) By anonymous on 2023-01-05 20:32:09 [source]

I had an anonymous checkout, which shouldn't submit any changes.
...but I did some change in the wrong terminal and comitted:
"The check-in was successful and is saved locally but you are not authorized to push the changes back to the server"

This ended up in a fork, which I cannot remove.
(Ok, workaround: remove current checkout and do a new clone)

Is there a simple option to prevent that?
Didn't see any readonly checkout or "no commit, if push is not allowed" setting.

The best option, that I found is with a hook:
fossil hook add --command "sh -c 'echo \"Forbidden.\"; return 1'" --type before-commit

(2.1) By Warren Young (wyoung) on 2023-01-05 20:54:08 edited from 2.0 in reply to 1 [link] [source]

I had an anonymous checkout, which shouldn't submit any changes.

That's a feature. I not only have clones of repos with local changes that I intend never to push, I've outright recommended it to others for assorted good reasons.

It wouldn't be a distributed version control system if you could prevent people with local clones to do whatever they liked with their local clone.

What you're talking about requires centralization if you want it to stick.

Didn't see any readonly checkout

If there were such a thing in Fossil, it would be a trivial matter to clear it on the local clone, landing you right back where you are now. It'd be about as secure as the old DOS "read-only" flag.

workaround: remove current checkout and do a new clone

Or, workaround 2: tag your local side of the clone as a branch so it is no longer a fork.

Or, workaround 3: mark it as a private branch so the local Fossil instance doesn't try to push it at all. (Tricky bit: do it retrospectively. I'm sure it can be done, but I don't see any UI for it currently.)

(3) By Martin Gagnon (mgagnon) on 2023-01-05 20:52:36 in reply to 1 [link] [source]

If you want to fix this after the fact (without re-cloning), you can always move your checkin to a branch (it will avoid the fork).

If you want to be sure it will never land on the remote server (let say you get permission to push later), you can make this branch private so it will never sync.

(4) By Richard Hipp (drh) on 2023-01-05 20:56:33 in reply to 2.0 [link] [source]

Yeah. But sometimes it is nice to have a "safety" that prevents write operations by mistake. Sure, you can always turn the safety off and do a write, but it is an extra step that helps to prevent errors that occur because you happened to be in the wrong terminal or ssh-ed into the wrong machine or similar.

There is already the "dont-push" setting, which if enabled prevents pushes to the remote. It wouldn't be much trouble to add a "dont-commit" setting that raises an error if you try to do a commit that you didn't really want to do.

(5) By mark on 2023-01-06 03:32:07 in reply to 1 [link] [source]

As you note, in the absence of a builtin option to prevent accidental commits, hooks are a great solution! For future accidents, however, there is an alternative to the trash-and-clone-again fix.

The following suggestion utilises an experimental command that is neither used nor recommended by most Fossil developers and comes with the following warnings:

WARNING: This command can potentially destroy historical data and leave your repository in a goofy state. Know what you are doing! Make a backup of your repository before using this command!

FURTHER WARNING: This command is a work-in-progress and may yet contain bugs.


Nonetheless, the command exists and I've used it for much the same reason.

If you have not made any additional changes to the repository since the accidental commit, you could purge the offending commit:

$ fossil up prev
$ fossil purge checkins `fossil timeline next -F %H -n 1 | head -1`

This will remove the OFFENDING-COMMIT and all of its descendants. IFF you have not made any changes to the repository since the accidental commit, obviously only OFFENDING-COMMIT will be removed.

For any readers looking to fix accidental commits, please take heed of the abovementioned warnings and at the very least make a backup!

(6) By mark on 2023-01-06 03:33:05 in reply to 4 [link] [source]

It wouldn't be much trouble to add a "dont-commit" setting that raises an error if you try to do a commit that you didn't really want to do.

I think that's a really good idea.

(7) By anonymous on 2023-01-06 08:24:54 in reply to 2.1 [link] [source]

I agree, there wouldn't be a readonly security feature.
It is more for preventing accidental commits.

I see anonymous checkout as a feature and it is exactly, how it should be in that case:
A library checked out to use only and not modify the code.

So I was just wondering, if a flag exist... (which would be "dont-commit", as proposed)

(8.1) By Warren Young (wyoung) on 2023-01-06 13:17:14 edited from 8.0 in reply to 7 [link] [source]

I can't say I'm morally opposed to this. It might even be good to have the flag on by default for anonymous clones, so that weirdos like me who currently make use of the local private fork capability have to turn it off, effectively saying, "Yes, I know what I'm doing."

(9) By Daniel Dumitriu (danield) on 2023-01-06 13:16:04 in reply to 4 [link] [source]

The setting has just landed on trunk under the proposed name dont-commit.

(10) By Warren Young (wyoung) on 2023-01-06 13:16:13 in reply to 5 [link] [source]

Purging a local commit like this before it's pushed is pretty much what the feature was created for. Only the original context motivating it differs, being that you've integrated a bundle someone sent you for testing and have decided not to publish it after all.

Good call-out.

(11) By Warren Young (wyoung) on 2023-01-06 13:18:29 in reply to 9 [link] [source]

Yay!

How about enabling it by default for anonymous clones, per my post #8?

(12) By Daniel Dumitriu (danield) on 2023-01-06 13:23:23 in reply to 11 [link] [source]

I guess it depends on how many weirdos gather around. Let us listen.

If it stays silent, you must unfortunately type your fingers out and say "fossil set dont-commit on" each time. Or script it 😄.

(13) By Warren Young (wyoung) on 2023-01-06 13:27:10 in reply to 12 [link] [source]

You've inverted the sensible condition. The nature of weirdos is that we're in the minority, so our wish to have anonymous clones that we can still commit to is the rare condition. Cater to the masses, not to us weirdos.

(14) By Stephan Beal (stephan) on 2023-01-06 14:20:45 in reply to 11 [link] [source]

How about enabling it by default for anonymous clones, per my post #8?

Perhaps running the "remote-url" command with an explicit user name should implicitly disable it?

Just spitballing.

(15) By Daniel Dumitriu (danield) on 2023-01-06 14:38:16 in reply to 13 [link] [source]

We can always add another (global) option that says whether (for anonymous clones) dont-push gets enabled 😅.

Stephan: it might make sense iif we decide in favor of default enabling it. I am rather disinclined thereto.

(16) By Warren Young (wyoung) on 2023-01-06 14:47:45 in reply to 15 [link] [source]

I think this is a case of "sensible defaults." If you clone anonymously, you probably never intend to commit anything; it's almost always an error. You should have to go out of your way to say, "Yes, really, I'm not kidding."

(17) By Warren Young (wyoung) on 2023-01-06 14:48:48 in reply to 14 [link] [source]

Yes, that's another case of sensible defaults. By assigning a new remote URL, you're saying, "Now I'm going to commit to this repo I previously cloned anonymously."

(18) By Andy Bradford (andybradford) on 2023-01-06 17:19:39 in reply to 11 [link] [source]

I vote to  leave it off by  default. In fact, I'm not  sure what problem
this new option solves in the first place.

(19) By Andy Bradford (andybradford) on 2023-01-06 17:23:57 in reply to 16 [link] [source]

I don't think it's  a sensible default at all. Just  one more hurdle for
people to have  to learn when using  Fossil. The crux of  the problem is
that  the OP  committed and  now is  getting an  error about  not having
permissions  to push.  Use  "dont-push", problem  solved. Having  Fossil
impose some kind of arbitrary "dont-commit" trammel seems unnecessary.

Andy

(20) By Andy Bradford (andybradford) on 2023-01-06 17:31:53 in reply to 14 [link] [source]

> Perhaps running  the "remote-url" command  with an explicit  user name
> should implicitly disable it?

I almost never  have usernames in my  SSH urls because I  don't need it.
It's  implicit in  the fact  that my  local account  matches the  remote
account that  I'm using (or is  governed by ~/.ssh/config). My  SSH urls
look like:

ssh://hostname/fossils/project.fossil

Andy

(21) By Andy Bradford (andybradford) on 2023-01-06 17:35:03 in reply to 17 [link] [source]

The problem is,  nobody commits to a remote repository.  Commit and Push
are entirely  different operations.  This kind  of behavior  muddies the
waters.

All commits are local. The fact that it was cloned and the remote source
from which it was cloned may or may not grant permission for push should
not be the determining factor in whether or not I can commit locally.

Just my $0.02.

Andy

(22) By Andy Bradford (andybradford) on 2023-01-06 17:37:20 in reply to 1 [link] [source]

> This ended up in a fork, which I cannot remove.

If you  never intend on sharing  the code from this  repository, utilize
the "shun" or other commands that wipe data from the repository. No need
to delete and reclone.

Andy

(23) By Stephan Beal (stephan) on 2023-01-06 17:39:00 in reply to 20 [link] [source]

ssh://hostname/fossils/project.fossil

That only works for repos under your control, though. It's happened more than once that a new fossil contributor, after sending their CLA to Richard, wants to push changes they've made locally but couldn't previously push. For the main fossil repo, CGI/https is the only connection option, and "remote-url" is the easiest way to "upgrade" their previously anonymous checkouts.

(24) By Andy Bradford (andybradford) on 2023-01-06 18:36:58 in reply to 23 [link] [source]

> That only works for repos under your control, though.

Actually, it does not.

I often put the following in my ~/.ssh/config:

Host hostname
  User username

https://man.openbsd.org/ssh_config#User

This is so  hosts which have a different username  than my local account
work automatically for me.

And the  fact that new contributors  may want to commit  before having a
CLA in  place is one  good reason why the  default for this  new setting
should be off. :-)

Andy

(25) By ravbc on 2023-01-07 11:25:18 in reply to 24 [link] [source]

So maybe the automatic "no commit enabled" should only apply to anonymous clones over http(s) and not to clones over ssh?

Maybe it's just me, but when cloning not-my-own repository I rarely have a desire to commit changes to my clone, and when the need arise switching off this flag is not really hard too...