Run(`git --version`) on Windows errors

Hi all,

why does it error?

julia> run(`git --version`)
ERROR: IOError: could not spawn `git --version`: no such file or directory (ENOENT)
Stacktrace:
 [1] _spawn_primitive(file::String, cmd::Cmd, stdio::Vector{Any})
   @ Base .\process.jl:99
 [2] #637
   @ .\process.jl:112 [inlined]
 [3] setup_stdios(f::Base.var"#637#638"{Cmd}, stdios::Vector{Any})
   @ Base .\process.jl:196
 [4] _spawn
   @ .\process.jl:111 [inlined]
 [5] run(::Cmd; wait::Bool)
   @ Base .\process.jl:439
 [6] run(::Cmd)
   @ Base .\process.jl:438
 [7] top-level scope
   @ REPL[44]:1

It never worked for me on Windows. How would I fix it? Are there other people with the same problem?

Thanks

WFM:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.0 (2021-03-24)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> run(`git --version`)
git version 2.7.1.windows.2
Process(`git --version`, ProcessExited(0))

julia> run(`where git`)
C:\Program Files\Git\cmd\git.exe
C:\Program Files\Git\mingw64\bin\git.exe
Process(`where git`, ProcessExited(0))

Make sure that the path to git is in your PATH.

2 Likes

Do you have git installed as a Windows application? I.e., can you open a regular cmd.exe and run git?

If I can open git in cmd the PATH should be correct. Is that right?


C:\Users\User>git
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           [--super-prefix=<path>] [--config-env=<name>=<envvar>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone             Clone a repository into a new directory
   init              Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add               Add file contents to the index
   mv                Move or rename a file, a directory, or a symlink
   restore           Restore working tree files
   rm                Remove files from the working tree and from the index
   sparse-checkout   Initialize and modify the sparse-checkout

examine the history and state (see also: git help revisions)
   bisect            Use binary search to find the commit that introduced a bug
   diff              Show changes between commits, commit and working tree, etc
   grep              Print lines matching a pattern
   log               Show commit logs
   show              Show various types of objects
   status            Show the working tree status

grow, mark and tweak your common history
   branch            List, create, or delete branches
   commit            Record changes to the repository
   merge             Join two or more development histories together
   rebase            Reapply commits on top of another base tip
   reset             Reset current HEAD to the specified state
   switch            Switch branches
   tag               Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch             Download objects and refs from another repository
   pull              Fetch from and integrate with another repository or a local branch
   push              Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.

Yes, that sounds right. Check where cmd is finding git with where git and try putting the full path in run with appropriate escaping:

C:\>where git
C:\Program Files\Git\cmd\git.exe

C:\>julia
julia> run(`"C:\\Program Files\\Git\\cmd\\git.exe" --version`)
git version 2.7.1.windows.2

You can try this

using Git
git = Git.git()
run(`$git --version`)

after adding the Git package.

2 Likes
C:\Users\User>where git
C:\Program Files\Git\cmd\git.exe
julia> run(`C:\Program Files\Git\cmd\git.exe --version`)
ERROR: IOError: could not spawn `C:Program FilesGitcmdgit.exe --version`: no such file or directory (ENOENT)
Stacktrace:
 [1] _spawn_primitive(file::String, cmd::Cmd, stdio::Vector{Any})
   @ Base .\process.jl:99
 [2] #637
   @ .\process.jl:112 [inlined]
 [3] setup_stdios(f::Base.var"#637#638"{Cmd}, stdios::Vector{Any})
   @ Base .\process.jl:196
 [4] _spawn
   @ .\process.jl:111 [inlined]
 [5] run(::Cmd; wait::Bool)
   @ Base .\process.jl:439
 [6] run(::Cmd)
   @ Base .\process.jl:438
 [7] top-level scope
   @ REPL[45]:1

I don’t know what I’m doing wrong…

thx, but I wanna use that:
https://github.com/GunnarFarneback/LocalRegistry.jl

You forgot to quote the path and escape \:

julia> run(`C:\Program Files\Git\cmd\git.exe --version`)

should be

julia> run(`"C:\\Program Files\\Git\\cmd\\git.exe" --version`)

This is because there’s a space in “Program Files” and windows needs those \ escaped.

If you just want to use LocalRegistry, interacting with the git repo from the regular command line is ok.

2 Likes

OK that worked :slight_smile:

julia> run(`"C:\Program Files\Git\cmd\git.exe" --version`)
git version 2.31.1.windows.1
Process(`'C:\Program Files\Git\cmd\git.exe' --version`, ProcessExited(0))

OK good to know that I can use LocalRegistry that way.

But I would like to fix it anyway. Because it never worked for my on any machine…

Right, of course. It’s in my future plans to use the Git package for LocalRegistry but it requires bumping the Julia compatibility to 1.6, which I don’t want to do just yet.

But well, try if this branch works for you:

pkg> add LocalRegistry#git_jll

Actually it probably doesn’t since Use jll version of git via Git package. by GunnarFarneback · Pull Request #38 · GunnarFarneback/LocalRegistry.jl · GitHub fails the CI for Windows, but it might be enlightening to see in what way it fails for you.

Now I know what’s the issue was. Julia REPL was open, I installed git and tried using it right after. Simple fix: Stop and restart Julia.