Skip to content

Commit f5d5897

Browse files
authored
Added a backup.bare-clone option (#6)
When creating purely backups bare repositories are fine and checking out a branch isn't needed. This would save space and would possibly speed up backing up.
1 parent c551629 commit f5d5897

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ Options:
7878
The path to your config file. (default "git-backup.yml")
7979
-backup.fail-at-end
8080
Fail at the end of backing up repositories, rather than right away.
81+
-backup.bare-clone
82+
Make bare clones without checking out the main branch.
8183
```
8284

8385
## Usage: Docker

cmd/git-backup/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
var configFilePath = flag.String("config.file", "git-backup.yml", "The path to your config file.")
1313
var targetPath = flag.String("backup.path", "backup", "The target path to the backup folder.")
1414
var failAtEnd = flag.Bool("backup.fail-at-end", false, "Fail at the end of backing up repositories, rather than right away.")
15+
var bareClone = flag.Bool("backup.bare-clone", false, "Make bare clones without checking out the main branch.")
1516

1617
func main() {
1718
flag.Parse()
@@ -45,7 +46,7 @@ func main() {
4546
log.Printf("Failed to create directory: %s", err)
4647
os.Exit(100)
4748
}
48-
err = repo.CloneInto(targetPath)
49+
err = repo.CloneInto(targetPath, *bareClone)
4950
if err != nil {
5051
errors++
5152
log.Printf("Failed to clone: %s", err)

repository.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package git_backup
22

33
import (
4-
"github.com/go-git/go-git/v5"
5-
"github.com/go-git/go-git/v5/plumbing/transport"
6-
"github.com/go-git/go-git/v5/plumbing/transport/http"
74
"log"
85
"net/url"
96
"os"
7+
8+
"github.com/go-git/go-git/v5"
9+
"github.com/go-git/go-git/v5/plumbing/transport"
10+
"github.com/go-git/go-git/v5/plumbing/transport/http"
1011
)
1112

1213
type RepositorySource interface {
@@ -20,7 +21,7 @@ type Repository struct {
2021
FullName string
2122
}
2223

23-
func (r *Repository) CloneInto(path string) error {
24+
func (r *Repository) CloneInto(path string, bare bool) error {
2425
var auth http.AuthMethod
2526
if r.GitURL.User != nil {
2627
password, _ := r.GitURL.User.Password()
@@ -29,7 +30,7 @@ func (r *Repository) CloneInto(path string) error {
2930
Password: password,
3031
}
3132
}
32-
gitRepo, err := git.PlainClone(path, false, &git.CloneOptions{
33+
gitRepo, err := git.PlainClone(path, bare, &git.CloneOptions{
3334
URL: r.GitURL.String(),
3435
Auth: auth,
3536
Progress: os.Stdout,

0 commit comments

Comments
 (0)