We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
dbt deps does not handle non-master default branch
### Steps to reproduce
1. Add a package using a the git syntax. The package must use a default branch other than `master`. In this example, the default branch is `main` (this package is currently an internal package but will be public soon)
```
$ cat packages.yml
packages:
  - git: git@github.com:fishtown-analytics/dbt-artifacts.git
    
```

2. Run `dbt deps`
```
$ dbt deps
Running with dbt=0.19.0
Encountered an error:
Error checking out spec='master' for repo git@github.com:fishtown-analytics/dbt-artifacts.git
fatal: couldn't find remote ref master
```

### Expected behavior
Package should install from the default branch, `main` and warn about an unpinned package

If I do specify `revision: main`, I also expect to get an unpinned error, however currently no warning is shown.

### dbt version
0.19.0 :)


### Additional context
[Relevant code](https://github.com/fishtown-analytics/dbt/blob/develop/core/dbt/deps/git.py#L75)

Going to be more common since GitHub updated their default branch name.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `core/dbt/deps/git.py`
Content:
```
1 import os
2 import hashlib
3 from typing import List
4 
5 from dbt.clients import git, system
6 from dbt.config import Project
7 from dbt.contracts.project import (
8     ProjectPackageMetadata,
9     GitPackage,
10 )
11 from dbt.deps.base import PinnedPackage, UnpinnedPackage, get_downloads_path
12 from dbt.exceptions import (
13     ExecutableError, warn_or_error, raise_dependency_error
14 )
15 from dbt.logger import GLOBAL_LOGGER as logger
16 from dbt import ui
17 
18 PIN_PACKAGE_URL = 'https://docs.getdbt.com/docs/package-management#section-specifying-package-versions' # noqa
19 
20 
21 def md5sum(s: str):
22     return hashlib.md5(s.encode('latin-1')).hexdigest()
23 
24 
25 class GitPackageMixin:
26     def __init__(self, git: str) -> None:
27         super().__init__()
28         self.git = git
29 
30     @property
31     def name(self):
32         return self.git
33 
34     def source_type(self) -> str:
35         return 'git'
36 
37 
38 class GitPinnedPackage(GitPackageMixin, PinnedPackage):
39     def __init__(
40         self, git: str, revision: str, warn_unpinned: bool = True
41     ) -> None:
42         super().__init__(git)
43         self.revision = revision
44         self.warn_unpinned = warn_unpinned
45         self._checkout_name = md5sum(self.git)
46 
47     def get_version(self):
48         return self.revision
49 
50     def nice_version_name(self):
51         return 'revision {}'.format(self.revision)
52 
53     def _checkout(self):
54         """Performs a shallow clone of the repository into the downloads
55         directory. This function can be called repeatedly. If the project has
56         already been checked out at this version, it will be a no-op. Returns
57         the path to the checked out directory."""
58         try:
59             dir_ = git.clone_and_checkout(
60                 self.git, get_downloads_path(), branch=self.revision,
61                 dirname=self._checkout_name
62             )
63         except ExecutableError as exc:
64             if exc.cmd and exc.cmd[0] == 'git':
65                 logger.error(
66                     'Make sure git is installed on your machine. More '
67                     'information: '
68                     'https://docs.getdbt.com/docs/package-management'
69                 )
70             raise
71         return os.path.join(get_downloads_path(), dir_)
72 
73     def _fetch_metadata(self, project, renderer) -> ProjectPackageMetadata:
74         path = self._checkout()
75         if self.revision == 'master' and self.warn_unpinned:
76             warn_or_error(
77                 'The git package "{}" is not pinned.\n\tThis can introduce '
78                 'breaking changes into your project without warning!\n\nSee {}'
79                 .format(self.git, PIN_PACKAGE_URL),
80                 log_fmt=ui.yellow('WARNING: {}')
81             )
82         loaded = Project.from_project_root(path, renderer)
83         return ProjectPackageMetadata.from_project(loaded)
84 
85     def install(self, project, renderer):
86         dest_path = self.get_installation_path(project, renderer)
87         if os.path.exists(dest_path):
88             if system.path_is_symlink(dest_path):
89                 system.remove_file(dest_path)
90             else:
91                 system.rmdir(dest_path)
92 
93         system.move(self._checkout(), dest_path)
94 
95 
96 class GitUnpinnedPackage(GitPackageMixin, UnpinnedPackage[GitPinnedPackage]):
97     def __init__(
98         self, git: str, revisions: List[str], warn_unpinned: bool = True
99     ) -> None:
100         super().__init__(git)
101         self.revisions = revisions
102         self.warn_unpinned = warn_unpinned
103 
104     @classmethod
105     def from_contract(
106         cls, contract: GitPackage
107     ) -> 'GitUnpinnedPackage':
108         revisions = contract.get_revisions()
109 
110         # we want to map None -> True
111         warn_unpinned = contract.warn_unpinned is not False
112         return cls(git=contract.git, revisions=revisions,
113                    warn_unpinned=warn_unpinned)
114 
115     def all_names(self) -> List[str]:
116         if self.git.endswith('.git'):
117             other = self.git[:-4]
118         else:
119             other = self.git + '.git'
120         return [self.git, other]
121 
122     def incorporate(
123         self, other: 'GitUnpinnedPackage'
124     ) -> 'GitUnpinnedPackage':
125         warn_unpinned = self.warn_unpinned and other.warn_unpinned
126 
127         return GitUnpinnedPackage(
128             git=self.git,
129             revisions=self.revisions + other.revisions,
130             warn_unpinned=warn_unpinned,
131         )
132 
133     def resolved(self) -> GitPinnedPackage:
134         requested = set(self.revisions)
135         if len(requested) == 0:
136             requested = {'master'}
137         elif len(requested) > 1:
138             raise_dependency_error(
139                 'git dependencies should contain exactly one version. '
140                 '{} contains: {}'.format(self.git, requested))
141 
142         return GitPinnedPackage(
143             git=self.git, revision=requested.pop(),
144             warn_unpinned=self.warn_unpinned
145         )
146
```

Path: `core/dbt/clients/git.py`
Content:
```
1 import re
2 import os.path
3 
4 from dbt.clients.system import run_cmd, rmdir
5 from dbt.logger import GLOBAL_LOGGER as logger
6 import dbt.exceptions
7 
8 
9 def clone(repo, cwd, dirname=None, remove_git_dir=False, branch=None):
10     clone_cmd = ['git', 'clone', '--depth', '1']
11 
12     if branch is not None:
13         clone_cmd.extend(['--branch', branch])
14 
15     clone_cmd.append(repo)
16 
17     if dirname is not None:
18         clone_cmd.append(dirname)
19 
20     result = run_cmd(cwd, clone_cmd, env={'LC_ALL': 'C'})
21 
22     if remove_git_dir:
23         rmdir(os.path.join(dirname, '.git'))
24 
25     return result
26 
27 
28 def list_tags(cwd):
29     out, err = run_cmd(cwd, ['git', 'tag', '--list'], env={'LC_ALL': 'C'})
30     tags = out.decode('utf-8').strip().split("\n")
31     return tags
32 
33 
34 def _checkout(cwd, repo, branch):
35     logger.debug('  Checking out branch {}.'.format(branch))
36 
37     run_cmd(cwd, ['git', 'remote', 'set-branches', 'origin', branch])
38     run_cmd(cwd, ['git', 'fetch', '--tags', '--depth', '1', 'origin', branch])
39 
40     tags = list_tags(cwd)
41 
42     # Prefer tags to branches if one exists
43     if branch in tags:
44         spec = 'tags/{}'.format(branch)
45     else:
46         spec = 'origin/{}'.format(branch)
47 
48     out, err = run_cmd(cwd, ['git', 'reset', '--hard', spec],
49                        env={'LC_ALL': 'C'})
50     return out, err
51 
52 
53 def checkout(cwd, repo, branch=None):
54     if branch is None:
55         branch = 'master'
56     try:
57         return _checkout(cwd, repo, branch)
58     except dbt.exceptions.CommandResultError as exc:
59         stderr = exc.stderr.decode('utf-8').strip()
60     dbt.exceptions.bad_package_spec(repo, branch, stderr)
61 
62 
63 def get_current_sha(cwd):
64     out, err = run_cmd(cwd, ['git', 'rev-parse', 'HEAD'], env={'LC_ALL': 'C'})
65 
66     return out.decode('utf-8')
67 
68 
69 def remove_remote(cwd):
70     return run_cmd(cwd, ['git', 'remote', 'rm', 'origin'], env={'LC_ALL': 'C'})
71 
72 
73 def clone_and_checkout(repo, cwd, dirname=None, remove_git_dir=False,
74                        branch=None):
75     exists = None
76     try:
77         _, err = clone(repo, cwd, dirname=dirname,
78                        remove_git_dir=remove_git_dir)
79     except dbt.exceptions.CommandResultError as exc:
80         err = exc.stderr.decode('utf-8')
81         exists = re.match("fatal: destination path '(.+)' already exists", err)
82         if not exists:  # something else is wrong, raise it
83             raise
84 
85     directory = None
86     start_sha = None
87     if exists:
88         directory = exists.group(1)
89         logger.debug('Updating existing dependency {}.', directory)
90     else:
91         matches = re.match("Cloning into '(.+)'", err.decode('utf-8'))
92         if matches is None:
93             raise dbt.exceptions.RuntimeException(
94                 f'Error cloning {repo} - never saw "Cloning into ..." from git'
95             )
96         directory = matches.group(1)
97         logger.debug('Pulling new dependency {}.', directory)
98     full_path = os.path.join(cwd, directory)
99     start_sha = get_current_sha(full_path)
100     checkout(full_path, repo, branch)
101     end_sha = get_current_sha(full_path)
102     if exists:
103         if start_sha == end_sha:
104             logger.debug('  Already at {}, nothing to do.', start_sha[:7])
105         else:
106             logger.debug('  Updated checkout from {} to {}.',
107                          start_sha[:7], end_sha[:7])
108     else:
109         logger.debug('  Checked out at {}.', end_sha[:7])
110     return directory
111
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/core/dbt/clients/git.py b/core/dbt/clients/git.py
--- a/core/dbt/clients/git.py
+++ b/core/dbt/clients/git.py
@@ -52,7 +52,7 @@
 
 def checkout(cwd, repo, branch=None):
     if branch is None:
-        branch = 'master'
+        branch = 'HEAD'
     try:
         return _checkout(cwd, repo, branch)
     except dbt.exceptions.CommandResultError as exc:
diff --git a/core/dbt/deps/git.py b/core/dbt/deps/git.py
--- a/core/dbt/deps/git.py
+++ b/core/dbt/deps/git.py
@@ -72,7 +72,7 @@
 
     def _fetch_metadata(self, project, renderer) -> ProjectPackageMetadata:
         path = self._checkout()
-        if self.revision == 'master' and self.warn_unpinned:
+        if self.revision == 'HEAD' and self.warn_unpinned:
             warn_or_error(
                 'The git package "{}" is not pinned.\n\tThis can introduce '
                 'breaking changes into your project without warning!\n\nSee {}'
@@ -133,7 +133,7 @@
     def resolved(self) -> GitPinnedPackage:
         requested = set(self.revisions)
         if len(requested) == 0:
-            requested = {'master'}
+            requested = {'HEAD'}
         elif len(requested) > 1:
             raise_dependency_error(
                 'git dependencies should contain exactly one version. '

{"golden_diff": "diff --git a/core/dbt/clients/git.py b/core/dbt/clients/git.py\n--- a/core/dbt/clients/git.py\n+++ b/core/dbt/clients/git.py\n@@ -52,7 +52,7 @@\n \n def checkout(cwd, repo, branch=None):\n     if branch is None:\n-        branch = 'master'\n+        branch = 'HEAD'\n     try:\n         return _checkout(cwd, repo, branch)\n     except dbt.exceptions.CommandResultError as exc:\ndiff --git a/core/dbt/deps/git.py b/core/dbt/deps/git.py\n--- a/core/dbt/deps/git.py\n+++ b/core/dbt/deps/git.py\n@@ -72,7 +72,7 @@\n \n     def _fetch_metadata(self, project, renderer) -> ProjectPackageMetadata:\n         path = self._checkout()\n-        if self.revision == 'master' and self.warn_unpinned:\n+        if self.revision == 'HEAD' and self.warn_unpinned:\n             warn_or_error(\n                 'The git package \"{}\" is not pinned.\\n\\tThis can introduce '\n                 'breaking changes into your project without warning!\\n\\nSee {}'\n@@ -133,7 +133,7 @@\n     def resolved(self) -> GitPinnedPackage:\n         requested = set(self.revisions)\n         if len(requested) == 0:\n-            requested = {'master'}\n+            requested = {'HEAD'}\n         elif len(requested) > 1:\n             raise_dependency_error(\n                 'git dependencies should contain exactly one version. '\n", "issue": "dbt deps does not handle non-master default branch\n### Steps to reproduce\r\n1. Add a package using a the git syntax. The package must use a default branch other than `master`. In this example, the default branch is `main` (this package is currently an internal package but will be public soon)\r\n```\r\n$ cat packages.yml\r\npackages:\r\n  - git: git@github.com:fishtown-analytics/dbt-artifacts.git\r\n    \r\n```\r\n\r\n2. Run `dbt deps`\r\n```\r\n$ dbt deps\r\nRunning with dbt=0.19.0\r\nEncountered an error:\r\nError checking out spec='master' for repo git@github.com:fishtown-analytics/dbt-artifacts.git\r\nfatal: couldn't find remote ref master\r\n```\r\n\r\n### Expected behavior\r\nPackage should install from the default branch, `main` and warn about an unpinned package\r\n\r\nIf I do specify `revision: main`, I also expect to get an unpinned error, however currently no warning is shown.\r\n\r\n### dbt version\r\n0.19.0 :)\r\n\r\n\r\n### Additional context\r\n[Relevant code](https://github.com/fishtown-analytics/dbt/blob/develop/core/dbt/deps/git.py#L75)\r\n\r\nGoing to be more common since GitHub updated their default branch name.\n", "before_files": [{"content": "import os\nimport hashlib\nfrom typing import List\n\nfrom dbt.clients import git, system\nfrom dbt.config import Project\nfrom dbt.contracts.project import (\n    ProjectPackageMetadata,\n    GitPackage,\n)\nfrom dbt.deps.base import PinnedPackage, UnpinnedPackage, get_downloads_path\nfrom dbt.exceptions import (\n    ExecutableError, warn_or_error, raise_dependency_error\n)\nfrom dbt.logger import GLOBAL_LOGGER as logger\nfrom dbt import ui\n\nPIN_PACKAGE_URL = 'https://docs.getdbt.com/docs/package-management#section-specifying-package-versions' # noqa\n\n\ndef md5sum(s: str):\n    return hashlib.md5(s.encode('latin-1')).hexdigest()\n\n\nclass GitPackageMixin:\n    def __init__(self, git: str) -> None:\n        super().__init__()\n        self.git = git\n\n    @property\n    def name(self):\n        return self.git\n\n    def source_type(self) -> str:\n        return 'git'\n\n\nclass GitPinnedPackage(GitPackageMixin, PinnedPackage):\n    def __init__(\n        self, git: str, revision: str, warn_unpinned: bool = True\n    ) -> None:\n        super().__init__(git)\n        self.revision = revision\n        self.warn_unpinned = warn_unpinned\n        self._checkout_name = md5sum(self.git)\n\n    def get_version(self):\n        return self.revision\n\n    def nice_version_name(self):\n        return 'revision {}'.format(self.revision)\n\n    def _checkout(self):\n        \"\"\"Performs a shallow clone of the repository into the downloads\n        directory. This function can be called repeatedly. If the project has\n        already been checked out at this version, it will be a no-op. Returns\n        the path to the checked out directory.\"\"\"\n        try:\n            dir_ = git.clone_and_checkout(\n                self.git, get_downloads_path(), branch=self.revision,\n                dirname=self._checkout_name\n            )\n        except ExecutableError as exc:\n            if exc.cmd and exc.cmd[0] == 'git':\n                logger.error(\n                    'Make sure git is installed on your machine. More '\n                    'information: '\n                    'https://docs.getdbt.com/docs/package-management'\n                )\n            raise\n        return os.path.join(get_downloads_path(), dir_)\n\n    def _fetch_metadata(self, project, renderer) -> ProjectPackageMetadata:\n        path = self._checkout()\n        if self.revision == 'master' and self.warn_unpinned:\n            warn_or_error(\n                'The git package \"{}\" is not pinned.\\n\\tThis can introduce '\n                'breaking changes into your project without warning!\\n\\nSee {}'\n                .format(self.git, PIN_PACKAGE_URL),\n                log_fmt=ui.yellow('WARNING: {}')\n            )\n        loaded = Project.from_project_root(path, renderer)\n        return ProjectPackageMetadata.from_project(loaded)\n\n    def install(self, project, renderer):\n        dest_path = self.get_installation_path(project, renderer)\n        if os.path.exists(dest_path):\n            if system.path_is_symlink(dest_path):\n                system.remove_file(dest_path)\n            else:\n                system.rmdir(dest_path)\n\n        system.move(self._checkout(), dest_path)\n\n\nclass GitUnpinnedPackage(GitPackageMixin, UnpinnedPackage[GitPinnedPackage]):\n    def __init__(\n        self, git: str, revisions: List[str], warn_unpinned: bool = True\n    ) -> None:\n        super().__init__(git)\n        self.revisions = revisions\n        self.warn_unpinned = warn_unpinned\n\n    @classmethod\n    def from_contract(\n        cls, contract: GitPackage\n    ) -> 'GitUnpinnedPackage':\n        revisions = contract.get_revisions()\n\n        # we want to map None -> True\n        warn_unpinned = contract.warn_unpinned is not False\n        return cls(git=contract.git, revisions=revisions,\n                   warn_unpinned=warn_unpinned)\n\n    def all_names(self) -> List[str]:\n        if self.git.endswith('.git'):\n            other = self.git[:-4]\n        else:\n            other = self.git + '.git'\n        return [self.git, other]\n\n    def incorporate(\n        self, other: 'GitUnpinnedPackage'\n    ) -> 'GitUnpinnedPackage':\n        warn_unpinned = self.warn_unpinned and other.warn_unpinned\n\n        return GitUnpinnedPackage(\n            git=self.git,\n            revisions=self.revisions + other.revisions,\n            warn_unpinned=warn_unpinned,\n        )\n\n    def resolved(self) -> GitPinnedPackage:\n        requested = set(self.revisions)\n        if len(requested) == 0:\n            requested = {'master'}\n        elif len(requested) > 1:\n            raise_dependency_error(\n                'git dependencies should contain exactly one version. '\n                '{} contains: {}'.format(self.git, requested))\n\n        return GitPinnedPackage(\n            git=self.git, revision=requested.pop(),\n            warn_unpinned=self.warn_unpinned\n        )\n", "path": "core/dbt/deps/git.py"}, {"content": "import re\nimport os.path\n\nfrom dbt.clients.system import run_cmd, rmdir\nfrom dbt.logger import GLOBAL_LOGGER as logger\nimport dbt.exceptions\n\n\ndef clone(repo, cwd, dirname=None, remove_git_dir=False, branch=None):\n    clone_cmd = ['git', 'clone', '--depth', '1']\n\n    if branch is not None:\n        clone_cmd.extend(['--branch', branch])\n\n    clone_cmd.append(repo)\n\n    if dirname is not None:\n        clone_cmd.append(dirname)\n\n    result = run_cmd(cwd, clone_cmd, env={'LC_ALL': 'C'})\n\n    if remove_git_dir:\n        rmdir(os.path.join(dirname, '.git'))\n\n    return result\n\n\ndef list_tags(cwd):\n    out, err = run_cmd(cwd, ['git', 'tag', '--list'], env={'LC_ALL': 'C'})\n    tags = out.decode('utf-8').strip().split(\"\\n\")\n    return tags\n\n\ndef _checkout(cwd, repo, branch):\n    logger.debug('  Checking out branch {}.'.format(branch))\n\n    run_cmd(cwd, ['git', 'remote', 'set-branches', 'origin', branch])\n    run_cmd(cwd, ['git', 'fetch', '--tags', '--depth', '1', 'origin', branch])\n\n    tags = list_tags(cwd)\n\n    # Prefer tags to branches if one exists\n    if branch in tags:\n        spec = 'tags/{}'.format(branch)\n    else:\n        spec = 'origin/{}'.format(branch)\n\n    out, err = run_cmd(cwd, ['git', 'reset', '--hard', spec],\n                       env={'LC_ALL': 'C'})\n    return out, err\n\n\ndef checkout(cwd, repo, branch=None):\n    if branch is None:\n        branch = 'master'\n    try:\n        return _checkout(cwd, repo, branch)\n    except dbt.exceptions.CommandResultError as exc:\n        stderr = exc.stderr.decode('utf-8').strip()\n    dbt.exceptions.bad_package_spec(repo, branch, stderr)\n\n\ndef get_current_sha(cwd):\n    out, err = run_cmd(cwd, ['git', 'rev-parse', 'HEAD'], env={'LC_ALL': 'C'})\n\n    return out.decode('utf-8')\n\n\ndef remove_remote(cwd):\n    return run_cmd(cwd, ['git', 'remote', 'rm', 'origin'], env={'LC_ALL': 'C'})\n\n\ndef clone_and_checkout(repo, cwd, dirname=None, remove_git_dir=False,\n                       branch=None):\n    exists = None\n    try:\n        _, err = clone(repo, cwd, dirname=dirname,\n                       remove_git_dir=remove_git_dir)\n    except dbt.exceptions.CommandResultError as exc:\n        err = exc.stderr.decode('utf-8')\n        exists = re.match(\"fatal: destination path '(.+)' already exists\", err)\n        if not exists:  # something else is wrong, raise it\n            raise\n\n    directory = None\n    start_sha = None\n    if exists:\n        directory = exists.group(1)\n        logger.debug('Updating existing dependency {}.', directory)\n    else:\n        matches = re.match(\"Cloning into '(.+)'\", err.decode('utf-8'))\n        if matches is None:\n            raise dbt.exceptions.RuntimeException(\n                f'Error cloning {repo} - never saw \"Cloning into ...\" from git'\n            )\n        directory = matches.group(1)\n        logger.debug('Pulling new dependency {}.', directory)\n    full_path = os.path.join(cwd, directory)\n    start_sha = get_current_sha(full_path)\n    checkout(full_path, repo, branch)\n    end_sha = get_current_sha(full_path)\n    if exists:\n        if start_sha == end_sha:\n            logger.debug('  Already at {}, nothing to do.', start_sha[:7])\n        else:\n            logger.debug('  Updated checkout from {} to {}.',\n                         start_sha[:7], end_sha[:7])\n    else:\n        logger.debug('  Checked out at {}.', end_sha[:7])\n    return directory\n", "path": "core/dbt/clients/git.py"}], "after_files": [{"content": "import os\nimport hashlib\nfrom typing import List\n\nfrom dbt.clients import git, system\nfrom dbt.config import Project\nfrom dbt.contracts.project import (\n    ProjectPackageMetadata,\n    GitPackage,\n)\nfrom dbt.deps.base import PinnedPackage, UnpinnedPackage, get_downloads_path\nfrom dbt.exceptions import (\n    ExecutableError, warn_or_error, raise_dependency_error\n)\nfrom dbt.logger import GLOBAL_LOGGER as logger\nfrom dbt import ui\n\nPIN_PACKAGE_URL = 'https://docs.getdbt.com/docs/package-management#section-specifying-package-versions' # noqa\n\n\ndef md5sum(s: str):\n    return hashlib.md5(s.encode('latin-1')).hexdigest()\n\n\nclass GitPackageMixin:\n    def __init__(self, git: str) -> None:\n        super().__init__()\n        self.git = git\n\n    @property\n    def name(self):\n        return self.git\n\n    def source_type(self) -> str:\n        return 'git'\n\n\nclass GitPinnedPackage(GitPackageMixin, PinnedPackage):\n    def __init__(\n        self, git: str, revision: str, warn_unpinned: bool = True\n    ) -> None:\n        super().__init__(git)\n        self.revision = revision\n        self.warn_unpinned = warn_unpinned\n        self._checkout_name = md5sum(self.git)\n\n    def get_version(self):\n        return self.revision\n\n    def nice_version_name(self):\n        return 'revision {}'.format(self.revision)\n\n    def _checkout(self):\n        \"\"\"Performs a shallow clone of the repository into the downloads\n        directory. This function can be called repeatedly. If the project has\n        already been checked out at this version, it will be a no-op. Returns\n        the path to the checked out directory.\"\"\"\n        try:\n            dir_ = git.clone_and_checkout(\n                self.git, get_downloads_path(), branch=self.revision,\n                dirname=self._checkout_name\n            )\n        except ExecutableError as exc:\n            if exc.cmd and exc.cmd[0] == 'git':\n                logger.error(\n                    'Make sure git is installed on your machine. More '\n                    'information: '\n                    'https://docs.getdbt.com/docs/package-management'\n                )\n            raise\n        return os.path.join(get_downloads_path(), dir_)\n\n    def _fetch_metadata(self, project, renderer) -> ProjectPackageMetadata:\n        path = self._checkout()\n        if self.revision == 'HEAD' and self.warn_unpinned:\n            warn_or_error(\n                'The git package \"{}\" is not pinned.\\n\\tThis can introduce '\n                'breaking changes into your project without warning!\\n\\nSee {}'\n                .format(self.git, PIN_PACKAGE_URL),\n                log_fmt=ui.yellow('WARNING: {}')\n            )\n        loaded = Project.from_project_root(path, renderer)\n        return ProjectPackageMetadata.from_project(loaded)\n\n    def install(self, project, renderer):\n        dest_path = self.get_installation_path(project, renderer)\n        if os.path.exists(dest_path):\n            if system.path_is_symlink(dest_path):\n                system.remove_file(dest_path)\n            else:\n                system.rmdir(dest_path)\n\n        system.move(self._checkout(), dest_path)\n\n\nclass GitUnpinnedPackage(GitPackageMixin, UnpinnedPackage[GitPinnedPackage]):\n    def __init__(\n        self, git: str, revisions: List[str], warn_unpinned: bool = True\n    ) -> None:\n        super().__init__(git)\n        self.revisions = revisions\n        self.warn_unpinned = warn_unpinned\n\n    @classmethod\n    def from_contract(\n        cls, contract: GitPackage\n    ) -> 'GitUnpinnedPackage':\n        revisions = contract.get_revisions()\n\n        # we want to map None -> True\n        warn_unpinned = contract.warn_unpinned is not False\n        return cls(git=contract.git, revisions=revisions,\n                   warn_unpinned=warn_unpinned)\n\n    def all_names(self) -> List[str]:\n        if self.git.endswith('.git'):\n            other = self.git[:-4]\n        else:\n            other = self.git + '.git'\n        return [self.git, other]\n\n    def incorporate(\n        self, other: 'GitUnpinnedPackage'\n    ) -> 'GitUnpinnedPackage':\n        warn_unpinned = self.warn_unpinned and other.warn_unpinned\n\n        return GitUnpinnedPackage(\n            git=self.git,\n            revisions=self.revisions + other.revisions,\n            warn_unpinned=warn_unpinned,\n        )\n\n    def resolved(self) -> GitPinnedPackage:\n        requested = set(self.revisions)\n        if len(requested) == 0:\n            requested = {'HEAD'}\n        elif len(requested) > 1:\n            raise_dependency_error(\n                'git dependencies should contain exactly one version. '\n                '{} contains: {}'.format(self.git, requested))\n\n        return GitPinnedPackage(\n            git=self.git, revision=requested.pop(),\n            warn_unpinned=self.warn_unpinned\n        )\n", "path": "core/dbt/deps/git.py"}, {"content": "import re\nimport os.path\n\nfrom dbt.clients.system import run_cmd, rmdir\nfrom dbt.logger import GLOBAL_LOGGER as logger\nimport dbt.exceptions\n\n\ndef clone(repo, cwd, dirname=None, remove_git_dir=False, branch=None):\n    clone_cmd = ['git', 'clone', '--depth', '1']\n\n    if branch is not None:\n        clone_cmd.extend(['--branch', branch])\n\n    clone_cmd.append(repo)\n\n    if dirname is not None:\n        clone_cmd.append(dirname)\n\n    result = run_cmd(cwd, clone_cmd, env={'LC_ALL': 'C'})\n\n    if remove_git_dir:\n        rmdir(os.path.join(dirname, '.git'))\n\n    return result\n\n\ndef list_tags(cwd):\n    out, err = run_cmd(cwd, ['git', 'tag', '--list'], env={'LC_ALL': 'C'})\n    tags = out.decode('utf-8').strip().split(\"\\n\")\n    return tags\n\n\ndef _checkout(cwd, repo, branch):\n    logger.debug('  Checking out branch {}.'.format(branch))\n\n    run_cmd(cwd, ['git', 'remote', 'set-branches', 'origin', branch])\n    run_cmd(cwd, ['git', 'fetch', '--tags', '--depth', '1', 'origin', branch])\n\n    tags = list_tags(cwd)\n\n    # Prefer tags to branches if one exists\n    if branch in tags:\n        spec = 'tags/{}'.format(branch)\n    else:\n        spec = 'origin/{}'.format(branch)\n\n    out, err = run_cmd(cwd, ['git', 'reset', '--hard', spec],\n                       env={'LC_ALL': 'C'})\n    return out, err\n\n\ndef checkout(cwd, repo, branch=None):\n    if branch is None:\n        branch = 'HEAD'\n    try:\n        return _checkout(cwd, repo, branch)\n    except dbt.exceptions.CommandResultError as exc:\n        stderr = exc.stderr.decode('utf-8').strip()\n    dbt.exceptions.bad_package_spec(repo, branch, stderr)\n\n\ndef get_current_sha(cwd):\n    out, err = run_cmd(cwd, ['git', 'rev-parse', 'HEAD'], env={'LC_ALL': 'C'})\n\n    return out.decode('utf-8')\n\n\ndef remove_remote(cwd):\n    return run_cmd(cwd, ['git', 'remote', 'rm', 'origin'], env={'LC_ALL': 'C'})\n\n\ndef clone_and_checkout(repo, cwd, dirname=None, remove_git_dir=False,\n                       branch=None):\n    exists = None\n    try:\n        _, err = clone(repo, cwd, dirname=dirname,\n                       remove_git_dir=remove_git_dir)\n    except dbt.exceptions.CommandResultError as exc:\n        err = exc.stderr.decode('utf-8')\n        exists = re.match(\"fatal: destination path '(.+)' already exists\", err)\n        if not exists:  # something else is wrong, raise it\n            raise\n\n    directory = None\n    start_sha = None\n    if exists:\n        directory = exists.group(1)\n        logger.debug('Updating existing dependency {}.', directory)\n    else:\n        matches = re.match(\"Cloning into '(.+)'\", err.decode('utf-8'))\n        if matches is None:\n            raise dbt.exceptions.RuntimeException(\n                f'Error cloning {repo} - never saw \"Cloning into ...\" from git'\n            )\n        directory = matches.group(1)\n        logger.debug('Pulling new dependency {}.', directory)\n    full_path = os.path.join(cwd, directory)\n    start_sha = get_current_sha(full_path)\n    checkout(full_path, repo, branch)\n    end_sha = get_current_sha(full_path)\n    if exists:\n        if start_sha == end_sha:\n            logger.debug('  Already at {}, nothing to do.', start_sha[:7])\n        else:\n            logger.debug('  Updated checkout from {} to {}.',\n                         start_sha[:7], end_sha[:7])\n    else:\n        logger.debug('  Checked out at {}.', end_sha[:7])\n    return directory\n", "path": "core/dbt/clients/git.py"}]}