Skip to content

Parsing error on git config #112

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

Closed
louisrli opened this issue Jun 30, 2013 · 6 comments
Closed

Parsing error on git config #112

louisrli opened this issue Jun 30, 2013 · 6 comments
Assignees

Comments

@louisrli
Copy link

The error is below, doing a config.get_value("user", "name")

File "python-client/client.py", line 53, in <module>
main()
File "python-client/client.py", line 19, in main
user_info = githelpers.get_computer_info()["user"]
File "/home/sagar/dev/meteor/live-git/python-client/githelpers.py", line 35, in get_computer_info
user_name = config.get_value("user", "name")
File "/usr/local/lib/python2.7/dist-packages/git/config.py", line 379, in get_value
valuestr = self.get(section, option)
File "/usr/local/lib/python2.7/dist-packages/git/config.py", line 52, in assure_data_present
self.read()
File "/usr/local/lib/python2.7/dist-packages/git/config.py", line 291, in read
self._read(fp, fp.name)
File "/usr/local/lib/python2.7/dist-packages/git/config.py", line 262, in _read
raise e
ConfigParser.ParsingError: File contains parsing errors: /home/sagar/.gitconfig
[line 149]: '\t\tend\\n\\\n'
[line 150]: '\t\tFile.open(%(%A), %(w)) {|f| f.write(b)}\\n\\\n'
[line 151]: '\t\texit 1 if b.include?(%(<)*%L)\'"\n'

It happens on this .gitconfig after line 142. If you remove those parts, then it works fine.

https://github.com/cjhveal/dotfiles/blob/master/git/gitconfig.symlink

@jschlather
Copy link

Is this issue for the correct library? I can't find for instance a client.py in gitpython.

@louisrli
Copy link
Author

Sorry, client.py is my file, but it makes a call to try to get a value from the .gitconfig (that looks like the linked one)

@Byron Byron added this to the v0.3.5 - bugfixes milestone Nov 19, 2014
@Byron
Copy link
Member

Byron commented Nov 19, 2014

git-python uses the (downright terrible) standard configparser implementation, which is very picky.
If a better library would be used, this one could be fixed as well I suppose.

@Byron Byron self-assigned this Jan 9, 2015
@Byron
Copy link
Member

Byron commented Jan 9, 2015

I am able to reproduce the error and believe the only way to fix it is to use a different/better parser implementation. There seem to be alternatives which are available on pypi as well, and I am confident I will find something suitable.
The config parser part of git-python has been a constant source for grief, and I will be happy to finally fix it.

@Byron Byron closed this as completed in b825dc7 Jan 10, 2015
@Byron
Copy link
Member

Byron commented Jan 10, 2015

I ended up improving the current (and custom) config parser implementation to the point where it can handle multi-line values correctly. There is a new test-case which verifies that git-python returns exactly the same value as git does.

it config -f git/test/fixtures/git_config_with_comments --get "merge.railsschema.driver"
ruby -e '
                system %(git), %(merge-file), %(--marker-size=%L), %(%A), %(%O), %(%B)
                b = File.read(%(%A))
                b.sub!(/^<+ .*\nActiveRecord::Schema\.define.:version => (\d+). do\n=+\nActiveRecord::Schema\.define.:version => (\d+). do\n>+ .*/) do
                  %(ActiveRecord::Schema.define(:version => #{[$1, $2].max}) do)
                end
                File.open(%(%A), %(w)) {|f| f.write(b)}
                exit 1 if b.include?(%(<)*%L)'

@Byron
Copy link
Member

Byron commented Jan 10, 2015

Also, just for fun, I have recorded the process of fixing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants