Skip to content

Commit

Permalink
init: remove .git directory after clone (#487)
Browse files Browse the repository at this point in the history
* init: remove .git directory after clone

* fix bad merge w development
  • Loading branch information
cmcarthur authored and drewbanin committed Jul 14, 2017
1 parent e0430e6 commit 66d8673
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
13 changes: 10 additions & 3 deletions dbt/clients/git.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from dbt.clients.system import run_cmd
import os.path

from dbt.clients.system import run_cmd, rmdir
from dbt.logger import GLOBAL_LOGGER as logger
import dbt.exceptions


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

if dirname is not None:
clone_cmd.append(dirname)

return run_cmd(cwd, clone_cmd)
result = run_cmd(cwd, clone_cmd)

if remove_git_dir:
rmdir(os.path.join(dirname, '.git'))

return result


def list_tags(cwd):
Expand Down
11 changes: 10 additions & 1 deletion dbt/clients/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import fnmatch
import os
import os.path
import sys
import shutil
import subprocess
import sys

from dbt.logger import GLOBAL_LOGGER as logger

Expand Down Expand Up @@ -89,6 +90,14 @@ def make_file(path, contents='', overwrite=False):
return False


def rmdir(path):
"""
Make a file at `path` assuming that the directory it resides in already
exists. The file is saved with contents `contents`
"""
return shutil.rmtree(path)


def open_dir_cmd():
# https://docs.python.org/2/library/sys.html#sys.platform
if sys.platform == 'win32':
Expand Down
4 changes: 3 additions & 1 deletion dbt/task/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@

class InitTask(BaseTask):
def clone_starter_repo(self, project_name):
dbt.clients.git.clone(STARTER_REPO, '.', project_name)
dbt.clients.git.clone(
STARTER_REPO, '.', project_name,
remove_git_dir=True)
dbt.clients.git.remove_remote(project_name)

def create_profiles_dir(self, profiles_dir):
Expand Down

0 comments on commit 66d8673

Please sign in to comment.