mirror of https://github.com/databricks/cli.git
Function to find the Git repository containing a bundle (#289)
## Changes Useful functions from #277. ## Tests Tests pass.
This commit is contained in:
parent
8fd3dccca9
commit
8af934bbbb
|
@ -7,11 +7,14 @@
|
||||||
package bundle
|
package bundle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/databricks/bricks/bundle/config"
|
"github.com/databricks/bricks/bundle/config"
|
||||||
|
"github.com/databricks/bricks/folders"
|
||||||
|
"github.com/databricks/bricks/libs/git"
|
||||||
"github.com/databricks/bricks/libs/locker"
|
"github.com/databricks/bricks/libs/locker"
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
"github.com/hashicorp/terraform-exec/tfexec"
|
"github.com/hashicorp/terraform-exec/tfexec"
|
||||||
|
@ -115,3 +118,12 @@ func (b *Bundle) CacheDir(paths ...string) (string, error) {
|
||||||
|
|
||||||
return dir, nil
|
return dir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bundle) GitRepository() (*git.Repository, error) {
|
||||||
|
rootPath, err := folders.FindDirWithLeaf(b.Config.Path, ".git")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to locate repository root: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return git.NewRepository(rootPath)
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,11 @@ type Repository struct {
|
||||||
ignore map[string][]ignoreRules
|
ignore map[string][]ignoreRules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Root returns the repository root.
|
||||||
|
func (r *Repository) Root() string {
|
||||||
|
return r.rootPath
|
||||||
|
}
|
||||||
|
|
||||||
// loadConfig loads and combines user specific and repository specific configuration files.
|
// loadConfig loads and combines user specific and repository specific configuration files.
|
||||||
func (r *Repository) loadConfig() (*config, error) {
|
func (r *Repository) loadConfig() (*config, error) {
|
||||||
config, err := globalGitConfig()
|
config, err := globalGitConfig()
|
||||||
|
|
|
@ -26,6 +26,9 @@ func TestRepository(t *testing.T) {
|
||||||
tr := testRepository{t, repo}
|
tr := testRepository{t, repo}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Check that the root path is real.
|
||||||
|
assert.True(t, filepath.IsAbs(repo.Root()))
|
||||||
|
|
||||||
// Check that top level ignores work.
|
// Check that top level ignores work.
|
||||||
assert.True(t, tr.Ignore(".DS_Store"))
|
assert.True(t, tr.Ignore(".DS_Store"))
|
||||||
assert.True(t, tr.Ignore("foo.pyc"))
|
assert.True(t, tr.Ignore("foo.pyc"))
|
||||||
|
|
Loading…
Reference in New Issue