Streamlined Git command execution engine with fluent chaining interface and comprehensive Git operations support.
π Fluent Chaining Interface: Method chaining for complex Git workflows with automatic error propagation β‘ Comprehensive Git Operations: Full coverage of Git commands including commit, push, pull, and branch management π Smart State Detection: Intelligent checking for staged/unstaged changes, clean working trees, and repository status π― Error Handling: Robust error propagation with detailed context and debug information π Repository Querying: Advanced repository introspection with branch, commit, and status information
go get github.com/go-xlan/gitgo
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("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 ready")
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 := rese.V1(gcm.LatestGitTag())
zaplog.SUG.Info("latest tag:", latest)
count := rese.V1(gcm.GetCommitCount())
zaplog.SUG.Info("total commits:", count)
}
β¬οΈ Source: Source
New(path string) *Gcm
- Create new Git command managerNewGcm(path, execConfig) *Gcm
- Create with custom configuration
Status() *Gcm
- Display working tree statusAdd() *Gcm
- Stage all changesCommit(message) *Gcm
- Create commit with messagePush() *Gcm
- Push to remote repositoryPull() *Gcm
- Pull from remote repository
CheckoutNewBranch(name) *Gcm
- Create and switch to new branchCheckout(name) *Gcm
- Switch to existing branchGetCurrentBranch() (string, error)
- Get current branch nameListBranches() ([]string, error)
- List all branches
HasStagingChanges() (bool, error)
- Check for staged changesHasUnstagedChanges() (bool, error)
- Check for unstaged changesHasChanges() (bool, error)
- Check for any changesGetCommitCount() (int, error)
- Get total commit countGitCommitHash(ref) (string, error)
- Get commit hash for referenceGetRemoteURL(remote) (string, error)
- Get remote repository URL
Result() ([]byte, error)
- Get output and check for errorsMustDone() *Gcm
- Panic if error occurred
MIT License. See LICENSE.
Contributions are welcome! Report bugs, suggest features, and contribute code:
- π Found a bug? Open an issue on GitHub with reproduction steps
- π‘ Have a feature idea? Create an issue to discuss the suggestion
- π 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 and use significant commit messages
- 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 pull 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! π