mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +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,15 +50,21 @@ func main() {
|
|||||||
DetectDotGit: true,
|
DetectDotGit: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
if err.Error() != "repository does not exist" {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
repo = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
wt, err := repo.Worktree()
|
var wt *git.Worktree
|
||||||
if err != nil {
|
if repo != nil {
|
||||||
fatal(err)
|
wt, err = repo.Worktree()
|
||||||
}
|
if err != nil {
|
||||||
if !isEnterprise(wt) {
|
fatal(err)
|
||||||
return
|
}
|
||||||
|
if !isEnterprise(wt) {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the file and figure out if we need to do anything.
|
// Read the file and figure out if we need to do anything.
|
||||||
@@ -88,26 +94,28 @@ func main() {
|
|||||||
|
|
||||||
// We'd like to write the file, but first make sure that we're not going
|
// 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.
|
// to blow away anyone's work or overwrite a file already in git.
|
||||||
head, err := repo.Head()
|
if repo != nil {
|
||||||
if err != nil {
|
head, err := repo.Head()
|
||||||
fatal(err)
|
if err != nil {
|
||||||
}
|
fatal(err)
|
||||||
obj, err := repo.Object(plumbing.AnyObject, head.Hash())
|
}
|
||||||
if err != nil {
|
obj, err := repo.Object(plumbing.AnyObject, head.Hash())
|
||||||
fatal(err)
|
if err != nil {
|
||||||
}
|
fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
st, err := wt.Status()
|
st, err := wt.Status()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tracked, err := inGit(wt, st, obj, outputFile)
|
tracked, err := inGit(wt, st, obj, outputFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
if tracked {
|
if tracked {
|
||||||
fatal(fmt.Errorf("output file %s exists in git, not overwriting", outputFile))
|
fatal(fmt.Errorf("output file %s exists in git, not overwriting", outputFile))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we can finally write the file
|
// Now we can finally write the file
|
||||||
|
|||||||
Reference in New Issue
Block a user