Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init: remove .git directory after clone #487

Merged
merged 2 commits into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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