rahedges / git-repo

Automatically exported from code.google.com/p/git-repo
Apache License 2.0
0 stars 0 forks source link

Typo in GitConfig._SaveJson causing the repo init to crash #190

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Affected Version: master:3eb87cec5cae5f43becfe9fd1ff94de855cac08c
Introduced in: master:85b24acd6a11af3d84cc71fc35ebdb6d3c78065f
Environment: All

What steps will reproduce the problem?
1. in clean repository
2. repo init -u <manifest url> --repo-branch stable --no-repo-verify
3. repo sync
4. delete the repository including .repo subdir
2. repo init -u <manifest url> --repo-branch master --no-repo-verify 

What is the expected output? What do you see instead?

Expected: .repo is created succesfully
Result:
m:29418/dpd_hive-repo  --repo-branch master --no-repo-verify -b master
Get ssh://xxxxxxx/xxxxxx
remote: Counting objects: 2841, done
remote: Finding sources: 100% (2841/2841)
remote: Total 2841 (delta 1699), reused 2841 (delta 1699)
Receiving objects: 100% (2841/2841), 1.90 MiB | 0 bytes/s, done.
Resolving deltas: 100% (1699/1699), done.
From ssh://xxxxxxxxx/xxxxxx
 * [new branch]      maint      -> origin/maint
 * [new branch]      master     -> origin/master
 * [new branch]      stable     -> origin/stable
Traceback (most recent call last):
  File "/home/jenkins/jobs/trigger_post_commit_llvm_master/workspace/.repo/repo/main.py", line 500, in <module>
    _Main(sys.argv[1:])
  File "/home/jenkins/jobs/trigger_post_commit_llvm_master/workspace/.repo/repo/main.py", line 476, in _Main
    result = repo._Run(argv) or 0
  File "/home/jenkins/jobs/trigger_post_commit_llvm_master/workspace/.repo/repo/main.py", line 155, in _Run
    result = cmd.Execute(copts, cargs)
  File "/home/jenkins/jobs/trigger_post_commit_llvm_master/workspace/.repo/repo/subcmds/init.py", line 390, in Execute
    self._SyncManifest(opt)
  File "/home/jenkins/jobs/trigger_post_commit_llvm_master/workspace/.repo/repo/subcmds/init.py", line 149, in _SyncManifest
    print('Get %s' % GitConfig.ForUser().UrlInsteadOf(opt.manifest_url),
  File "/home/jenkins/jobs/trigger_post_commit_llvm_master/workspace/.repo/repo/git_config.py", line 218, in UrlInsteadOf
    for new_url in self.GetSubSections('url'):
  File "/home/jenkins/jobs/trigger_post_commit_llvm_master/workspace/.repo/repo/git_config.py", line 205, in GetSubSections
    return self._sections.get(section, set())
  File "/home/jenkins/jobs/trigger_post_commit_llvm_master/workspace/.repo/repo/git_config.py", line 229, in _sections
    for name in self._cache.keys():
  File "/home/jenkins/jobs/trigger_post_commit_llvm_master/workspace/.repo/repo/git_config.py", line 246, in _cache
    self._cache_dict = self._Read()
  File "/home/jenkins/jobs/trigger_post_commit_llvm_master/workspace/.repo/repo/git_config.py", line 253, in _Read
    self._SaveJson(d)
  File "/home/jenkins/jobs/trigger_post_commit_llvm_master/workspace/.repo/repo/git_config.py", line 283, in _SaveJson
    if os.path.exists(self.json):
AttributeError: 'GitConfig' object has no attribute 'json'

Please provide any additional information below.

Looking at the source code - it appears to be a typo:

  def _SaveJson(self, cache):
    try:
      fd = open(self._json, 'w')
      try:
        json.dump(cache, fd, indent=2)
      finally:
        fd.close()
    except (IOError, TypeError):
      if os.path.exists(self.json):   <=------------ here
        os.remove(self._json)

Original issue reported on code.google.com by vladi...@gmail.com on 21 Dec 2014 at 5:56

GoogleCodeExporter commented 9 years ago
I confirm that after the suggested change the issue disappears.
The jenkins gerrit repo polling works as expected.

Original comment by patrick....@gmail.com on 29 Jan 2015 at 9:41

GoogleCodeExporter commented 9 years ago
I got this error while building in Jenkins. The problem was, that Jenkins 
didn't have the permissions to save the file. Once I fixed the directory 
permissions, repo didn't run into the exception anymore. Nevertheless there is 
a typo in the exception branch.

Original comment by henrik.n...@gmail.com on 19 Feb 2015 at 1:03