mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 02:57:59 +00:00
Allow stubmaker to work outside of a git repository (#24678)
Co-authored-by: Violet Hynes <violet.hynes@hashicorp.com>
This commit is contained in:
@@ -50,16 +50,22 @@ func main() {
|
||||
DetectDotGit: true,
|
||||
})
|
||||
if err != nil {
|
||||
if err.Error() != "repository does not exist" {
|
||||
fatal(err)
|
||||
}
|
||||
repo = nil
|
||||
}
|
||||
|
||||
wt, err := repo.Worktree()
|
||||
var wt *git.Worktree
|
||||
if repo != nil {
|
||||
wt, err = repo.Worktree()
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
if !isEnterprise(wt) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Read the file and figure out if we need to do anything.
|
||||
inputFile := os.Getenv("GOFILE")
|
||||
@@ -88,6 +94,7 @@ func main() {
|
||||
|
||||
// We'd like to write the file, but first make sure that we're not going
|
||||
// to blow away anyone's work or overwrite a file already in git.
|
||||
if repo != nil {
|
||||
head, err := repo.Head()
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
@@ -109,6 +116,7 @@ func main() {
|
||||
if tracked {
|
||||
fatal(fmt.Errorf("output file %s exists in git, not overwriting", outputFile))
|
||||
}
|
||||
}
|
||||
|
||||
// Now we can finally write the file
|
||||
output, err := os.Create(outputFile + ".tmp")
|
||||
|
||||
Reference in New Issue
Block a user