Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git causes NativeCommandError #12

Open
JonatanAntoni opened this issue Jun 28, 2019 · 2 comments
Open

git causes NativeCommandError #12

JonatanAntoni opened this issue Jun 28, 2019 · 2 comments

Comments

@JonatanAntoni
Copy link

I am using Ansible 2.8.1 with latest win_git module targeting a Windows 10 Pro 1903 machine running Git for Windows 2.16.2. Updating an existing git clone fails, see below. Initial cloning fails with a similar issue.

TASK [win_git] ************************************************************************************
task path: ansible-win_git.yaml:10
Using module file library/win_git.ps1
Pipelining is enabled.
<192.168.xx.xx> ESTABLISH WINRM CONNECTION FOR USER: user on PORT 5986 TO 192.168.xx.xx
EXEC (via pipeline wrapper)
fatal: [win10pro]: FAILED! => {
    "changed": false,
    "cmd_msg": null,
    "msg": "Error cloning https://github.com/tivrobo/ansible-win_git.git to C:\\ansible-win_git! Msg: Already on 'master' - ",
    "win_git": {
        "accept_hostkey": true,
        "branch": "master",
        "clone": false,
        "dest": "C:\\ansible-win_git",
        "git_opts": "--no-pager pull origin master",
        "method": "pull",
        "recursive": true,
        "replace_dest": false,
        "repo": "https://github.com/tivrobo/ansible-win_git.git",
        "update": true,
        "valid_url": "https://github.com/tivrobo/ansible-win_git.git is valid url"
    }
}

I recognized that this is caused by git generating a NativeCommandError exception when being executing in Powershell:

PS C:\ansible-win_git> git --no-pager checkout master
Your branch is up to date with 'origin/master'.
git : Already on 'master'
At line:1 char:1
+ git --no-pager checkout master
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Already on 'master':String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

As a work around I added the following into win_git.ps1:

$env:GIT_REDIRECT_STDERR = '2>&1'

This changes the behavior of git in Powershell to the following:

PS C:\ansible-win_git> $env:GIT_REDIRECT_STDERR = '2>&1'
PS C:\ansible-win_git> git --no-pager checkout master
Your branch is up to date with 'origin/master'.
Already on 'master'

No exception is thrown anymore. The drawback is all stderr is merged into stdout.

@tivrobo
Copy link
Owner

tivrobo commented Oct 18, 2019

Thank you for sharing this!
I think that we need to update this plugin to work with Ansible 2.8

@tivrobo
Copy link
Owner

tivrobo commented Oct 18, 2019

duplicate of #11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants