windows-git-bash-compatibility について
Windows の Git Bash を使う Azure Data Factory 開発者向けのスキルです。パス変換による問題と、コマンドや CI/CD スクリプトでの対処方法を説明します。
主な機能
- 01Git Bash のパス変換を解説
- 02MSYS_NO_PATHCONV の使い方
- 03npm、PowerShell、Azure CLI に対応
- 04シェル検出パターンを紹介
- 05CI/CD スクリプトの実践例
活用シーン
- 01ADF の npm 検証・エクスポートコマンドの修正
- 02Git Bash からの PowerShell デプロイスクリプト実行
- 03Azure CLI による ARM テンプレートのデプロイ
- 04スクリプトでの現在のシェルの検出
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ josiahsiegel/ claude-plugin-marketplace --skill windows-git-bash-compatibilityインストール後、Claude Code で/windows-git-bash-compatibilityを入力して読み込まれたか確認します。
詳細
Azure Data Factory の Windows と Git Bash の互換性
概要
Azure Data Factory の開発は、主なシェルとして Git Bash(MINGW64)を使用する Windows マシンで頻繁に行われます。そのため、パス変換によって CI/CD パイプライン、npm コマンド、デプロイスクリプトが機能しなくなることがあります。
Git Bash のパス変換の動作
自動パス変換
Git Bash(MINGW)は、Unix 形式のパスを Windows のパスに自動変換します。
変換例:
/foo→C:/Program Files/Git/usr/foo/foo:/bar→C:\msys64\foo;C:\msys64\bar(パスリスト)--dir=/foo→--dir=C:/msys64/foo(引数)
変換がトリガーされる条件:
- 引数内の先頭のスラッシュ(
/) - コロン区切りのパスリスト
- パス構成要素を含む、
-または,の後の引数
変換対象外:
=を含む引数(変数の代入)- ドライブ指定子(
C:) ;を含む引数(すでに Windows 形式)//で始まる引数(Windows のスイッチ)
ADF 固有のパスの問題
npm ビルドコマンド
問題:
# This fails in Git Bash due to path conversion
npm run build validate ./adf-resources /subscriptions/abc/resourceGroups/rg/providers/Microsoft.DataFactory/factories/myFactory
# Path gets converted incorrectly
解決策:
# Disable path conversion before running
export MSYS_NO_PATHCONV=1
npm run build validate ./adf-resources /subscriptions/abc/resourceGroups/rg/providers/Microsoft.DataFactory/factories/myFactory
# Or wrap the command
MSYS_NO_PATHCONV=1 npm run build export ./adf-resources /subscriptions/.../myFactory "ARMTemplate"
PowerShell スクリプト
問題:
# Calling PowerShell scripts from Git Bash
pwsh ./PrePostDeploymentScript.Ver2.ps1 -armTemplate "./ARMTemplate/ARMTemplateForFactory.json"
# Path conversion may interfere
解決策:
# Disable conversion for PowerShell calls
MSYS_NO_PATHCONV=1 pwsh ./PrePostDeploymentScript.Ver2.ps1 -armTemplate "./ARMTemplate/ARMTemplateForFactory.json"
ARM テンプレートのパス
問題:
# Azure CLI deployment from Git Bash
az deployment group create \
--resource-group myRG \
--template-file ARMTemplate/ARMTemplateForFactory.json # Path may get converted
解決策:
# Use relative paths with ./ prefix or absolute Windows paths
export MSYS_NO_PATHCONV=1
az deployment group create \
--resource-group myRG \
--template-file ./ARMTemplate/ARMTemplateForFactory.json
シェルの検出パターン
Bash シェルの検出
#!/usr/bin/env bash
# Method 1: Check $MSYSTEM (Git Bash/MSYS2 specific)
if [ -n "$MSYSTEM" ]; then
echo "Running in Git Bash/MinGW ($MSYSTEM)"
export MSYS_NO_PATHCONV=1
fi
# Method 2: Check uname -s (more portable)
case "$(uname -s)" in
MINGW64*|MINGW32*|MSYS*)
echo "Git Bash detected"
export MSYS_NO_PATHCONV=1
;;
Linux*)
if grep -q Microsoft /proc/version 2>/dev/null; then
echo "WSL detected"
else
echo "Native Linux"
fi
;;
Darwin*)
echo "macOS"
;;
esac
# Method 3: Check $OSTYPE (bash-specific)
case "$OSTYPE" in
msys*)
echo "Git Bash/MSYS"
export MSYS_NO_PATHCONV=1
;;
linux-gnu*)
echo "Linux"
;;
darwin*)
echo "macOS"
;;
esac
Node.js シェルの検出
// detect-shell.js - For use in npm scripts or Node tools
function detectShell() {
const env = process.env;
// Git Bash/MinGW (MOST RELIABLE)
if (env.MSYSTEM) {
return {
type: 'mingw',
subsystem: env.MSYSTEM, // MINGW64, MINGW32, or MSYS
needsPathFix: true
};
}
// WSL
if (env.WSL_DISTRO_NAME) {
return {
type: 'wsl',
distro: env.WSL_DISTRO_NAME,
needsPathFix: false
};
}
// PowerShell (3+ paths in PSModulePath)
if (env.PSModulePath?.split(';').length >= 3) {
return {
type: 'powershell',
needsPathFix: false
};
}
// CMD
if (process.platform === 'win32' && env.PROMPT === '$P$G') {
return {
type: 'cmd',
needsPathFix: false
};
}
// Cygwin
if (env.TERM === 'cygwin') {
return {
type: 'cygwin',
needsPathFix: true
};
}
// Unix shells
if (env.SHELL?.includes('bash')) {
return { type: 'bash', needsPathFix: false };
}
if (env.SHELL?.includes('zsh')) {
return { type: 'zsh', needsPathFix: false };
}
return {
type: 'unknown',
platform: process.platform,
needsPathFix: false
};
}
// Usage
const shell = detectShell();
console.log(`Detected shell: ${shell.type}`);
if (shell.needsPathFix) {
process.env.MSYS_NO_PATHCONV = '1';
console.log('Path conversion disabled for Git Bash compatibility');
}
module.exports = { detectShell };
PowerShell の検出
# Detect PowerShell edition and version
function Get-ShellInfo {
$info = @{
Edition = $PSVersionTable.PSEdition
Version = $PSVersionTable.PSVersion
OS = $PSVersionTable.OS
Platform = $PSVersionTable.Platform
}
if ($info.Edition -eq 'Core') {
Write-Host "PowerShell Core (pwsh) - Cross-platform compatible" -ForegroundColor Green
$info.CrossPlatform = $true
} else {
Write-Host "Windows PowerShell - Windows only" -ForegroundColor Yellow
$info.CrossPlatform = $false
}
return $info
}
$shellInfo = Get-ShellInfo
CI/CD パイプラインのパターン
ローカル開発スクリプト
validate-adf.sh(Git Bash 対応):
#!/usr/bin/env bash
set -e
# Detect and handle Git Bash
if [ -n "$MSYSTEM" ]; then
export MSYS_NO_PATHCONV=1
echo "🔧 Git Bash detected - path conversion disabled"
fi
# Configuration
ADF_ROOT="./adf-resources"
FACTORY_ID="/subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.DataFactory/factories/${FACTORY_NAME}"
# Validate ADF resources
echo "📋 Validating ADF resources..."
npm run build validate "$ADF_ROOT" "$FACTORY_ID"
# Generate ARM templates
echo "📦 Generating ARM templates..."
npm run build export "$ADF_ROOT" "$FACTORY_ID" "ARMTemplate"
echo "✅ Validation complete"
deploy-adf.sh(クロスプラットフォーム):
#!/usr/bin/env bash
set -e
# Detect shell
detect_shell() {
if [ -n "$MSYSTEM" ]; then echo "git-bash"
elif [ -n "$WSL_DISTRO_NAME" ]; then echo "wsl"
elif [[ "$OSTYPE" == "darwin"* ]]; then echo "macos"
else echo "linux"
fi
}
SHELL_TYPE=$(detect_shell)
echo "🖥️ Detected shell: $SHELL_TYPE"
# Handle Git Bash
if [ "$SHELL_TYPE" = "git-bash" ]; then
export MSYS_NO_PATHCONV=1
fi
# Download PrePostDeploymentScript
curl -sLo PrePostDeploymentScript.Ver2.ps1 \
https://raw.githubusercontent.com/Azure/Azure-DataFactory/main/SamplesV2/ContinuousIntegrationAndDelivery/PrePostDeploymentScript.Ver2.ps1
# Stop triggers
echo "⏸️ Stopping triggers..."
MSYS_NO_PATHCONV=1 pwsh ./PrePostDeploymentScript.Ver2.ps1 \
-armTemplate "./ARMTemplate/ARMTemplateForFactory.json" \
-ResourceGroupName "$RESOURCE_GROUP" \
-DataFactoryName "$FACTORY_NAME" \
-predeployment $true \
-deleteDeployment $false
# Deploy ARM template
echo "🚀 Deploying ARM template..."
az deployment group create \
--resource-group "$RESOURCE_GROUP" \
--template-file ./ARMTemplate/ARMTemplateForFactory.json \
--parameters ./ARMTemplate/ARMTemplateParametersForFactory.json \
--parameters factoryName="$FACTORY_NAME"
# Start triggers
echo "▶️ Starting triggers..."
MSYS_NO_PATHCONV=1 pwsh ./PrePostDeploymentScript.Ver2.ps1 \
-armTemplate "./ARMTemplate/ARMTemplateForFactory.json" \
-ResourceGroupName "$RESOURCE_GROUP" \
-DataFactoryName "$FACTORY_NAME" \
-predeployment $false \
-deleteDeployment $true
echo "✅ Deployment complete"
シェル検出を含む package.json
{
"scripts": {
"prevalidate": "node scripts/detect-shell.js",
"validate": "node node_modules/@microsoft/azure-data-factory-utilities/lib/index validate",
"prebuild": "node scripts/detect-shell.js",
"build": "node node_modules/@microsoft/azure-data-factory-utilities/lib/index export"
},
"dependencies": {
"@microsoft/azure-data-factory-utilities": "^1.0.3"
}
}
scripts/detect-shell.js:
const detectShell = () => {
if (process.env.MSYSTEM) {
console.log('🔧 Git Bash detected - disabling path conversion');
process.env.MSYS_NO_PATHCONV = '1';
return 'git-bash';
}
console.log(`🖥️ Shell: ${process.platform}`);
return process.platform;
};
detectShell();
よくある問題と解決策
問題 1:npm build validate が「Resource not found」で失敗する
症状:
npm run build validate ./adf-resources /subscriptions/abc/...
# Error: Resource '/subscriptions/C:/Program Files/Git/subscriptions/abc/...' not found
原因: Git Bash によってファクトリー ID のパスが変換されました。
解決策:
export MSYS_NO_PATHCONV=1
npm run build validate ./adf-resources /subscriptions/abc/...
問題 2:PowerShell スクリプトのパスが正しくない
症状:
pwsh PrePostDeploymentScript.Ver2.ps1 -armTemplate "./ARM/template.json"
# Error: Cannot find path 'C:/Program Files/Git/ARM/template.json'
原因: Git Bash によって ARM テンプレートのパスが変換されました。
解決策:
MSYS_NO_PATHCONV=1 pwsh PrePostDeploymentScript.Ver2.ps1 -armTemplate "./ARM/template.json"
問題 3:Azure CLI の template-file パラメーターが失敗する
症状:
az deployment group create --template-file ./ARMTemplate/file.json
# Error: Template file not found
原因: パス変換が Azure CLI の動作を妨げています。
解決策:
export MSYS_NO_PATHCONV=1
az deployment group create --template-file ./ARMTemplate/file.json
ベストプラクティス
1. .bashrc で MSYS_NO_PATHCONV を設定する
# Add to ~/.bashrc for Git Bash
if [ -n "$MSYSTEM" ]; then
export MSYS_NO_PATHCONV=1
fi
2. ラッパースクリプトを作成する
# adf-cli.sh - Wrapper for ADF npm commands
#!/usr/bin/env bash
export MSYS_NO_PATHCONV=1
npm run build "$@"
3. ./ を使った相対パスを使用する
# Prefer this (less likely to trigger conversion)
./ARMTemplate/ARMTemplateForFactory.json
# Over this
ARMTemplate/ARMTemplateForFactory.json
4. シェルの要件を文書化する
# README.md
## Development Environment
### Windows Users
- Use Git Bash or PowerShell Core (pwsh)
- Git Bash users: Add `export MSYS_NO_PATHCONV=1` to .bashrc
- Alternative: Use WSL2 for native Linux environment
5. 複数のシェルでテストする
# Test matrix for Windows developers
- Git Bash (MINGW64)
- PowerShell Core 7+
- WSL2 (Ubuntu/Debian)
- cmd.exe (if applicable)
クイックリファレンス
| 環境変数 | 用途 | 値 |
|---|---|---|
MSYS_NO_PATHCONV | すべてのパス変換を無効にする(Git for Windows) | 1 |
MSYS2_ARG_CONV_EXCL | 特定の引数を変換対象から除外する(MSYS2) | * またはパターン |
MSYSTEM | 現在の MSYS サブシステム | MINGW64、MINGW32、MSYS |
WSL_DISTRO_NAME | WSL ディストリビューション名 | Ubuntu、Debian など |
リソース
まとめ
重要なポイント:
- Git Bash は Unix 形式のパスを Windows のパスに自動変換します
export MSYS_NO_PATHCONV=1を使用して変換を無効にします$MSYSTEM変数を使用してシェル環境を検出します- チームで使用するすべてのシェルで CI/CD スクリプトをテストします
- クロスプラットフォームスクリプトには PowerShell Core(pwsh)を使用します
- ローカル開発スクリプトにシェル検出を追加します
コメント
Markdown 対応