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

Traceback in git module when version checkout fails #3723

Merged
merged 2 commits into from
Aug 3, 2013

Conversation

psvo
Copy link
Contributor

@psvo psvo commented Aug 1, 2013

"UnboundLocalError: local variable 'branch' referenced before assignment" is
raised in git, line 282, in switch_version.

Exception is raised when version is not branch and version checkout fails.
E.g. when version is nonexistant commit.

Full traceback:

REMOTE_MODULE git repo="ssh://xxx/xxx.git" dest="/xxx" version="a98ef5944f5fe3969accfffa40e76fb43d6b49dc"

failed to parse: Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-1375350491.22-159151807716270/git", line 1306, in <module>
    main()
  File "/root/.ansible/tmp/ansible-1375350491.22-159151807716270/git", line 364, in main
    (rc, out, err) = switch_version(git_path, module, dest, remote, version)
  File "/root/.ansible/tmp/ansible-1375350491.22-159151807716270/git", line 282, in switch_version
    module.fail_json(msg="Failed to checkout branch %s" % (branch))
UnboundLocalError: local variable 'branch' referenced before assignment

"UnboundLocalError: local variable 'branch' referenced before assignment" is
raised in git, line 282, in switch_version.

Exception is raised when version is not branch and version checkout fails.
E.g. when version is nonexistant commit.
@jimi-c
Copy link
Member

jimi-c commented Aug 1, 2013

Would it be better just to do this on line 283 (282 of the original):

module.fail_json(msg="Failed to checkout %s" % (version))

Since the checkout could be a tag as well as a branch or sha.

@psvo
Copy link
Contributor Author

psvo commented Aug 1, 2013

But than we will loose information about checked out branch when version is HEAD. Than maybe there should be something like:

module.fail_json(msg="Failed to checkout %s" % (version if version != HEAD else branch))

@psvo
Copy link
Contributor Author

psvo commented Aug 1, 2013

Hmm, but its python 2.5+ only, so maybe keeping current patch and removing branch from message would be good enough?

@mpdehaan
Copy link
Contributor

mpdehaan commented Aug 2, 2013

Don't do the one line thing, instead do:

if version:
    module.fail_json(msg="Failed to checkout %s" % (version))
else branch:
    module.fail_json(...)

Also more readable.

Can you update this? Then I'll merge it in. Thanks!

@mpdehaan
Copy link
Contributor

mpdehaan commented Aug 3, 2013

This should just say "if version", actually, but I'll take care of fixing it.

@mpdehaan
Copy link
Contributor

mpdehaan commented Aug 3, 2013

ah, I see, the parameter is being reused for both tags and branches.

Got it, thanks!

@mpdehaan
Copy link
Contributor

mpdehaan commented Aug 3, 2013

merged, thank you!

@mpdehaan mpdehaan closed this Aug 3, 2013
@mpdehaan mpdehaan merged commit d9576b3 into ansible:devel Aug 3, 2013
@psvo psvo deleted the git_undefined_branch_variable branch August 8, 2013 11:40
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 5, 2018
@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants