-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add gitswitch tool and documentation #921
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
Open
ryo246912
wants to merge
1
commit into
main
Choose a base branch
from
feat/add-gitswitch-424747221993088420
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "identities": [ | ||
| { | ||
| "id": "personal", | ||
| "name": "Your Name", | ||
| "email": "personal@example.com" | ||
| }, | ||
| { | ||
| "id": "work", | ||
| "name": "Your Name", | ||
| "email": "work@example.com" | ||
| } | ||
| ], | ||
| "bindings": [] | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ cosign = "2.6.2" | |
| "github:philschmid/mcp-cli" = "0.3.0" | ||
| "github:ryo246912/github-markdown-toc.go" = "2.0.1" | ||
| "github:ryo246912/lazychezmoi" = "0.0.1" | ||
| "github:target-ops/gitswitch" = "1.1.2" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| "github:trasta298/keifu" = "0.3.0" | ||
| "go:github.com/air-verse/air" = "1.65.1" | ||
| "go:github.com/atotto/clipboard/cmd/gocopy" = "0.1.4" | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # gitswitch 導入・利用ガイド | ||
|
|
||
| [gitswitch](https://github.com/target-ops/gitswitch) は、ディレクトリごとに Git のユーザー情報を自動で切り替えるツールです。 | ||
|
|
||
| ## 導入方法 | ||
|
|
||
| このリポジトリでは `mise` を介して `gitswitch` を導入しています。 | ||
|
|
||
| 1. **ツールのインストール** | ||
|
|
||
| ```bash | ||
| mise install | ||
| ``` | ||
|
|
||
| 2. **初期化** | ||
| 既存の設定から ID を自動検出します。 | ||
| ```bash | ||
| gitswitch init | ||
| ``` | ||
|
|
||
| ## 基本的な使い方 | ||
|
|
||
| ### アイデンティティの紐付け | ||
|
|
||
| 特定のディレクトリ配下で特定のユーザー情報を使うように設定します。 | ||
|
|
||
| ```bash | ||
| # ~/work 配下で 'work' アイデンティティを使用 | ||
| gitswitch use work ~/work | ||
|
|
||
| # ~/personal 配下で 'personal' アイデンティティを使用 | ||
| gitswitch use personal ~/personal | ||
| ``` | ||
|
|
||
| ### コミットガードの有効化 | ||
|
|
||
| 誤ったユーザー情報でのコミットを防止するために、グローバルなプリコミットフックをインストールします。 | ||
|
|
||
| ```bash | ||
| gitswitch guard install | ||
| ``` | ||
|
|
||
| ### 状態の確認 | ||
|
|
||
| 現在のアイデンティティや各レイヤー(git, ssh, gh, signing)の設定が一致しているか確認します。 | ||
|
|
||
| ```bash | ||
| gitswitch doctor | ||
| ``` | ||
|
|
||
| ## chezmoi との統合に関する注意点 | ||
|
|
||
| `gitswitch use` を実行すると、`~/.gitconfig` に `includeIf` ブロックが追加されます。 | ||
|
|
||
| ```gitconfig | ||
| # >>> gitswitch:work | ||
| [includeIf "gitdir:~/work/"] | ||
| path = ~/.config/gitswitch/identities/work.gitconfig | ||
| # <<< gitswitch:work | ||
| ``` | ||
|
|
||
| このリポジトリは `~/.gitconfig` を `dot_config/git/config.tmpl` から管理しています。`gitswitch` によって `~/.gitconfig` に直接加えられた変更は、次に `chezmoi apply` を実行した際に上書きされて消えてしまいます。 | ||
|
|
||
| ### 変更を永続化する方法 | ||
|
|
||
| `gitswitch` による設定を永続化したい場合は、`~/.gitconfig` に追加された内容を `dot_config/git/config.tmpl` に手動で転記してください。 | ||
|
|
||
| 1. `~/.gitconfig` の内容を確認 | ||
| 2. `dot_config/git/config.tmpl` の末尾などに該当の `includeIf` セクションを追記 | ||
| 3. `chezmoi apply` を実行して反映を確認 | ||
|
|
||
| ## 設定のバックアップ | ||
|
|
||
| `dot_config/gitswitch/config.json.sample` を参考に、個人の設定を `~/.config/gitswitch/config.json` に配置することができます。 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bindingsが空ですが、利用方法の参考となるように、ディレクトリとアイデンティティの紐付け設定のサンプル(例:{"path": "~/work", "identity": "work"})を含めることを検討してください。