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 # determines whether hitting 'esc' will quit the application when there is nothing to cancel/close
quitOnTopLevelReturn: false quitOnTopLevelReturn: false
disableStartupPopups: 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 promptToReturnFromSubprocess: true # display confirmation when subprocess terminates
keybinding: keybinding:
universal: universal:
@ -531,3 +531,8 @@ notARepository: 'create'
# to skip without creating a new repo # to skip without creating a new repo
notARepository: 'skip' 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 return false, err
} }
shouldInitRepo := true var shouldInitRepo bool
notARepository := app.UserConfig.NotARepository initialBranchArg := ""
initialBranch := "" switch app.UserConfig.NotARepository {
if notARepository == "prompt" { case "prompt":
// Offer to initialize a new repository in current directory. // Offer to initialize a new repository in current directory.
fmt.Print(app.Tr.CreateRepo) fmt.Print(app.Tr.CreateRepo)
response, _ := bufio.NewReader(os.Stdin).ReadString('\n') response, _ := bufio.NewReader(os.Stdin).ReadString('\n')
if strings.Trim(response, " \r\n") != "y" { shouldInitRepo = (strings.Trim(response, " \r\n") == "y")
shouldInitRepo = false if shouldInitRepo {
} else {
// Ask for the initial branch name // Ask for the initial branch name
fmt.Print(app.Tr.InitialBranch) fmt.Print(app.Tr.InitialBranch)
response, _ := bufio.NewReader(os.Stdin).ReadString('\n') response, _ := bufio.NewReader(os.Stdin).ReadString('\n')
if trimmedResponse := strings.Trim(response, " \r\n"); len(trimmedResponse) > 0 { 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 shouldInitRepo = false
} case "quit":
fmt.Fprintln(os.Stderr, app.Tr.NotARepository)
if !shouldInitRepo { os.Exit(1)
// check if we have a recent repo we can open default:
for _, repoDir := range app.Config.GetAppState().RecentRepos { fmt.Fprintln(os.Stderr, app.Tr.IncorrectNotARepository)
if isRepo, _ := isDirectoryAGitRepository(repoDir); isRepo {
if err := os.Chdir(repoDir); err == nil {
return true, nil
}
}
}
fmt.Println(app.Tr.NoRecentRepositories)
os.Exit(1) 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 return false, nil

View File

@ -261,6 +261,7 @@ type TranslationSet struct {
CreateRepo string CreateRepo string
InitialBranch string InitialBranch string
NoRecentRepositories string NoRecentRepositories string
IncorrectNotARepository string
AutoStashTitle string AutoStashTitle string
AutoStashPrompt string AutoStashPrompt string
StashPrefix string StashPrefix string
@ -900,6 +901,7 @@ func EnglishTranslationSet() TranslationSet {
CreateRepo: "Not in a git repository. Create a new git repository? (y/n): ", CreateRepo: "Not in a git repository. Create a new git repository? (y/n): ",
InitialBranch: "Branch name? (leave empty for git's default): ", InitialBranch: "Branch name? (leave empty for git's default): ",
NoRecentRepositories: "Must open lazygit in a git repository. No valid recent repositories. Exiting.", 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?", AutoStashTitle: "Autostash?",
AutoStashPrompt: "You must stash and pop your changes to bring them across. Do this automatically? (enter/esc)", AutoStashPrompt: "You must stash and pop your changes to bring them across. Do this automatically? (enter/esc)",
StashPrefix: "Auto-stashing changes for ", StashPrefix: "Auto-stashing changes for ",