esrlabs / git-repo

repo - The multiple repository tool (also works on MS Windows!)
https://code.google.com/p/git-repo/
Apache License 2.0
436 stars 145 forks source link

GitError: config: environment can only contain strings #82

Open pranshuthegamer opened 4 years ago

pranshuthegamer commented 4 years ago

I was using repo init: repo init -u git://github.com/MiCode/patchrom.git -b marshmallow then i got

Traceback (most recent call last): File "C:\Users\admin.repo\repo\git_command.py", line 311, in init p = subprocess.Popen(command, File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in init self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, TypeError: environment can only contain strings

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\admin.repo\repo/main.py", line 568, in _Main(sys.argv[1:]) File "C:\Users\admin.repo\repo/main.py", line 542, in _Main result = run() File "C:\Users\admin.repo\repo/main.py", line 535, in run = lambda: repo._Run(name, gopts, argv) or 0 File "C:\Users\admin.repo\repo/main.py", line 213, in _Run result = cmd.Execute(copts, cargs) File "C:\Users\admin.repo\repo\subcmds\init.py", line 462, in Execute self._SyncManifest(opt) File "C:\Users\admin.repo\repo\subcmds\init.py", line 187, in _SyncManifest print('Get %s' % GitConfig.ForUser().UrlInsteadOf(opt.manifest_url), File "C:\Users\admin.repo\repo\git_config.py", line 237, in UrlInsteadOf for new_url in self.GetSubSections('url'): File "C:\Users\admin.repo\repo\git_config.py", line 224, in GetSubSections return self._sections.get(section, set()) File "C:\Users\admin.repo\repo\git_config.py", line 248, in _sections for name in self._cache.keys(): File "C:\Users\admin.repo\repo\git_config.py", line 265, in _cache self._cache_dict = self._Read() File "C:\Users\admin.repo\repo\git_config.py", line 271, in _Read d = self._ReadGit() File "C:\Users\admin.repo\repo\git_config.py", line 306, in _ReadGit d = self._do('--null', '--list') File "C:\Users\admin.repo\repo\git_config.py", line 329, in _do p = GitCommand(None, File "C:\Users\admin.repo\repo\git_command.py", line 318, in init raise GitError('%s: %s' % (command[1], e)) error.GitError: config: environment can only contain strings

pranshuthegamer commented 4 years ago

How do I fix this??

BeQuietLee commented 4 years ago

Same issue. Waiting for the answer.

BeQuietLee commented 4 years ago

UPDATE: Caused by windows encoding. Found an alternative solution, inspired by this post Add the code below to __init__ function inside git_command.py

    try:
      # ADD START: clean the encoding
      env_clean = {}
      for k in env:
        key = k
        if isinstance(key, unicode):
          key = key.encode('utf-8')
        env_clean[key] = env[k]
        if isinstance(env_clean[key], unicode):
          env_clean[key] = env_clean[key].encode('utf-8')
      env = env_clean
      # ADD END

      p = subprocess.Popen(command,
                           cwd=cwd,
                           env=env,
                           stdin=stdin,
                           stdout=stdout,
                           stderr=stderr)
sivakotich commented 4 years ago

Above solution is not working for me on windows with python 3.8 version. Observing the same failure (modified unicode to str in above snippet to make it work for py3)

Any other solutions are appreciated. Thanks

charlesli640 commented 4 years ago

I think on Windows, somehow the env is stored as utf-8 encoded bytes/bytearray. But it only accept string in the env Popen( env…)

So instead of encoding, we need decoding bytes to str I modified above solution as following. Then it works on Windows py3

  # ADD START: clean the encoding
  env_clean = {}
  for k, v in env.items():
      if isinstance(k, bytes):
          k = k.decode('utf-8')
      if isinstance(v, bytes):
          v = v.decode('utf-8')
      env_clean[k] = v
  env = env_clean
  # ADD END