Streamlined Git command execution engine with fluent chaining interface and comprehensive Git operations support.
π Fluent Chaining Interface: Method chaining with complex Git workflows and automatic issue propagation β‘ Comprehensive Git Operations: Complete Git commands coverage including commit, push, fetch, and branch management π Smart State Detection: Intelligent checking on staged and unstaged changes, clean working trees, and repo status π― Issue Handling: Robust issue propagation with detailed context and debug information π Repo Querying: Advanced repo introspection with branch, commit, and status information
- gogit - Enhanced Git operations toolkit with go-git foundation, providing pure Go implementation without CLI dependencies
- gitgo (this project) - Streamlined Git command execution engine with fluent chaining interface
go get github.com/go-xlan/gitgopackage main
import (
"os"
"path/filepath"
"github.com/go-xlan/gitgo"
"github.com/yyle88/must"
"github.com/yyle88/rese"
"github.com/yyle88/zaplog"
)
func main() {
tempDIR := rese.V1(os.MkdirTemp("", "gitgo-*"))
defer func() {
must.Done(os.RemoveAll(tempDIR))
}()
zaplog.SUG.Debug("working in:", tempDIR)
gcm := gitgo.New(tempDIR)
gcm.Init().Done()
zaplog.SUG.Info("git repo initialized")
must.Done(os.WriteFile(filepath.Join(tempDIR, "demo.txt"), []byte("hello"), 0644))
zaplog.SUG.Info("created demo.txt")
gcm.Add().Commit("demo commit").Done()
zaplog.SUG.Info("committed changes")
}β¬οΈ Source: Source
package main
import (
"os"
"path/filepath"
"github.com/go-xlan/gitgo"
"github.com/yyle88/must"
"github.com/yyle88/rese"
"github.com/yyle88/zaplog"
)
func main() {
tempDIR := rese.V1(os.MkdirTemp("", "gitgo-*"))
defer func() {
must.Done(os.RemoveAll(tempDIR))
}()
zaplog.SUG.Debug("working in:", tempDIR)
gcm := gitgo.New(tempDIR)
gcm.Init().Done()
zaplog.SUG.Info("initialized repo")
must.Done(os.WriteFile(filepath.Join(tempDIR, "file.txt"), []byte("v1"), 0644))
gcm.Add().Commit("add file").Done()
zaplog.SUG.Info("committed v1")
must.Done(os.WriteFile(filepath.Join(tempDIR, "file.txt"), []byte("v2"), 0644))
zaplog.SUG.Info("modified file to v2")
hasChanges := rese.V1(gcm.HasUnstagedChanges())
zaplog.SUG.Info("has unstaged changes:", hasChanges)
if hasChanges {
gcm.Add().Commit("update file").Done()
zaplog.SUG.Info("committed v2 changes")
}
}β¬οΈ Source: Source
package main
import (
"os"
"path/filepath"
"github.com/go-xlan/gitgo"
"github.com/yyle88/must"
"github.com/yyle88/rese"
"github.com/yyle88/zaplog"
)
func main() {
tempDIR := rese.V1(os.MkdirTemp("", "gitgo-*"))
defer func() {
must.Done(os.RemoveAll(tempDIR))
}()
zaplog.SUG.Debug("working in:", tempDIR)
gcm := gitgo.New(tempDIR)
gcm.Init().Done()
zaplog.SUG.Info("repo setup complete")
must.Done(os.WriteFile(filepath.Join(tempDIR, "app.txt"), []byte("v1"), 0644))
gcm.Add().Commit("v1").Tag("v1.0.0").Done()
zaplog.SUG.Info("tagged v1.0.0")
must.Done(os.WriteFile(filepath.Join(tempDIR, "app.txt"), []byte("v2"), 0644))
gcm.Add().Commit("v2").Tag("v1.1.0").Done()
zaplog.SUG.Info("tagged v1.1.0")
latest, exists, err := gcm.GetLatestTag()
must.Done(err)
must.True(exists)
zaplog.SUG.Info("latest tag:", latest)
count := rese.V1(gcm.GetCommitCount())
zaplog.SUG.Info("commit count:", count)
}β¬οΈ Source: Source
New(path string) *Gcm- Create new Git command engineNewGcm(path, execConfig) *Gcm- Create with custom settings
Status() *Gcm- Show working tree statusAdd() *Gcm- Stage changesCommit(message) *Gcm- Create commit with messagePush() *Gcm- Push to remote repoPull() *Gcm- Fetch and merge from remote repo
CheckoutNewBranch(name) *Gcm- Create and switch to new branchCheckout(name) *Gcm- Switch to existing branchGetCurrentBranch() (string, error)- Get the branch nameListBranches() ([]string, error)- Get branches as a list
HasStagedChanges() (bool, error)- Check staged changes existenceHasUnstagedChanges() (bool, error)- Check unstaged changes existenceHasChanges() (bool, error)- Check changes existenceGetCommitCount() (int, error)- Get commit countGetCommitHash(ref) (string, error)- Get commit hash with referenceGetRemoteURL(remote) (string, error)- Get remote repo URLGetIgnoredFiles() ([]string, error)- Get files ignored in gitignoreConfigGet(key) (string, error)- Get Git configuration value
GetLatestTag() (string, bool, error)- Get latest tag name with existence check
Result() ([]byte, error)- Get output and check issuesMustDone() *Gcm- Panic when issues happen
MIT License - see LICENSE.
Contributions are welcome! Report bugs, suggest features, and contribute code:
- π Mistake reports? Open an issue on GitHub with reproduction steps
- π‘ Fresh ideas? Create an issue to discuss
- π Documentation confusing? Report it so we can improve
- π Need new features? Share the use cases to help us understand requirements
- β‘ Performance issue? Help us optimize through reporting slow operations
- π§ Configuration problem? Ask questions about complex setups
- π’ Follow project progress? Watch the repo to get new releases and features
- π Success stories? Share how this package improved the workflow
- π¬ Feedback? We welcome suggestions and comments
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage UI).
- Clone: Clone the forked project (
git clone https://github.com/yourname/repo-name.git). - Navigate: Navigate to the cloned project (
cd repo-name) - Branch: Create a feature branch (
git checkout -b feature/xxx). - Code: Implement the changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...) and follow Go code style conventions - Documentation: Update documentation to support client-facing changes
- Stage: Stage changes (
git add .) - Commit: Commit changes (
git commit -m "Add feature xxx") ensuring backward compatible code - Push: Push to the branch (
git push origin feature/xxx). - PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.
Please ensure tests pass and include relevant documentation updates.
Welcome to contribute to this project via submitting merge requests and reporting issues.
Project Support:
- β Give GitHub stars if this project helps you
- π€ Share with teammates and (golang) programming friends
- π Write tech blogs about development tools and workflows - we provide content writing support
- π Join the ecosystem - committed to supporting open source and the (golang) development scene
Have Fun Coding with this package! πππ