Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git-init failure with git ssh creds πŸ”‘ #804

Merged
merged 1 commit into from
Apr 26, 2019
Merged
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
16 changes: 13 additions & 3 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"os"
"os/exec"
"os/user"
"strings"

homedir "github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -48,10 +49,19 @@ func Fetch(logger *zap.SugaredLogger, revision, path, url string) error {
return err
}
homeenv := os.Getenv("HOME")
if homeenv != "" && homeenv != homepath {
u, err := user.Current()
if err != nil {
return err
}
if u.Name == "root" {
if err := os.Symlink(homeenv+"/.ssh", "/root/.ssh"); err != nil {
// Only do a warning, in case we don't have a real home
// directory writable in our image
logger.Warnf("Unexpected error: creating symlink: %v", err)
}
} else if homeenv != "" && homeenv != homepath {
if _, err := os.Stat(homepath + "/.ssh"); os.IsNotExist(err) {
err = os.Symlink(homeenv+"/.ssh", homepath+"/.ssh")
if err != nil {
if err := os.Symlink(homeenv+"/.ssh", homepath+"/.ssh"); err != nil {
// Only do a warning, in case we don't have a real home
// directory writable in our image
logger.Warnf("Unexpected error: creating symlink: %v", err)
Expand Down