Created
January 17, 2025 02:58
-
-
Save f440/c80e0b5d955a72ebbb3c491b8bc7d691 to your computer and use it in GitHub Desktop.
git rebase 中に pnpm-lock.yaml がコンフリクトしたら解消するスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# コンフリクトしているファイルを取得する関数 | |
get_conflicted_files() { | |
git diff --name-only --diff-filter=U | |
} | |
# rebaseを実行し、結果を処理する関数 | |
handle_rebase() { | |
if ! git rebase "$@" 2>/dev/null; then | |
local conflicted_files | |
conflicted_files=$(get_conflicted_files) | |
# コンフリクトしているファイルがpnpm-lock.yamlのみかチェック | |
if [ "$conflicted_files" = "pnpm-lock.yaml" ]; then | |
echo "pnpm-lock.yamlのコンフリクトを自動解決します" | |
if pnpm install && git add pnpm-lock.yaml && GIT_EDITOR=true git rebase --continue; then | |
# rebaseが成功した場合は再帰的に処理を続行 | |
handle_rebase "$@" | |
else | |
# rebase --continueが失敗した場合は再度コンフリクトをチェック | |
local new_conflicts | |
new_conflicts=$(get_conflicted_files) | |
if [ -n "$new_conflicts" ]; then | |
if [ "$new_conflicts" = "pnpm-lock.yaml" ]; then | |
echo "新しいpnpm-lock.yamlのコンフリクトを自動解決します" | |
handle_rebase "$@" | |
else | |
echo "pnpm-lock.yaml以外のファイルでコンフリクトが発生しました" | |
echo "コンフリクトしているファイル:" | |
echo "$new_conflicts" | |
exit 1 | |
fi | |
fi | |
fi | |
else | |
echo "pnpm-lock.yaml以外のファイルでコンフリクトが発生しました" | |
echo "コンフリクトしているファイル:" | |
echo "$conflicted_files" | |
exit 1 | |
fi | |
fi | |
} | |
# メイン処理 | |
handle_rebase "$@" | |
echo "rebaseが完了しました" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment