Skip to content

Git states not compatible with numeric tags #9718

Closed

Description

@Lothiraldan

During a deployment, we bump version from 3.2.5 to 3.3 and we get weird git error:

State: - git
Name:      [email protected]:**/**.git
Function:  latest
    Result:    False
    Comment:   cannot concatenate 'str' and 'float' objects
    Changes:  

I try to dig into the code and thinks I found the problem:

cmd = "git rev-parse " + rev + '^{commit}'

I tried to add some log before this line and revision is parsed as a float. With this patch, state.highstate ends successfully:

diff --git a/salt/states/git.py b/salt/states/git.py
index cc7b26e..1a75a46 100644
--- a/salt/states/git.py
+++ b/salt/states/git.py
@@ -213,7 +213,7 @@ def latest(name,
                                           identity=identity)
                 elif rev:

-                    cmd = "git rev-parse " + rev + '^{commit}'
+                    cmd = "git rev-parse %s ^{commit}" % rev
                     retcode = __salt__['cmd.retcode'](cmd,
                                                       cwd=target,
                                                       runas=user)

If it's the problem and the patch works, I will push a pull-request.

Activity

  1. basepi commented on Jan 13, 2014

    @basepi
    Contributor

    Yes, this is the correct fix, except that we want to use .format instead of the % syntax:

    diff --git a/salt/states/git.py b/salt/states/git.py
    index cc7b26e..8da78ec 100644
    --- a/salt/states/git.py
    +++ b/salt/states/git.py
    @@ -213,7 +213,7 @@ def latest(name,
                                               identity=identity)
                     elif rev:
    
    -                    cmd = "git rev-parse " + rev + '^{commit}'
    +                    cmd = 'git rev-parse {0} ^{{commit}}'.format(rev)
                         retcode = __salt__['cmd.retcode'](cmd,
                                                           cwd=target,
                                                           runas=user)
    

    Note the double brackets ({{commit}}) so that the format call doesn't try to insert a value for commit.

    Please feel free to submit a pull request with this modified fix.

  2. added a commit that references this issue on Jan 15, 2014
    091a551
  3. added 2 commits that reference this issue on Jan 15, 2014
    8ab6f46
    1c2be23
  4. added a commit that references this issue on Jan 23, 2014
    d5083f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions