Azure-devops-cli-extension: [Bug] git aliases don't work

Created on 10 May 2019  路  11Comments  路  Source: Azure/azure-devops-cli-extension

Describe the bug
Trying to use git aliases results in

environment: line 0: exec: az: not found

To Reproduce
Azure Cli Version: 2.0.64
Azure-Devops extension version: 0.8.0

Steps to reproduce the behaviour:

> az devops configure --use-git-aliases yes
> git pr create
environment: line 0: exec: az: not found

Expected behaviour
git pr should have same behaviour as az repos pr
git repo should have same behaviour as az repos

Additional info
Reproduced on windows in cmd and pwsh.

from .gitconfig

[alias]
    pr = "!f() { exec az repos pr \"$@\"; }; f"
    repo = "!f() { exec az repos \"$@\"; }; f"
bug ProToCol

Most helpful comment

The az command in the alias needs a .cmd added to it on Windows:

[alias]
    pr = "!f() { exec az.cmd repos pr \"$@\"; }; f"
    repo = "!f() { exec az.cmd repos \"$@\"; }; f"

All 11 comments

The az command in the alias needs a .cmd added to it on Windows:

[alias]
    pr = "!f() { exec az.cmd repos pr \"$@\"; }; f"
    repo = "!f() { exec az.cmd repos \"$@\"; }; f"

@centreboard @Jaykul How did you install azure cli? Was it using the msi or just a pip install?

@atbagga I used the msi

The file is https://github.com/Azure/azure-devops-cli-extension/blob/master/azure-devops/azext_devops/dev/common/git.py => line 193

def _get_alias_value(command):
    return '!f() { exec az ' + command + ' \"$@\"; }; f'

Encountering this was a bit of a pain

@qzdl , @centreboard is this happening when you are trying to use git from git bash?
Then this might be related to an issue in azure cli
https://github.com/Azure/azure-cli/issues/8560

can you confirm if this happens from normal terminal also or just git bash..
Apologies for the questions but this will help us to root cause it correctly.

I've been running from powershell/cmd prompts.
az repos pr create works from them.
git pr create only works once I've edited the git config to use az.cmd

looks like ultimately git alias is executed with git bash environment only
image

this proves that because cls is not recognized but clear works in cmd (which can't happen in cmd, but happens in bash)

This is related to Azure CLI MSI not packaging/handling the az bash script. It does work for me on my windows machine since az bash script is picked from the python scripts folder.

One quick fix for this could be to add windows specific hack in setting git aliases as suggested above and use az.cmd instead of az.

I will explore if we can fix the Azure CLI MSI packaging and fix this properly else go with the workaround.

@qzdl , @centreboard is this happening when you are trying to use git from git bash?
Then this might be related to an issue in azure cli
Azure/azure-cli#8560

can you confirm if this happens from normal terminal also or just git bash..
Apologies for the questions but this will help us to root cause it correctly.

@gauravsaralMs
This error occurs in powershell/git bash/cmd prompts.
I have no issue with other az commands in PS6

See a hacky fix in the below commit
https://github.com/qzdl/azure-devops-cli-extension/commit/595135739f0f9092a4a1f73052d28a598e36f0b8

@qzdl Thank you for the suggested fix. We have taken the workaround for now until this gets fixed in Azure CLI.
Feel free to raise a PR in the future for similar cases.

Fix will be available in the next release 0.9.0, scheduled to release in this week.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fidou picture fidou  路  5Comments

fordprefect480 picture fordprefect480  路  4Comments

geverghe picture geverghe  路  3Comments

ishitam8 picture ishitam8  路  6Comments

JohannesDrexler picture JohannesDrexler  路  5Comments