LoginSignup
17
8

More than 5 years have passed since last update.

Rust製gitラッパー "rusgit"

Last updated at Posted at 2018-01-16

速い/安全だと最近話題のRustで、gitコマンドをラップして使いやすくしてみました!
URL: https://github.com/miyagaw61/rusgit

インストール

事前にcargoのインストールが必要です。

curl https://sh.rustup.rs -sSf | sh #This command can download cargo to $HOME/.cargo
source $HOME/.cargo/env #You should write this to bashrc.

cargoでrusgitをインストール

cargo install --git https://github.com/miyagaw61/rusgit

個人的便利サブコマンドランキングTop3

  1. undo
    何かをやらかした時に対処するサブコマンドです。
    このラッパーの目玉機能でもあります。

  2. init
    補完とエイリアスってやっぱ大事ですよね。
    最初にこれをしておくだけでかなり効率が上がります。

3.integrate
統合ブランチに統合させるサブコマンドです。
地味にめんどくさい統合処理を自動化してくれます。
注意:現在はbetaブランチにのみ実装されています。

使い方

rusgit 1.0.0
miyagaw61 <miyagaw61@gmail.com>
Git Wrapper in Rust

USAGE:
    rusgit [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    ac          rusgit add and rusgit commit
    add         improved git-add
    branch      improved git-branch
    clone       improved git-clone
    commit      improved git-commit
    complete    completiton subcommand
    diff        improved git-diff
    help        Prints this message or the help of the given subcommand(s)
    log         improved git-log
    merge       improved git-merge
    pull        improved git-pull
    push        improved git-push
    rebase      improved git-rebase
    status      improved git-status
    tag         improved git-tag
    undo        undo actions

init

補完の設定をするコマンドです。
オプションでaliasも設定できます。
まず最初にこれをbashrcに書いておきましょう。

基本の使い方は以下のようになります。

eval "$(rusgit init <option>)"

独自のaliasを設定する場合は、次のように設定してください。

addとcommitのaliasを設定する場合
eval "$(rusgit init --add ra --commit rc)"

ちなみに、rusgit statusのaliasをrusgit init --status rsというように設定しても良いのですが、私は--lsオプション有りでstatusのaliasを設定したいので、別途`alias rs="rusgit status --ls 'ls -

私のオススメの初期設定をまとめておきます。

オススメ設定
eval "$(rusgit init --add ra --ac rac --diff rd --branch rb --undo ru --tag rt --push rpush --pull rpull --merge rmerge --rebase rrebase --log rl --commit rc --clone rclone --integrate rint
alias rs="rusgit status --ls 'ls --color=always'"

このようにbashrcに書いておくと、いつでも補完とaliasが効くようになります。

clone

clone
rusgit clone <user_name>/<repository_name> <directory>

status

ステータス表示(シンプル)
rusgit status
ステータス表示(verbose)
rusgit status -v
ls結果付きでステータス表示
rusgit status --ls 'ls --color=always'
rusgit status -v --ls 'ls --color=always'

add

add
rusgit add <files>...
分割add
rusgit add -p

commit

コミット
rusgit commit <commit message>...
#ダブルクオーテーションが不必要なところに注目!(あっても大丈夫です)
#Example:
rusgit commit This is comment.
コミットメッセージ修正(amend)
rusgit commit -a

引数無しで実行すると、エディタが開きます。

エディタでコミットメッセージ入力
rusgit commit

この時のエディタを独自で設定したいなら、$RUSGIT_EDITOR環境変数を設定しておきましょう。

エディタを独自設定
export RUSGIT_EDITOR="vim -u NONE -N"
rusgit commit

プレフィックス自動生成機能

先頭の2文字を特定の1文字+空白にすることで、コミットメッセージのプレフィックスを自動で生成することができます。

・i -> Improve
・I -> Implement
・r -> Remove
・R -> Refactor
・u -> Use
・U -> Update
・a -> Add
・c -> Change
・f -> Fix
・s -> Support
・l -> Allow
・v -> Avoid

(例)

rusgit commit a hoge-method to fuga-class
# Add hoge-method to fuga-class

ac

addとcommitを自動化
rusgit ac <files>...
addとコミットメッセージ付きcommitを自動化
rusgit ac <files>... -m <message>...
#messageオプションが最後の場合はダブルクオーテーションが不必要!
#Example:
rusgit ac -m "This is comment." file01 file02
rusgit ac file01 file02 -m This is comment.

プレフィックス自動付与オプション

acサブコマンドでもcommitサブコマンドと同様にプレフィックスを自動で生成する機能があります。
しかし、acサブコマンドには、プレフィックスを決定するための特定の1文字+空白すら必要の無くなる、プレフィックス自動付与オプションが各プレフィックスごとに用意してあります。

-a, --add <message>...          add-prefix message
-l, --allow <message>...        allow-prefix message
-v, --avoid <message>...        avoid-prefix message
-c, --change <message>...       change-prefix message
-f, --fix <message>...          fix-prefix message
-I, --implement <message>...    implement-prefix message
-i, --improve <message>...      improve-prefix message
-m, --message <message>...      commit message
-R, --refactor <message>...     refactor-prefix message
-r, --remove <message>...       remove-prefix message
-s, --support <message>...      support-prefix message
-U, --update <message>...       update-prefix message
-u, --use <message>...          use-prefix message

(例)

rusgit ac file01 -f typo in hoge-function
# Fix typo in hoge-function

ファイル名自動付与機能

files引数の数が一つだけの時、コミットメッセ―ジの最後の3~4文字を「空白+特定の文字列」にすることで、コミットメッセージの最後にファイル名を自動付与することができます。

・to
・in
・for

(例)

rusgit ac file01 -a hoge-function to
# Add hoge-function to file01

log

log(3件)
rusgit log
log(n件)
rusgit log <log num>
log(verbose)
rusgit log -v
log(graph)
rusgit log -g
log(all)
rusgit log -a
reflog(現在のブランチ)
rusgit log -r
reflog(指定のブランチ)
rusgit log -r <branch-name>
reflog(全て)
rusgit log -ra

diff

diff
rusgit diff <file-name>
ステージングされたファイルのdiff(--cached)
rusgit diff -c <file-name>
コミットIDでdiff
rusgit diff <commit-id>
ローカルリポジトリとリモートリポジトリのdiff
rusgit diff ..<remote-repository>
rusgit diff <remote-repository>..

branch

ブランチ一覧
rusgit branch
ブランチ移動
rusgit branch <既存ブランチ名>
ブランチ作成
rusgit branch <未作成ブランチ名>
リモートブランチを持ってくる
rusgit branch <未作成ブランチ名> <リモートブランチ名>
リモートブランチを削除
rusgit branch --remote-delete <ブランチ名>

merge

merge
rusgit merge <branch>

rebase

rebase
rusgit rebase <branch>
コミットIDを指定してそこまでrebase
rusgit rebase -i <commit-id>

pull

pull(現在いるブランチへ)
rusgit pull
pull(ブランチ指定)
rusgit pull <branch>

tag

タグ一覧
rusgit tag
タグ作成
rusgit tag <tag-name>
メッセージ付きタグ作成
rusgit tag <tag-name> -m <message>
タグの詳細
rusgit tag -s <tag-name>
タグの削除
rusgit tag -d <tag-name>

undo

このラッパーの目玉サブコマンド!
何かをやらかした時に役立ちます!

USAGE:
    rusgit undo <SUBCOMMAND>

SUBCOMMANDS:
    add       undo adding stage
    commit    undo commit(keep changes)
    head      undo changes
    orig      go to ORIG_HEAD
add取り消し
rusgit undo add <file-name>
commit取り消し(変更は残す)
rusgit undo commit
commit取り消し(変更ごと戻す)
rusgit undo commit --hard
指定されたコミットIDの状態まで戻す(変更は残す)
rusgit undo commit --id <commit-id>
指定されたコミットIDの状態まで戻す(変更ごと戻す)
rusgit undo commit --id <commit-id> --hard
ファイル一つを最後に記録されている状態に戻す
rusgit undo head <file-name>
指定されたコミットIDの状態まで戻す(変更は残す)
rusgit undo commit --id <commit-id>
指定されたコミットIDの状態まで戻す(変更ごと戻す)
rusgit undo commit --id <commit-id> --hard
ファイル一つを最後に記録されている状態に戻す
rusgit undo head <file-name>
ORIG_HEADまで戻る(undo-commitやmergeの取り消し等)(変更は残す)
rusgit undo orig
ORIG_HEADまで戻る(undo-commitやmergeの取り消し等)(変更ごと戻す)
rusgit undo orig --hard

integrate

統合ブランチへ統合するためのサブコマンドです(注意:現在はbetaブランチにのみ実装されています)(しかも未完成です)。
具体的には、
1.統合ブランチを最新にする
2.featureブランチを統合ブランチでrebase
3.統合ブランチへfeatureブランチをマージ
を自動化します。
コンフリクト等の問題が発生した場合は、そこで一時停止します。
再開するには、continueします。

統合
rusgit integrate <ブランチ名>
コンフリクト等の問題を解消した後続行
rusgit integrate --continue
rusgit integrate -c

追加予定の機能

stash

stash周り

browse

現在いるリポジトリのページをブラウザで開くコマンド

blame

blameやbisect関係

describe

cat-fileやdescribeを駆使してそのコミットの詳細情報を取得するコマンド

commit --fixup / rebase --autosquash 周り

ネイティブgitはcommit --fixupとrebase --autosquashで効率良くfixができるので、そこらへんの機能を更に便利にして追加する予定です。

コンフリクト解消系

コンフリクトした時、git show :[1/2/3]:[file-name]でbaseとoursとtheirsが見れるので、(git ls-files -uでハッシュ値が取れる)そこらへんを利用したコンフリクト解消系サブコマンドを追加する予定で

最後に

いつでも機能追加依頼やバグ報告等は募集中です。
もちろんissueでも大丈夫ですが、@miyagaw61にDMでもリプでもしていただければ、実装しますので、よろしくお願いします。

17
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
8