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

3 messages from 2019-06-28 to 2019-07-17. Participants: Massimo B..
Thread: https://gitlist.dev/t/51399

## Massimo B., 2019-06-28 09:57

Subject: git p4 sync: "str expected, not %s"
Message-ID: <34d6121da46f35e4b81d38169b1b86ca123cef37.camel@gmx.net>
URL: https://gitlist.dev/e/34d6121da46f35e4b81d38169b1b86ca123cef37.camel%40gmx.net

```
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., 2019-07-12 10:01

Subject: Re: git p4 sync: "str expected, not %s"
Message-ID: <edb1cc8f69e59015033604530513ff58f0bf8256.camel@gmx.net>
URL: https://gitlist.dev/e/edb1cc8f69e59015033604530513ff58f0bf8256.camel%40gmx.net
In-Reply-To: <17077551562900174@sas1-9134aa144859.qloud-c.yandex.net>

```
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., 2019-07-17 10:54

Subject: Re: git p4 sync: "str expected, not %s"
Message-ID: <61d7947142367c3abf6d6f0af60181a0677ce954.camel@gmx.net>
URL: https://gitlist.dev/e/61d7947142367c3abf6d6f0af60181a0677ce954.camel%40gmx.net
In-Reply-To: <23610851562985541@iva7-634c9cb1f49d.qloud-c.yandex.net>

```
Still failing:

On Fri, 2019-07-12 at 22:39 -0400, Andrey wrote:

> 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


> 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


```
