threads / discuss / 51399

git p4 sync: "str expected, not %s"

Subject: git p4 sync: "str expected, not %s"

## tl;dr

3 messages between Jun 28, 2019 and Jul 17, 2019.

replies: 2people: 1as markdown or json

Massimo B.· Jun 28, 2019, 09:57 UTC · lore
Hello everybody,
since last updates, git p4 does not work anymore:
# git p4 sync --verbose
Reading pipe: ['git', '--git-dir', '/mnt/data/userspace/project-pb/MM6.test/.git', 'rev-parse', '--git-dir']
Reading pipe: git rev-parse --git-dir
Reading pipe: git rev-parse --show-cdup
Reading pipe: ['git', '--git-dir', b'.', 'rev-parse', '--git-dir']
Traceback (most recent call last):
  File "/usr/libexec/git-core/git-p4", line 4163, in <module>
    main()
  File "/usr/libexec/git-core/git-p4", line 4155, in main
    os.environ["GIT_DIR"] = cmd.gitdir
  File "/usr/lib64/python3.6/os.py", line 674, in __setitem__
    value = self.encodevalue(value)
  File "/usr/lib64/python3.6/os.py", line 744, in encode
    raise TypeError("str expected, not %s" % type(value).__name__)
TypeError: str expected, not bytes

git version 2.22.0 Gentoo Linux Global Python is 3.6.

Last working version I found: 2.20.1

Best regards, Massimo

Massimo B.· Jul 12, 2019, 10:01 UTC · lore

Re: git p4 sync: "str expected, not %s"

On Thu, 2019-07-11 at 22:56 -0400, Andrey wrote:
> Strangely, I don't see any changes that could have broken it between 2.20.1
> and 2.22.0.
> Are you sure your git repository is not "bare", i.e. there's .git
> subdirectory?
> Looks like, it doesn't think that "MM6.test/.git" is a valid git repository
> while it would normally be.

I forgot to say, yes it is a bare repo, was created like this: # git p4 clone --bare //MM6.test@all --verbose

> Anyway, could you, please, try the patch below to see if it helps?
I did, but this fails now like this:
fatal: cannot locate git repository at b'.'

Best regards, Massimo

Massimo B.· Jul 17, 2019, 10:54 UTC · lore

Re: git p4 sync: "str expected, not %s"

Still failing:
On Fri, 2019-07-12 at 22:39 -0400, Andrey wrote:
Show 24 quoted lines
> Could you, please, try the patch below?
>
> diff --git a/git-p4.py b/git-p4.py
> index 5b79920f46..f5be048348 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -4137,13 +4137,13 @@ def main():
>      if cmd.needsGit:
>          if cmd.gitdir == None:
>              cmd.gitdir = os.path.abspath(".git")
>              if not isValidGitDir(cmd.gitdir):
>                  # "rev-parse --git-dir" without arguments will try $PWD/.git
> -                cmd.gitdir = read_pipe("git rev-parse --git-dir").strip()
> +                cmd.gitdir = read_pipe("git rev-parse --git-
> dir").strip().decode()
>                  if os.path.exists(cmd.gitdir):
> -                    cdup = read_pipe("git rev-parse --show-cdup").strip()
> +                    cdup = read_pipe("git rev-parse --show-
> cdup").strip().decode()
>                      if len(cdup) > 0:
>                          chdir(cdup);
>
>          if not isValidGitDir(cmd.gitdir):
>              if isValidGitDir(cmd.gitdir + "/.git"):
# git p4 sync
Traceback (most recent call last):
  File "/usr/libexec/git-core/git-p4", line 4163, in <module>
    main()
  File "/usr/libexec/git-core/git-p4", line 4157, in main
    if not cmd.run(args):
  File "/usr/libexec/git-core/git-p4", line 3569, in run
    branches = p4BranchesInGit(self.importIntoRemotes)
  File "/usr/libexec/git-core/git-p4", line 844, in p4BranchesInGit
    if not line.startswith('p4/'):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
Show 18 quoted lines
> Or, even this one:
>
> diff --git a/git-p4.py b/git-p4.py
> index 5b79920f46..2bf6720911 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -196,6 +196,10 @@ def read_pipe_full(c):
>      expand = isinstance(c,basestring)
>      p = subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
> shell=expand)
>      (out, err) = p.communicate()
> +    if out is not None:
> +        out = out.decode()
> +    if err is not None:
> +        err = err.decode()
>      return (p.returncode, out, err)
>
>  def read_pipe(c, ignore_error=False):
# git p4 sync
Traceback (most recent call last):
  File "/usr/libexec/git-core/git-p4", line 4167, in <module>
    main()
  File "/usr/libexec/git-core/git-p4", line 4146, in main
    cmd.gitdir = read_pipe("git rev-parse --git-dir").strip().decode()
AttributeError: 'str' object has no attribute 'decode'

Best regards, Massimo

← back to recent threads