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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Options:
The path to your config file. (default "git-backup.yml")
-backup.fail-at-end
Fail at the end of backing up repositories, rather than right away.
-backup.bare-clone
Make bare clones without checking out the main branch.
```

## Usage: Docker
Expand Down
3 changes: 2 additions & 1 deletion cmd/git-backup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
var configFilePath = flag.String("config.file", "git-backup.yml", "The path to your config file.")
var targetPath = flag.String("backup.path", "backup", "The target path to the backup folder.")
var failAtEnd = flag.Bool("backup.fail-at-end", false, "Fail at the end of backing up repositories, rather than right away.")
var bareClone = flag.Bool("backup.bare-clone", false, "Make bare clones without checking out the main branch.")

func main() {
flag.Parse()
Expand Down Expand Up @@ -45,7 +46,7 @@ func main() {
log.Printf("Failed to create directory: %s", err)
os.Exit(100)
}
err = repo.CloneInto(targetPath)
err = repo.CloneInto(targetPath, *bareClone)
if err != nil {
errors++
log.Printf("Failed to clone: %s", err)
Expand Down
11 changes: 6 additions & 5 deletions repository.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package git_backup

import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"log"
"net/url"
"os"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http"
)

type RepositorySource interface {
Expand All @@ -20,7 +21,7 @@ type Repository struct {
FullName string
}

func (r *Repository) CloneInto(path string) error {
func (r *Repository) CloneInto(path string, bare bool) error {
var auth http.AuthMethod
if r.GitURL.User != nil {
password, _ := r.GitURL.User.Password()
Expand All @@ -29,7 +30,7 @@ func (r *Repository) CloneInto(path string) error {
Password: password,
}
}
gitRepo, err := git.PlainClone(path, false, &git.CloneOptions{
gitRepo, err := git.PlainClone(path, bare, &git.CloneOptions{
URL: r.GitURL.String(),
Auth: auth,
Progress: os.Stdout,
Expand Down