2018-05-19 11:16:34 +10:00
|
|
|
package main
|
|
|
|
|
2018-06-02 08:35:49 +10:00
|
|
|
import (
|
2018-07-21 15:51:18 +10:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2018-08-09 12:25:32 +10:00
|
|
|
"io/ioutil"
|
2018-07-21 15:51:18 +10:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/user"
|
2018-08-09 13:21:30 +10:00
|
|
|
"path/filepath"
|
2018-07-21 15:51:18 +10:00
|
|
|
|
2018-08-11 15:04:02 +10:00
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
|
|
|
2018-08-12 19:31:27 +10:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/app"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/config"
|
2018-08-09 14:33:51 +10:00
|
|
|
git "gopkg.in/src-d/go-git.v4"
|
2018-06-02 08:35:49 +10:00
|
|
|
)
|
|
|
|
|
2018-06-05 19:30:55 +10:00
|
|
|
var (
|
2018-08-08 22:48:37 +10:00
|
|
|
commit string
|
|
|
|
version = "unversioned"
|
2018-08-12 19:31:27 +10:00
|
|
|
date string
|
2018-08-08 18:57:27 +10:00
|
|
|
|
2018-08-08 19:46:21 +10:00
|
|
|
debuggingFlag = flag.Bool("debug", false, "a boolean")
|
|
|
|
versionFlag = flag.Bool("v", false, "Print the current version")
|
2018-08-09 14:33:51 +10:00
|
|
|
|
|
|
|
w *git.Worktree
|
2018-08-11 15:09:37 +10:00
|
|
|
r *git.Repository
|
2018-06-05 19:30:55 +10:00
|
|
|
)
|
2018-05-27 16:32:09 +10:00
|
|
|
|
2018-06-05 19:32:03 +10:00
|
|
|
func homeDirectory() string {
|
2018-07-21 15:51:18 +10:00
|
|
|
usr, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return usr.HomeDir
|
2018-06-05 19:32:03 +10:00
|
|
|
}
|
|
|
|
|
2018-08-09 13:29:25 +10:00
|
|
|
func projectPath(path string) string {
|
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
return filepath.FromSlash(gopath + "/src/github.com/jesseduffield/lazygit/" + path)
|
|
|
|
}
|
|
|
|
|
2018-06-05 19:32:03 +10:00
|
|
|
func devLog(objects ...interface{}) {
|
2018-08-09 20:29:58 +10:00
|
|
|
localLog("development.log", objects...)
|
2018-06-05 19:32:03 +10:00
|
|
|
}
|
|
|
|
|
2018-08-11 15:04:02 +10:00
|
|
|
func objectLog(object interface{}) {
|
|
|
|
if !*debuggingFlag {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
str := spew.Sdump(object)
|
|
|
|
localLog("development.log", str)
|
|
|
|
}
|
|
|
|
|
2018-06-05 19:32:03 +10:00
|
|
|
func commandLog(objects ...interface{}) {
|
2018-08-09 20:29:58 +10:00
|
|
|
localLog("commands.log", objects...)
|
2018-06-05 19:32:03 +10:00
|
|
|
}
|
|
|
|
|
2018-08-09 20:29:58 +10:00
|
|
|
func localLog(path string, objects ...interface{}) {
|
2018-08-08 19:46:21 +10:00
|
|
|
if !*debuggingFlag {
|
2018-07-21 15:51:18 +10:00
|
|
|
return
|
|
|
|
}
|
2018-08-09 14:36:26 +10:00
|
|
|
f, err := os.OpenFile(projectPath(path), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
2018-07-21 15:51:18 +10:00
|
|
|
defer f.Close()
|
2018-08-09 20:29:58 +10:00
|
|
|
log.SetOutput(f)
|
2018-07-21 15:51:18 +10:00
|
|
|
for _, object := range objects {
|
2018-08-09 20:29:58 +10:00
|
|
|
log.Println(fmt.Sprint(object))
|
2018-07-21 15:51:18 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 12:25:32 +10:00
|
|
|
// when building the binary, `version` is set as a compile-time variable, along
|
|
|
|
// with `date` and `commit`. If this program has been opened directly via go,
|
|
|
|
// we will populate the `version` with VERSION in the lazygit root directory
|
|
|
|
func fallbackVersion() string {
|
2018-08-09 13:29:25 +10:00
|
|
|
path := projectPath("VERSION")
|
2018-08-09 13:21:30 +10:00
|
|
|
byteVersion, err := ioutil.ReadFile(path)
|
2018-08-09 12:25:32 +10:00
|
|
|
if err != nil {
|
2018-08-09 12:55:41 +10:00
|
|
|
return "unversioned"
|
2018-08-09 12:25:32 +10:00
|
|
|
}
|
|
|
|
return string(byteVersion)
|
|
|
|
}
|
|
|
|
|
2018-08-09 14:33:51 +10:00
|
|
|
func setupWorktree() {
|
2018-08-11 15:09:37 +10:00
|
|
|
var err error
|
|
|
|
r, err = git.PlainOpen(".")
|
2018-08-09 14:33:51 +10:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
w, err = r.Worktree()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-19 11:16:34 +10:00
|
|
|
func main() {
|
2018-08-07 16:15:23 +02:00
|
|
|
flag.Parse()
|
2018-08-09 12:25:32 +10:00
|
|
|
if version == "unversioned" {
|
|
|
|
version = fallbackVersion()
|
|
|
|
}
|
2018-08-07 16:15:23 +02:00
|
|
|
if *versionFlag {
|
2018-08-08 22:51:18 +10:00
|
|
|
fmt.Printf("commit=%s, build date=%s, version=%s", commit, date, version)
|
2018-08-07 16:15:23 +02:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
2018-08-12 19:31:27 +10:00
|
|
|
appConfig := &config.AppConfig{
|
|
|
|
Name: "lazygit",
|
|
|
|
Version: version,
|
|
|
|
Commit: commit,
|
|
|
|
BuildDate: date,
|
|
|
|
Debug: *debuggingFlag,
|
|
|
|
}
|
|
|
|
app, err := app.NewApp(appConfig)
|
|
|
|
app.Log.Info(err)
|
|
|
|
|
|
|
|
app.GitCommand.SetupGit()
|
|
|
|
// TODO remove this once r, w not used
|
2018-08-09 14:33:51 +10:00
|
|
|
setupWorktree()
|
2018-08-12 19:31:27 +10:00
|
|
|
|
2018-08-12 21:04:47 +10:00
|
|
|
app.Gui.RunWithSubprocesses()
|
2018-05-19 11:16:34 +10:00
|
|
|
}
|