1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

feat(config): add notARepository: quit

This commit is contained in:
Ryooooooga 2022-08-08 09:23:56 +09:00
parent 70a46028e1
commit 8b371ada73
No known key found for this signature in database
GPG Key ID: BAEABE191C5D793E
3 changed files with 41 additions and 25 deletions

View File

@ -101,7 +101,7 @@ confirmOnQuit: false
# determines whether hitting 'esc' will quit the application when there is nothing to cancel/close
quitOnTopLevelReturn: false
disableStartupPopups: false
notARepository: 'prompt' # one of: 'prompt' | 'create' | 'skip'
notARepository: 'prompt' # one of: 'prompt' | 'create' | 'skip' | 'quit'
promptToReturnFromSubprocess: true # display confirmation when subprocess terminates
keybinding:
universal:
@ -531,3 +531,8 @@ notARepository: 'create'
# to skip without creating a new repo
notARepository: 'skip'
```
```yaml
# to exit immediately if run outside of the Git repository
notARepository: 'quit'
```

View File

@ -171,43 +171,52 @@ func (app *App) setupRepo() (bool, error) {
return false, err
}
shouldInitRepo := true
notARepository := app.UserConfig.NotARepository
initialBranch := ""
if notARepository == "prompt" {
var shouldInitRepo bool
initialBranchArg := ""
switch app.UserConfig.NotARepository {
case "prompt":
// Offer to initialize a new repository in current directory.
fmt.Print(app.Tr.CreateRepo)
response, _ := bufio.NewReader(os.Stdin).ReadString('\n')
if strings.Trim(response, " \r\n") != "y" {
shouldInitRepo = false
} else {
shouldInitRepo = (strings.Trim(response, " \r\n") == "y")
if shouldInitRepo {
// Ask for the initial branch name
fmt.Print(app.Tr.InitialBranch)
response, _ := bufio.NewReader(os.Stdin).ReadString('\n')
if trimmedResponse := strings.Trim(response, " \r\n"); len(trimmedResponse) > 0 {
initialBranch += "--initial-branch=" + trimmedResponse
initialBranchArg += "--initial-branch=" + app.OSCommand.Quote(trimmedResponse)
}
}
} else if notARepository == "skip" {
case "create":
shouldInitRepo = true
case "skip":
shouldInitRepo = false
}
if !shouldInitRepo {
// check if we have a recent repo we can open
for _, repoDir := range app.Config.GetAppState().RecentRepos {
if isRepo, _ := isDirectoryAGitRepository(repoDir); isRepo {
if err := os.Chdir(repoDir); err == nil {
return true, nil
}
}
}
fmt.Println(app.Tr.NoRecentRepositories)
case "quit":
fmt.Fprintln(os.Stderr, app.Tr.NotARepository)
os.Exit(1)
default:
fmt.Fprintln(os.Stderr, app.Tr.IncorrectNotARepository)
os.Exit(1)
}
if err := app.OSCommand.Cmd.New("git init " + initialBranch).Run(); err != nil {
return false, err
if shouldInitRepo {
if err := app.OSCommand.Cmd.New("git init " + initialBranchArg).Run(); err != nil {
return false, err
}
return false, nil
}
// check if we have a recent repo we can open
for _, repoDir := range app.Config.GetAppState().RecentRepos {
if isRepo, _ := isDirectoryAGitRepository(repoDir); isRepo {
if err := os.Chdir(repoDir); err == nil {
return true, nil
}
}
}
fmt.Fprintln(os.Stderr, app.Tr.NoRecentRepositories)
os.Exit(1)
}
return false, nil

View File

@ -261,6 +261,7 @@ type TranslationSet struct {
CreateRepo string
InitialBranch string
NoRecentRepositories string
IncorrectNotARepository string
AutoStashTitle string
AutoStashPrompt string
StashPrefix string
@ -900,6 +901,7 @@ func EnglishTranslationSet() TranslationSet {
CreateRepo: "Not in a git repository. Create a new git repository? (y/n): ",
InitialBranch: "Branch name? (leave empty for git's default): ",
NoRecentRepositories: "Must open lazygit in a git repository. No valid recent repositories. Exiting.",
IncorrectNotARepository: "The value of 'notARepository' is incorrect. It should be one of 'prompt', 'create', 'skip', or 'quit'.",
AutoStashTitle: "Autostash?",
AutoStashPrompt: "You must stash and pop your changes to bring them across. Do this automatically? (enter/esc)",
StashPrefix: "Auto-stashing changes for ",