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

Add cleaner dubious ownership error #3881

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/app/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func knownError(tr *i18n.TranslationSet, err error) (string, bool) {
originalError: "getwd: no such file or directory",
newError: tr.WorkingDirectoryDoesNotExist,
},
{
originalError: "fatal: detected dubious ownership in repository",
newError: tr.UnsafeOrNetworkDirectoryError,
},
}

if mapping, ok := lo.Find(mappings, func(mapping errorMapping) bool {
Expand Down
4 changes: 4 additions & 0 deletions pkg/commands/git_commands/repo_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ func callGitRevParseWithDir(
gitCmd := cmd.New(gitRevParse.ToArgv()).DontLog()
res, err := gitCmd.RunWithOutput()
if err != nil {
if strings.Contains(err.Error(), "fatal: detected dubious ownership in repository") {
err = errors.New("fatal: detected dubious ownership in repository")
return "", err
}
return "", errors.Errorf("'%s' failed: %v", gitCmd.ToString(), err)
}
return strings.TrimSpace(res), nil
Expand Down
9 changes: 9 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ type TranslationSet struct {
RangeSelectNotSupportedForSubmodules string
OldCherryPickKeyWarning string
CommandDoesNotSupportOpeningInEditor string
UnsafeOrNetworkDirectoryError string
Actions Actions
Bisect Bisect
Log Log
Expand Down Expand Up @@ -1789,6 +1790,14 @@ func EnglishTranslationSet() *TranslationSet {
RangeSelectNotSupportedForSubmodules: "Range select not supported for submodules",
OldCherryPickKeyWarning: "The 'c' key is no longer the default key for copying commits to cherry pick. Please use `{{.copy}}` instead (and `{{.paste}}` to paste). The reason for this change is that the 'v' key for selecting a range of lines when staging is now also used for selecting a range of lines in any list view, meaning that we needed to find a new key for pasting commits, and if we're going to now use `{{.paste}}` for pasting commits, we may as well use `{{.copy}}` for copying them. If you want to configure the keybindings to get the old behaviour, set the following in your config:\n\nkeybinding:\n universal:\n toggleRangeSelect: <something other than v>\n commits:\n cherryPickCopy: 'c'\n pasteCommits: 'v'",
CommandDoesNotSupportOpeningInEditor: "This command doesn't support switching to the editor",
UnsafeOrNetworkDirectoryError: `Git detected unsafe/dubious ownership of the repository's root directory

Whilst there is a solution/workaround, please understand the relevant risks and purpose of this warning!
See 'https://github.com/git/git/commit/8959555cee7ec045958f9b6dd62e541affb7e7d9' for background information on said risks

This error is unrelated to lazygit
For more information, see 'https://git-scm.com/docs/git-config/2.35.2#Documentation/git-config.txt-safedirectory'
`,

Actions: Actions{
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)
Expand Down