From f5c7201333158a41d1774289bf55a41a013b4cff Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sat, 27 Apr 2024 07:01:30 +0300 Subject: [PATCH 1/4] [#15]: Make it work from subdirectories --- cmd/commit/main.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cmd/commit/main.go b/cmd/commit/main.go index b28256a..2efb163 100644 --- a/cmd/commit/main.go +++ b/cmd/commit/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "os" + "path/filepath" "regexp" "strings" "time" @@ -22,7 +23,7 @@ func main() { flag.StringVar( &configFilePath, "config-path", - helpers.DEFAULT_CONFIG_FILE_PATH, + "", "Path to the config json file", ) @@ -38,6 +39,10 @@ func main() { commitMessage := getCommitMessage() repo := openRepo() + worktree := openWorktree(repo) + + configFilePath = filepath.Join(worktree.Filesystem.Root(), helpers.DEFAULT_CONFIG_FILE_PATH) + headRef := getCurrentHead(repo) // Read branch name or HEAD @@ -52,7 +57,7 @@ func main() { } if !dryRun { - commitChanges(repo, commitMessage) + commitChanges(repo, worktree, commitMessage) } fmt.Println(commitMessage) @@ -76,9 +81,12 @@ func getCommitMessage() string { return args[0] } -// Opens the repository in current directory +// Opens the current repository func openRepo() *git.Repository { - repo, err := git.PlainOpen(".") + + options := git.PlainOpenOptions{DetectDotGit: true} + + repo, err := git.PlainOpenWithOptions(".", &options) if err != nil { fmt.Fprintf(os.Stderr, helpers.Red("Failed to open repository: %v\n"), err) os.Exit(1) @@ -158,8 +166,7 @@ func makeCommitOptions(usr user.User) git.CommitOptions { } // Commits changes with provided message -func commitChanges(repo *git.Repository, commitMessage string) { - worktree := openWorktree(repo) +func commitChanges(repo *git.Repository, worktree *git.Worktree, commitMessage string) { checkStagedChanges(worktree) From 43733d66a2a971499c91bb65b215d3bf214462b1 Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sat, 27 Apr 2024 07:09:28 +0300 Subject: [PATCH 2/4] [#15]: Clean up gitignore, ignore vscode folder --- .gitignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6e77a31..a6f002c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -# If you prefer the allow list template instead of the deny list, see community template: -# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore -# # Binaries for programs and plugins *.exe *.exe~ @@ -22,3 +19,6 @@ bin # Go workspace file go.work + +# Developer tools configs +.vscode From cc9531bc08f6a0410eb3d63ad43242279acda3fd Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sat, 27 Apr 2024 07:12:02 +0300 Subject: [PATCH 3/4] [#15]: Fix the link to license in readme --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 1e13f59..da73ea6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -87,5 +87,5 @@ Originally I wrote this tool for myself in shell and Swift and used a lot on Mac If you find it useful and see that something's wrong or missing, feel free to raise issues and contribute to the project. When doing so, please follow the ususal code of conduct and contribution guidelines from GitHub, and just common sense. ## License -This repository is distributed under the MIT license (see [LICENSE.md](/docs/LICENSE.md). +This repository is distributed under the MIT license (see [LICENSE.md](/docs/LICENSE)). My tool uses [go-git](https://github.com/go-git/go-git) as a 3rd party dependency to work with git directly, you might want to check it out too. From 856bafc11669df1fcd925c7709b6abefb65e709b Mon Sep 17 00:00:00 2001 From: Artem Yelizarov <52959979+artem-y@users.noreply.github.com> Date: Sat, 27 Apr 2024 07:22:42 +0300 Subject: [PATCH 4/4] [#15]: Use custom path for config if passed --- cmd/commit/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/commit/main.go b/cmd/commit/main.go index 2efb163..f32af1d 100644 --- a/cmd/commit/main.go +++ b/cmd/commit/main.go @@ -41,7 +41,12 @@ func main() { repo := openRepo() worktree := openWorktree(repo) - configFilePath = filepath.Join(worktree.Filesystem.Root(), helpers.DEFAULT_CONFIG_FILE_PATH) + if configFilePath == "" { + configFilePath = filepath.Join( + worktree.Filesystem.Root(), + helpers.DEFAULT_CONFIG_FILE_PATH, + ) + } headRef := getCurrentHead(repo)