lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Check for bare repositories

Open nullishamy opened this issue 3 years ago • 7 comments
trafficstars

This adds checks for bare repositories, which are unsupported, and errors gracefully if we encounter one.

Related: #2066

nullishamy avatar Jul 29 '22 22:07 nullishamy

Rather than exit the program, it would be better to ask the user if they want to open lazygit anyway, to the most recently opened repo. E.g.:

You've attempted to open Lazygit in a bare repo but Lazygit does not yet support bare repos. Open most recent repo? Y/N

If the user presses Y, then we'll do the same thing we currently do when the user opens lazygit in a non-repo and chooses not to initialise a new one. Otherwise, we'll exit the program.

Another point: we should move the message into pkg/i18n/english.go so that it can be translated into other languages (don't worry, you don't need to actually do any translating in this PR, it just makes things easier for others who want to add translations).

Lemme know if you need any pointers :)

jesseduffield avatar Jul 30 '22 11:07 jesseduffield

Yeah i wasnt sure how to handle the case where we need to exit, but just left it for review because its not a huge deal to change. Also wasnt sure how to operate the i18n, but judging from existing usage it shouldn't be too hard. Will work on this soon.

nullishamy avatar Aug 01 '22 02:08 nullishamy

I'm not sure if we should factor out the "switch to a recent repo" logic or not, thoughts?

nullishamy avatar Aug 01 '22 16:08 nullishamy

I'm not sure if we should factor out the "switch to a recent repo" logic or not, thoughts?

Does seem reasonable, and since you're already in that neck of the woods...

mark2185 avatar Aug 01 '22 18:08 mark2185

Will implement that, where should it go? Unsure if we'd need to use it in other files and whatnot, so not sure what place would be best.

nullishamy avatar Aug 01 '22 18:08 nullishamy

All three references to isDirectoryAGitRepository are in app.go, so I guess that is as good place as any.

But Jesse has a better mental model of the entire project so I'd rather hear his two cents clink.

mark2185 avatar Aug 01 '22 18:08 mark2185

Right, I've put it in there for now, will wait for Jesse's opinion on it and alter if needed.

nullishamy avatar Aug 01 '22 19:08 nullishamy

@nullishamy code looks good. You'll need to run gofumpt i.e.

go install mvdan.cc/gofumpt@latest && gofumpt -l -w .

jesseduffield avatar Aug 15 '22 21:08 jesseduffield

Never saw your comment, I believe that's what you wanted?

nullishamy avatar Aug 18 '22 17:08 nullishamy

nice work @nullishamy !

jesseduffield avatar Aug 18 '22 22:08 jesseduffield