This library provides functionalities to clone and pull Git repositories using the go-git
package.
It supports setting authentication, branch selection, depth cloning, progress reporting, and destination directory customization.
To install this library, you can use the following command:
go get github.com/weidongkl/git
-
Create a new clone instance:
clone := NewClone("https://github.com/user/repo.git")
-
Set optional parameters (authentication, branch, depth, progress, destination directory):
clone.SetAuth("username", "password"). SetBranch("main"). SetDepth(1). SetProgress(os.Stdout). SetDstDir("/path/to/destination")
-
Clone the repository:
err := clone.Clone() if err != nil { log.Fatalf("Failed to clone repository: %v", err) }
-
Create a new pull instance:
pull := NewPull("/path/to/local/repo")
-
Set optional parameters (authentication, progress):
pull.SetAuth("username", "password"). SetProgress(os.Stdout)
-
Pull changes:
err := pull.Pull() if err != nil { log.Fatalf("Failed to pull changes: %v", err) }
Here is an example of how to use the library to clone and pull a repository:
package main
import (
"log"
"os"
"github.com/weidongkl/git"
)
func main() {
// Clone a repository
clone := git.NewClone("https://github.com/user/repo.git").
SetAuth("username", "password").
SetBranch("main").
SetDepth(1).
SetProgress(os.Stdout).
SetDstDir("/path/to/destination")
err := clone.Clone()
if err != nil {
log.Fatalf("Failed to clone repository: %v", err)
}
// Pull changes from a repository
pull := git.NewPull("/path/to/local/repo").
SetAuth("username", "password").
SetProgress(os.Stdout)
err = pull.Pull()
if err != nil {
log.Fatalf("Failed to pull changes: %v", err)
}
}
Contributions are welcome! Please fork the repository and create a pull request with your changes. Make sure to follow the existing code style and add tests for your new features or fixes.
This project is licensed under the MIT License.
For any questions or issues, please contact [email protected]