salt icon indicating copy to clipboard operation
salt copied to clipboard

Note regarding git.latest branch tracking changes and rev field

Open jasonrm opened this issue 12 years ago • 1 comments

Can't find the original reason why I though it was the expected way, but I've always set rev in my git states to be in the format remote_name/branch_name. It worked fine until the branch tracking changes relating to #11611 which cause git.latest to fail when the rev includes the remote name. The correct way is to just have the branch/sha/tag in the rev field and the remote name in the remote_name field.

And since it took me a while to figure out the cause (and I almost blamed the changes, haha, that would have been embarrassing), I figured might as well document it here in case others come across the same issue.

The failure looks something like this.

state/test-incorrect.sls

oh-my-zsh-repo:
    git.latest:
        - name: 'https://github.com/robbyrussell/oh-my-zsh'
        - target: /tmp/oh-my-zsh
        - rev: 'origin/master'
        - always_fetch: True
        - force_checkout: True

Output from first run

$ salt '*' state.highstate

localhost:
----------
          ID: oh-my-zsh-repo
    Function: git.latest
        Name: https://github.com/robbyrussell/oh-my-zsh
      Result: True
     Comment: Repository https://github.com/robbyrussell/oh-my-zsh cloned to /tmp/oh-my-zsh
     Started: 13:36:05.631903
     Duration: 182 ms
     Changes:   
              ----------
              new:
                  https://github.com/robbyrussell/oh-my-zsh
              revision:
                  eafd5f325208421b82a770e57441dd1063eb5745

Summary
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1

Output from second run

$ salt '*' state.highstate

localhost:
----------
          ID: oh-my-zsh-repo
    Function: git.latest
        Name: https://github.com/robbyrussell/oh-my-zsh
      Result: False
     Comment: 
     Started: 13:42:47.524488
     Duration: 92 ms
     Changes:   

Summary
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1

salt-minion log

[INFO    ] Starting a new job with PID 43042
[DEBUG   ] Reading configuration from /Users/jason/git-local/salt-dev/minion
[INFO    ] Returning information for job: 20140513135656114624
[INFO    ] Executing command 'git checkout  -f origin/master ' in directory '/tmp/oh-my-zsh'
[INFO    ] stderr: HEAD is now at eafd5f3... Merge pull request #1635 from jimhester/per-directory-history
[INFO    ] Executing command 'git config branch.origin/master.remote' in directory '/tmp/oh-my-zsh'
[ERROR   ] Command 'git config branch.origin/master.remote' failed with return code: 1
[ERROR   ] retcode: 1
[ERROR   ] No changes made for https://github.com/robbyrussell/oh-my-zsh
[INFO    ] Completed state [https://github.com/robbyrussell/oh-my-zsh] at time 13:56:56.621690
[INFO    ] Returning information for job: 20140513135650514260

Once I fix my state to the following, everything works as expected.

state/test-correct.sls

oh-my-zsh-repo:
    git.latest:
        - name: 'https://github.com/robbyrussell/oh-my-zsh'
        - target: /tmp/oh-my-zsh
        - rev: master
        - remote_name: origin
        - always_fetch: True
        - force_checkout: True

and now things work,

$ salt '*' state.highstate
localhost:
  Name: https://github.com/robbyrussell/oh-my-zsh - Function: git.latest - Result: Clean

Summary
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1

jasonrm avatar May 13 '14 21:05 jasonrm

Just saw this. Thanks for adding this issue to explain the change & fix for possible Google searchers. FWIW, I prefer your method of specifying the revision as remote_name/branch_name. If you're automating changes to a repo using a management tool why even care about local refs, branches, or remote-tracking? Much, much simpler to just checkout a single ref and be done with it. Seems you and I are in the minority though.

Anyhoo. Thanks for the detailed comment!

whiteinge avatar Jul 01 '14 01:07 whiteinge