Skip to content

Commit

Permalink
Fix private repo cloning (#76)
Browse files Browse the repository at this point in the history
* Always use token for cloning via HTTPS

On GitLab for some reason the `repo.Private` always returns false even if the repo is actually private, which means this code is never executed and the `git` client asks for a username and password to clone. 

It would make sense to use the token for cloning any type of repo, as it would prevent the need for asking these details.

Tested on my local build with gitlab.com and it works as expected.

* separate private repo check
  • Loading branch information
syphernl authored May 20, 2022
1 parent b4a3713 commit d8c1598
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ func backUp(backupDir string, repo *Repository, bare bool, wg *sync.WaitGroup) (
log.Printf("Cloning %s\n", repo.Name)
log.Printf("%#v\n", repo)

if repo.Private && useHTTPSClone != nil && *useHTTPSClone && ignorePrivate != nil && !*ignorePrivate {
if repo.Private && ignorePrivate != nil && !*ignorePrivate {
log.Printf("Skipping %s as it is a private repo.\n", repo.Name)
return stdoutStderr, nil
}

if useHTTPSClone != nil && *useHTTPSClone {
// Add username and token to the clone URL
// https://gitlab.com/amitsaha/testproject1 => https://amitsaha:token@gitlab.com/amitsaha/testproject1
u, err := url.Parse(repo.CloneURL)
Expand Down

0 comments on commit d8c1598

Please sign in to comment.