harbur / captain

Captain - Convert your Git workflow to Docker :whale: containers
MIT License
766 stars 51 forks source link

Captain push -Bc fails when on a tag #85

Open jwliechty opened 5 years ago

jwliechty commented 5 years ago

If on a tag of a git repository (for instance v3.0 and doing a captain push -Bc, there is an error where captain tries to create a docker tag with the name (HEAD detached at v3.0). This is because the getBranches function uses the following command to get all the branch names.

git branch --no-column --contains HEAD

Which gives the output (on my system)

* (HEAD detached at v3.0)
  b-four
  b-one
  b-three
  b-two
  master

The other interesting thing is that it uses the --contains flag. Instead, I think this should be the --points-at. If pushing up docker contains for tagged with branches, wouldn't you want to do so only for those branches whose HEAD is the same as what you currently have checked out? As it stands, the --contains will grab any branch that has the HEAD commit. This means that if on master and pushing with -B, master and develop will get tagged and pushed up even if develop is ahead of master in commits.

I have a pull request which addresses both of these concerns with tests!

Please review and accept!