Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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~
Expand All @@ -22,3 +19,6 @@ bin

# Go workspace file
go.work

# Developer tools configs
.vscode
24 changes: 18 additions & 6 deletions cmd/commit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"time"
Expand All @@ -22,7 +23,7 @@ func main() {
flag.StringVar(
&configFilePath,
"config-path",
helpers.DEFAULT_CONFIG_FILE_PATH,
"",
"Path to the config json file",
)

Expand All @@ -38,6 +39,15 @@ func main() {

commitMessage := getCommitMessage()
repo := openRepo()
worktree := openWorktree(repo)

if configFilePath == "" {
configFilePath = filepath.Join(
worktree.Filesystem.Root(),
helpers.DEFAULT_CONFIG_FILE_PATH,
)
}

headRef := getCurrentHead(repo)

// Read branch name or HEAD
Expand All @@ -52,7 +62,7 @@ func main() {
}

if !dryRun {
commitChanges(repo, commitMessage)
commitChanges(repo, worktree, commitMessage)
}

fmt.Println(commitMessage)
Expand All @@ -76,9 +86,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)
Expand Down Expand Up @@ -158,8 +171,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)

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.