11

After git installation - I tried to clone an existing p4 branch, but it failed with the following information:

c:\P4_GIT\DT>git p4 clone //depot/CTAT/Windows/OneP/
fatal: 'p4' appears to be a git command, but we were not
able to execute it. Maybe git-p4 is broken?
araknoid
  • 3,065
  • 5
  • 33
  • 35
Ulysses
  • 5,616
  • 7
  • 48
  • 84

5 Answers5

18

I saw this on Git for Windows 2.16.1.4 and fixed it by replacing the shebang in "C:\Program Files\Git\mingw64\libexec\git-core\git-p4".

I replaced:

#!/usr/bin/python2

with:

#!/usr/bin/env python

NOTE: depending on how git was installed, this file may instead be in

C:\Users\[USERNAME]\AppData\Local\Programs\Git\mingw64\libexec\git-core
sferencik
  • 3,144
  • 1
  • 24
  • 36
Russell Gallop
  • 1,631
  • 2
  • 17
  • 34
8

Gabriel Morin's answer is the best for me, but it's incomplete:

  1. gitconfig is found in C:\Program Files\Git\mingw64\etc.
  2. if you get python.exe 'c:\program files\Git\mingw64\libexec\git-core\git-p4': python.exe: command not found you might want to add Python to the PATH or fully specify the path of a python.exe on your machine, like this:
[alias]
    p4 = !'C:\\Program Files\\Python27\\python.exe' 'c:\\program files\\Git\\mingw64\\libexec\\git-core\\git-p4'
  1. even so you might get something like: failure accessing depot: could not connect which is either because you use the interactive p4 interface and you don't have the environment variables that allow you to connect to perforce from the command line (see if p4 sync works for you) and set :
p4 set P4PORT=<server>:1666
p4 set P4USER=<user>
p4 set P4PASSWD=<password>
p4 set P4CLIENT=<some name>

  1. git-p4.py does NOT work with Python 3.0. You need to install Python 2.7.3 or whichever is highest.
Siderite Zackwehdex
  • 6,293
  • 3
  • 30
  • 46
  • 1
    Thanks for adding those details, my answer assumed some familiarity with all three tools, and I had not tried Python 3. gitconfig can be set at three different levels, system, global or repo. Use the `git config --edit` command with the proper argument to edit the one you want: https://git-scm.com/docs/git-config For p4, besides environment variables you can connect with: `p4 -p -c login` and all p4 commands can be prefixed with those options if needed. – Gabriel Morin Jul 16 '19 at 21:57
  • 1
    Finding the right config path was my issue. For other readers reaching this, find the git config paths by using this git command. git config --list --show-origin --show-scope – Per Svensson May 13 '20 at 05:58
6

It's not that complicated really, at least as of October 2017:

I installed Python 2.7.x for Windows, Git for Windows 2.14.2, and Perforce command line tools. I put all three on my path and tested that I was able to call python, git and p4 from the command line. Then I was able to add this to my gitconfig:

[alias]
    p4 = !python.exe 'c:\\program files\\Git\\mingw64\\libexec\\git-core\\git-p4'

Then using git p4 from the command line worked.

Gabriel Morin
  • 667
  • 8
  • 13
2

I've never come across git for Windows with Python support (which is needed for git p4). But maybe I'm missing something. Every time I used git p4 on Windows, I would get

> git p4
basename: too many arguments
Try `basename --help' for more information.
fatal: git was built without support for  (NO_PYTHON=YesPlease).

Which is also confirmed here.

But your error message is different so maybe you do have git with Python support. Not sure...

sferencik
  • 3,144
  • 1
  • 24
  • 36
1

I've had more success (on Linux admittedly) downloading one of the git-p4 branches from github and calling it directly (git-p4) rather than through git p4.

Maybe that would help you?

Douglas Leeder
  • 52,368
  • 9
  • 94
  • 137
  • Ok so I downloaded git-p4.py and kept in: c:\\Program Files\\Git\\bin\\git-p4.py and added the following line in .gitConfig [alias] p4 = !'c:\\Program Files\\Git\\bin\\git-p4.py' but it gave me a different issue now:| >git p4 /usr/bin/env: python: No such file or directoryfatal: While expanding alias 'p4': ''c:\Program Files\Git\bin\git-p4.py'': No such file or directory – Ulysses Dec 21 '15 at 10:56
  • I guess that means it can't find python – Douglas Leeder Dec 21 '15 at 11:08
  • Maybe call python explicitly with git-p4.py as the first argument? – Douglas Leeder Dec 21 '15 at 11:09