From 5638bf76012112233ba5a30e4558b8cb3cf439e0 Mon Sep 17 00:00:00 2001 From: Thomas Miceli Date: Tue, 4 Apr 2023 02:01:31 +0200 Subject: [PATCH] Fix bug on undefined commiter name --- internal/git/commands.go | 14 +++++++++++++- internal/models/gist.go | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/git/commands.go b/internal/git/commands.go index bd4e1e0..df847ba 100644 --- a/internal/git/commands.go +++ b/internal/git/commands.go @@ -129,7 +129,7 @@ func GetLog(user string, gist string, skip string) ([]*Commit, error) { return parseLog(stdout), nil } -func CloneTmp(user string, gist string, gistTmpId string) error { +func CloneTmp(user string, gist string, gistTmpId string, email string) error { repositoryPath := RepositoryPath(user, gist) tmpPath := TmpRepositoriesPath() @@ -150,6 +150,18 @@ func CloneTmp(user string, gist string, gistTmpId string) error { // remove every file (and not the .git directory!) cmd = exec.Command("find", ".", "-maxdepth", "1", "-type", "f", "-delete") cmd.Dir = tmpRepositoryPath + if err = cmd.Run(); err != nil { + return err + } + + cmd = exec.Command("git", "config", "--local", "user.name", user) + cmd.Dir = tmpRepositoryPath + if err = cmd.Run(); err != nil { + return err + } + + cmd = exec.Command("git", "config", "--local", "user.email", email) + cmd.Dir = tmpRepositoryPath return cmd.Run() } diff --git a/internal/models/gist.go b/internal/models/gist.go index 676a860..4bea1a3 100644 --- a/internal/models/gist.go +++ b/internal/models/gist.go @@ -237,7 +237,7 @@ func (gist *Gist) NbCommits() (string, error) { } func (gist *Gist) AddAndCommitFiles(files *[]FileDTO) error { - if err := git.CloneTmp(gist.User.Username, gist.Uuid, gist.Uuid); err != nil { + if err := git.CloneTmp(gist.User.Username, gist.Uuid, gist.Uuid, gist.User.Email); err != nil { return err }