Gerrit 和 Git 第一次設定

1.Gerrit 安裝

Android Studio > Preferences > PlugIn 搜尋 Gerrit 並安裝

VCS-Enable Version Control Integration2

2.SSH設定

  • Generate key In ~/.ssh/

    • ssh-keygen -f ~/.ssh/$yourname (Ex: ssh-keygen -f ~/.ssh/gemtekers)

    • Cat $yourname.pub and add into gerrit

  • Modfied ~/.ssh/config and add

    • host gerrit.gemteks.com

    • user $account port 29418 (Ex: user gemtekers port 294

    • identityfile ~/.ssh/$yourname (Ex: identityfile ~/.ssh/gemtekers)

3.Gerrit網站 SSH Key and HTTP Password 設定

http://gerrit.gemteks.com:8080/#/

帳號 : Gemtek domain account

產生HTTP的password

4.設定 Android Studio Gerrit HTTP帳號和網址

Android Studio > Preferences > Version Control > Gerrit

輸入 Gerrit URL 和剛剛的 HTTP Username , Password

5.Clone Project

如果之前都沒問題的話 , 選擇底下的路徑可以看到Gerrit底下的專案,也可以直接從Gerrit複製ssh的檔案連結

File > New > Project from Version Control > Gerrit

6.Git Hook : Commit Message , PreCommit Message

打開Android Studio的 Terminal介面輸入下列指令

  • 指令下載 ~/.git/hook/commit-msg (在message 後面結尾加上 Change-ID For Gerrit )

: gitdir=$(git rev-parse --git-dir); scp -p -P 29418 $(ID)@gerrit.gemteks.com:hooks/commit-msg${gitdir}/hooks/

(EX: gitdir=$(git rev-parse --git-dir); scp -p -P 29418 [email protected]:hooks/commit-msg ${gitdir}/hooks/)

  • 請手動新增 ~/.git/hook/pre-commit (Merge的時候呼叫commit-msg的hook)

#!/bin/sh
if [ "$2" = "merge" -a -f .git/MERGE_MSG ]; then
# Explicitly call Gerrit's commit-msg hook for merge commits.
    .git/hooks/commit-msg "$1"
fi  Use android studio to commit and push

7.編輯完可使用Git介面做Commit , Push , Pull...

Ps:強烈建議在push之前先做一次Pull

Ps:如果沒有.gitIgnore 請手動去plugin安裝

Q&A

1.Gerrit Permission Denied Problem:

~/.ssh 確認本資料夾下的三個檔案

  • config : add Gerrit host and username
  • ***.pub : private key to Gerrit Server
  • known_hosts : add Gerrit host public key

results matching ""

    No results matching ""