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

Prevent erroneous remote tracking branch modification by salt.formulas #238

Closed
myii opened this issue Jun 29, 2016 · 1 comment
Closed

Comments

@myii
Copy link
Member

myii commented Jun 29, 2016

Problem definition

Starting point
salt_formulas:
  git_opts:
    default:
      baseurl: git@github.com:myii
$ git remote -v
origin  git@github.com:myii/nginx-formula.git (fetch)
origin  git@github.com:myii/nginx-formula.git (push)
upstream        git@github.com:saltstack-formulas/nginx-formula.git (fetch)
upstream        git@github.com:saltstack-formulas/nginx-formula.git (push)
$ git branch -vv
  master   5fc7685 [origin/master] Merge pull request #103 from percipient/fix-nginx-kill
* upstream 5fc7685 [upstream/master: behind 28] Merge pull request #103 from percipient/fix-nginx-kill
  • Note that the upstream branch is currently checked out, which tracks upstream/master
Issue after running salt.formulas
# salt 'my_minion' state.sls salt.formulas

...

          ID: /srv/Salt/formulas/nginx-formula
    Function: git.latest
        Name: git@github.com:myii/nginx-formula.git
      Result: True
     Comment: Repository /srv/Salt/formulas/nginx-formula is up-to-date

              Changes made: Tracking branch was updated to origin/master
     Started: 17:30:58.774605
    Duration: 3006.362 ms
     Changes:
$ git branch -vv
  master   5fc7685 [origin/master] Merge pull request #103 from percipient/fix-nginx-kill
* upstream 5fc7685 [origin/master] Merge pull request #103 from percipient/fix-nginx-kill
  • Unwanted remote tracking branch modification from upstream/master to origin/master

Suggested solution

Already understood that this can be avoided by adding the branch option to the pillar:

salt_formulas:
  git_opts:
    default:
      options:
        branch: master

However, suggesting to add a conditional block to the git.latest state in formulas.sls, setting the branch: master option by default, if no specific value set in the pillar:

{{ gitdir }}:
  git.latest:
    - name: {{ baseurl }}/{{ entry }}.git
    - target: {{ gitdir }}
    {%- if 'branch' not in options.items() %}
    - branch: master
    {%- endif %}
    {%- for key, value in options.items() %}
    - {{ key }}: {{ value }}
    {%- endfor %}
    ...

This then avoids the problem outlined above:

# salt 'my_minion' state.sls salt.formulas

...

          ID: /srv/Salt/formulas/nginx-formula
    Function: git.latest
        Name: git@github.com:myii/nginx-formula.git
      Result: True
     Comment: Repository /srv/Salt/formulas/nginx-formula is up-to-date

              Changes made: 'master' was checked out
     Started: 17:37:55.763145
    Duration: 3842.103 ms
     Changes:

Notes

Another side effect of this issue is that the remote tracking branch is set whichever branch is currently checked out, such as a local dev branch:

* dev      5fc7685 Merge pull request #103 from percipient/fix-nginx-kill

Unfortunately becomes:

* dev      5fc7685 [origin/master] Merge pull request #103 from percipient/fix-nginx-kill

Happy to submit a PR if approved.

aboe76 pushed a commit that referenced this issue Jun 10, 2018
* Ensure options for formulas `git.latest` are also based on defaults

* Prevent erroneous remote tracking branch modification by `salt.formulas` #238

* Allow multiple envs to use the same gitdir for `salt.formulas`

* Ensure `gitdir` original branch is checked out after formulas `git.latest`

* Fix erroneous comment re: merging in `salt` pillar
@myii
Copy link
Member Author

myii commented Jun 11, 2018

With the merge of #239, this is now resolved -- closing.

@myii myii closed this as completed Jun 11, 2018
ixs pushed a commit to bawuenet/salt-formula that referenced this issue Jul 22, 2018
…tack-formulas#239)

* Ensure options for formulas `git.latest` are also based on defaults

* Prevent erroneous remote tracking branch modification by `salt.formulas` saltstack-formulas#238

* Allow multiple envs to use the same gitdir for `salt.formulas`

* Ensure `gitdir` original branch is checked out after formulas `git.latest`

* Fix erroneous comment re: merging in `salt` pillar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant