Skip to content

Commit

Permalink
Merge pull request #2420 from fishtown-analytics/fix/dbt-init-v2-project
Browse files Browse the repository at this point in the history
Fix dbt init to clone a v2 project (#2404)
  • Loading branch information
beckjake authored May 8, 2020
2 parents c9eec4f + 2cd98c2 commit 8686ab9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
9 changes: 7 additions & 2 deletions core/dbt/clients/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
import dbt.exceptions


def clone(repo, cwd, dirname=None, remove_git_dir=False):
clone_cmd = ['git', 'clone', '--depth', '1', repo]
def clone(repo, cwd, dirname=None, remove_git_dir=False, branch=None):
clone_cmd = ['git', 'clone', '--depth', '1']

if branch is not None:
clone_cmd.extend(['--branch', branch])

clone_cmd.append(repo)

if dirname is not None:
clone_cmd.append(dirname)
Expand Down
9 changes: 7 additions & 2 deletions core/dbt/task/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dbt.task.base import BaseTask

STARTER_REPO = 'https://github.com/fishtown-analytics/dbt-starter-project.git'
STARTER_BRANCH = 'dbt-yml-config-version-2'
DOCS_URL = 'https://docs.getdbt.com/docs/configure-your-profile'
SAMPLE_PROFILES_YML_FILE = 'https://docs.getdbt.com/docs/profile' # noqa

Expand Down Expand Up @@ -62,8 +63,12 @@
class InitTask(BaseTask):
def clone_starter_repo(self, project_name):
dbt.clients.git.clone(
STARTER_REPO, '.', project_name,
remove_git_dir=True)
STARTER_REPO,
cwd='.',
dirname=project_name,
remove_git_dir=True,
branch=STARTER_BRANCH,
)

def create_profiles_dir(self, profiles_dir):
if not os.path.exists(profiles_dir):
Expand Down
16 changes: 9 additions & 7 deletions test/integration/040_init_test/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from test.integration.base import DBTIntegrationTest, use_profile
import os
import shutil
import yaml


class TestInit(DBTIntegrationTest):
Expand Down Expand Up @@ -29,13 +30,14 @@ def test_postgres_init_task(self):
project_name = self.get_project_name()
self.run_dbt(['init', project_name])

dir_exists = os.path.exists(project_name)
assert os.path.exists(project_name)
project_file = os.path.join(project_name, 'dbt_project.yml')
project_file_exists = os.path.exists(project_file)
assert os.path.exists(project_file)
with open(project_file) as fp:
project_data = yaml.safe_load(fp.read())

git_dir = os.path.join(project_name, '.git')
git_dir_exists = os.path.exists(git_dir)
assert 'config-version' in project_data
assert project_data['config-version'] == 2

self.assertTrue(dir_exists)
self.assertTrue(project_file_exists)
self.assertFalse(git_dir_exists)
git_dir = os.path.join(project_name, '.git')
assert not os.path.exists(git_dir)

0 comments on commit 8686ab9

Please sign in to comment.