複数のリポジトリが存在する環境で、 複数のリポジトリに対して一括でgit操作を行えるスクリプト群です。
誤った指定に対しては、警告を表示しmerge/push実行しないことで、事故を防止しています。
- eccube/ 配下に、本コードを配置します. (初回のみ)
cd eccube_web/eccube/
git clone git@github.com:yasuke-kuroda-diezon/script__git.git
- 本コードを、ec-cubeリポジトリのGit管理の対象外とします. (初回のみ)
echo "script__git/" >> .git/info/exclude
- スクリプトに実行権限を付与します (初回のみ)
chmod +x ./script__git/*.sh
- configファイルに、ブランチの設定を記述します.
(※設定の記述方法は、ファイル内に記載しています)
vim script__git/config/config.sh
- スクリプト実行します (例)
./script__git/pull.sh
./script__git/delete_fully_merged_branch.sh
以下のファイルは編集不要です。 対象ブランチは、script__git/config/config.shの内容を読み込んで実行します。
| コマンド | 1つずつのリポジトリに対して行う処理 |
|---|---|
| ./script__git/pull.sh | git pullを実行 |
| ./script__git/checkout.sh | git checkoutを実行 |
| ./script__git/restore.sh | git restoreを実行 |
| ./script__git/merge_and_push.sh | git merge && git pushを実行 |
| ./script__git/delete_untracked_files.sh | git clean -fを実行(git管理してないファイルを削除します) |
| ./script__git/delete_fully_merged_branch.sh | git branch -dを実行(マージ済みブランチを安全に削除します。feature作業ブランチなど。) |
script__git/
├── config/
│ └── config.sh # 設定ファイル.
├── base/
│ └── main.sh
├── lib/
│ ├── git_command.sh # gitコマンド一覧.
│ ├── log.sh
│ └── task.sh # gitコマンドを組み合わせたタスクセットの一覧.
├── checkout.sh
├── delete_fully_merged_branch.sh
├── delete_untracked_files.sh
├── merge_and_push.sh
├── pull.sh
├── restore.sh
└── README.md
./script__git/merge_and_push.shを実行する際、以下のような危険な操作を防ぐためのバリデーションを行っています。
- main(master)ブランチ上で、
git merge xxxを実行することはできません (=main(master)ブランチは、別ブランチにマージされることのみ許可します)
- yyyブランチ上で、
git merge stagingを実行することはできません (=staging(develop)ブランチは、別ブランチをマージすることのみ許可します)
config/config.shにprojectType="RegolithHeadless"を指定することで対応可能です。
cd regolith-docker/
echo "script__git/" >> .git/info/exclude
chmod +x ./script__git/*.sh
./script__git/pull.sh
ディレクトリ構成に悩みました。
- スクリプトは
bin/に入れたかったけど、実行パスがその分長くなってしまい使いやすさを失うので、bin/に入れず、本リポジトリの直下にスクリプト群を配置しました. main.shは実行権限を付与する必要がなく、mを入力してタブキー押下でmerge_and_push.shを実行できるように、実行スクリプト群とmain.shのディレクトリを分けました。core/main.shにすると、config/とcoまで重複するので、coまで入力してタブキー押下で設定ファイルが開けなくなるので、core/は採用できず、base/にしました。