terra-ops / terra-cli

The Terra Command Line Interface
http://terra.readthedocs.org
GNU General Public License v2.0
48 stars 17 forks source link

Update Version when branch changes #125

Open jameswilson opened 8 years ago

jameswilson commented 8 years ago

I believe it may be a caching thing where the App Environment Version gets cached based on the git branch you use when you create the environment. If you switch branches at some point, this information is not updated when you do a terra status <appname>, it lists the branch name you used when you cloned the code.

jonpugh commented 8 years ago

Yeah.... this one is tricky. I'm not sure we should store branch name at all in the metadata. It's very fast to extract it from the git repo itself.

That said we want to know the version, and we need to let the user choose the version, so we should...

  1. Remove it from the environments config. Make sure the desired branch is still passed to the git clone in environment:add and the git checkout in environment:deploy.
  2. Add a getVersion() method to EnvironmentFactory that figures out the actual branch or tag, straight from the git repo. I already do this in devshop in a nice little hack: https://github.com/opendevshop/devmaster/blob/1.x/modules/devshop/devshop_projects/projects.inc#L304

    // Get the actual tag or branch
    $environment->git_ref = trim(str_replace('refs/heads/', '', shell_exec("cd {$environment->repo_root}; git describe --tags --exact-match || git symbolic-ref -q HEAD")));
  3. Implement getVersion() wherever we wanted to show environment version.