Repository: dbt-labs/dbt-core

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.


Discussion:
Good call :)
@jtcohen6 , @clrcrl 
I want to pick up this task if nobody minds

Here is my ideas:
1. Add new method to client/git.py default_branch(repo) that will get the value of default branch from the git configuration using CLI git remote show [repository]
2. Modify deps/git.py@resolved 
instead of hard coded 'master' assign result value from _default_branch_ 
https://github.com/fishtown-analytics/dbt/blob/c8f0469a44f84cfc7d48cb6b938c6cd27288feba/core/dbt/deps/git.py#L136
3. Modify deps/git.py@_fetch_metadata
check self.revision for ('master', 'main')
https://github.com/fishtown-analytics/dbt/blob/c8f0469a44f84cfc7d48cb6b938c6cd27288feba/core/dbt/deps/git.py#L75

And one more possible change that is out of the scope but is related
1. Modify clients/git.py@checkout 
instead of hard coded 'master' assign result value from the _default_branch_ 
https://github.com/fishtown-analytics/dbt/blob/c8f0469a44f84cfc7d48cb6b938c6cd27288feba/core/dbt/clients/git.py#L55


@VasiliiSurov Thanks for your interest! We'd welcome a contribution for this, and your proposal sounds solid.

I imagine we may also wish to update the unit test here:

https://github.com/fishtown-analytics/dbt/blob/c8f0469a44f84cfc7d48cb6b938c6cd27288feba/test/unit/test_deps.py#L95-L109

Let me know if I can be of any help :)
💡 just jotting down my thoughts here, I haven't tested this out. I know this applies to GitHub: after running `git clone` the default branch defined in GitHub will be checked out locally. When there is no `version` supplied for a package in `packages.yml`, we should probably:
- after cloning the package, either skip checking out anything or check out the current branch (maybe even use `HEAD` here?)
- ensure unpinned warning is displayed

There should be no reference to `master` after these changed.


When the `version` supplied for a package is a branch name, we could:
- check if the `version` points to a branch as opposed to a tag and display an appropriate warning.

I apologize if this is repeating or different than was is mentioned above! I think the main issue here is `git` has no notion of default branch, so `git clone` is the important piece to get this info from. 
@kwigley If I correctly understood your idea we can achieve it by simple replacing 'master' to 'HEAD' in the same 3 lines I mentioned before and no need to jump through hoops to get the name of the default branch.

Resolving patch:
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):
 
 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 _checkout(self):
 
     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 incorporate(
     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. '


Test patch:
diff --git a/test/unit/test_deps.py b/test/unit/test_deps.py
--- a/test/unit/test_deps.py
+++ b/test/unit/test_deps.py
@@ -104,7 +104,7 @@ def test_default_revision(self):
 
         a_pinned = a.resolved()
         self.assertEqual(a_pinned.name, 'http://example.com')
-        self.assertEqual(a_pinned.get_version(), 'master')
+        self.assertEqual(a_pinned.get_version(), 'HEAD')
         self.assertEqual(a_pinned.source_type(), 'git')
         self.assertIs(a_pinned.warn_unpinned, True)