Skip to content

Commit

Permalink
feat: clone bare repositories without blobs (#269)
Browse files Browse the repository at this point in the history
In order to save disk space, make bare clones of repositories filtering
out blobs.
  • Loading branch information
tensor5 committed May 17, 2022
1 parent e216011 commit 7238d10
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions crawler/crawler/cloneRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,14 @@ func CloneRepository(domain Domain, hostname, name, gitURL, index string) error

// If folder already exists it will do a fetch instead of a clone.
if _, err := os.Stat(path); !os.IsNotExist(err) {
// Command is: git fetch --all
out, err := exec.Command("git", "-C", path, "fetch", "--all").CombinedOutput() // nolint: gas
if err != nil {
return errors.New(fmt.Sprintf("cannot git pull the repository: %s: %s", err.Error(), out))
}
out, err = exec.Command("git", "-C", path, "reset", "--hard", "origin/HEAD").CombinedOutput() // nolint: gas
if err != nil {
return errors.New(fmt.Sprintf("cannot git pull the repository: %s: %s", err.Error(), out))
}

return nil
}

// Clone the repository using the external command "git".
// Command is: git clone -b <branch> <remote_repo>
out, err := exec.Command("git", "clone", gitURL, path).CombinedOutput() // nolint: gas
out, err := exec.Command("git", "clone", "--filter=blob:none", "--mirror", "-b", gitURL, path).CombinedOutput() // nolint: gas
if err != nil {
return errors.New(fmt.Sprintf("cannot git clone the repository: %s: %s", err.Error(), out))
}
Expand Down

0 comments on commit 7238d10

Please sign in to comment.