顯示具有 Git 標籤的文章。 顯示所有文章
顯示具有 Git 標籤的文章。 顯示所有文章

2013年2月21日 星期四

git push到gerrit review server的方法與設定

假設 git project 的 url 為
   ssh://Gerrit_SERVER/Project-A

當 git clone下來後
  git clone ssh://Gerrit_SERVER/Project-A
  // 設定 review 
  git config remote.review.pushurl ssh://Gerrit_SERVER/Project-A
  git config remote.review.push refs/heads/*:refs/for/*
  // 設定bypass review
  git config remote.noreview.pushurl ssh://Gerrit_SERVER/Project-A
  git config remote.noreview.push refs/heads/*

之後當commit 之後 如果要push  進 review
  git push review

如果要 bypass review的話
  git push noreview



2012年12月26日 星期三

讓git push變成default push到code review server

假設local 端clone了一份 git project, 現在修改完後要準備push上去
如果單純只是下
   git push
的話, 會變成直接push 到 git server (假設權限允許的話)

但是現在如果多了一道 code review 的流程, 那要如何讓 git push 是先push 到 code review server呢?
一個方法是使用如下command
git push origin HEAD:refs/for/master
如果不想每次都打這麼長或忘記了直接打git push而造成bypass 了 code review階段
那可以在clone下 git project後, 先打下述指令來設定
git config remote.origin.push refs/heads/*:refs/for/*
之後的git push就會先push到code review server了

2012年12月18日 星期二

Revert/undo commit

git reset --soft HEAD^ reference: http://stackoverflow.com/questions/927358/undo-last-git-commit

檢查client與gerrit server的connection是否正常和正確設定code review

方法如下:
ssh -p PORT User@HostName
如果運作正常, 那應該會顯示下面訊息:
(如果port = 29418)
  $ ssh -p 29418 sshusername@hostname

    ****    Welcome to Gerrit Code Review    ****

    Hi John Doe, you have successfully connected over SSH.

    Unfortunately, interactive shells are disabled.
    To clone a hosted Git repository, use:

    git clone ssh://sshusername@hostname:29418/REPOSITORY_NAME.git

  Connection to hostname closed.


另外, 該如何知道Gerrit server所使用的port number呢?
可以用這個方法
curl http://HostName/ssh_info
這時候就會獲得下述訊息
HostName PORT

這個查詢port number的方法所輸入的url還需要依據實際情況作修正, 以現在公司的情況來說, server的url是http://HostName/DHC
因此如果要查詢 port number 則使用的指令就為
curl http://HostName/DHC/ssh_info

另外 其實這同時也就是code review server的url , 這部份也讓我在編輯repo manifest file時卡好久, 一直無法使用repo upload正確的自動upload commits到code review server

以公司為例, repo manifest file的review欄位就必須要寫成
fetch="ssh://HostName:PORT" review="HostName/DHC" /> remote="yyyy" sync-j="4" /> ........... ..........
reference: https://review.openstack.org/Documentation/user-upload.html

2012年12月17日 星期一

更改git的editor

由於習慣用vim, 所以如果要將git 的editor改成vim的話 可以用下述的指令
git config --global core.editor vim

2012年12月14日 星期五

mirror android source to an internal git/gerrit server

花了好長一段時間 目前看來終於有初步結果了
就以git://github.com/MIPS/ 為例子

步驟一:
首先創建一個 mirror的參考project, 重點是把相關的access control permission設好, 之後要mirror的project都繼承自該project, 或者是去修改ALL-Projects 的 access permission, 至於要設哪些permission其實我還不是很清楚, 反正我就幾乎全開了XD,  如下:


Rights Inherit From:
Reference:
refs/for/*
Push

Push Merge Commit

Reference:
refs/heads/*
Read


Create Reference

Forge Author Identity

Forge Committer Identity

Forge Server Identity

Push

Push Merge Commit

Push Annotated Tag

Label Code-Review
 
 
Rebase

Submit

Reference:
refs/meta/config
Read

Create Reference

Forge Author Identity

Forge Committer Identity

Forge Server Identity

Push

Push Merge Commit

Push Annotated Tag

Submit

Reference:
refs/tags/*
Read

Create Reference

Forge Author Identity

Forge Committer Identity

Forge Server Identity

Push

Push Merge Commit

Push Annotated Tag

Submit

步驟二:
1. mkdir mirror-folder
2. repo init -u git://github.com/MIPS/manifests.git --mirror
3. repo sync -j4
4. repo forall -c 'ssh -p PORT ACCOUNT@SERVER gerrit create-project PROJECT_ROOT/$REPO_PROJECT;  \
    ssh -p PORT ACCOUNT@SERVER gerrit set-project-parent --parent mirror-project-permission-base PROJECT_ROOT/$REPO_PROJECT; \
    git push ssh://ACCOUNT@SERVER:PORT/PROJECT_ROOT/$REPO_PROJECT 'refs/heads/*' 'refs/tags/*' 'refs/notes/*''


note: 紅色字的部份很重要, 這是試了好多種方式後目前可行的方式

步驟三:
1. 接下來就先去 git clone 其manifests的project的下來 修改其xml file, 使其fetch/review的url能對應到internal server

1. git clone ssh://ACCOUNT@SERVER:PORT/PROJECT_ROOT/manifests
2. 將default.xml 的fetch and review URLs改成internal server, 例如
             fetch="git://github.com/MIPS"
             remote="mips"
             sync-j="4"
==>  
           fetch="ssh://SERVER:PORT/PROJECT_ROOT"
           review="SERVER:PORT"
           remote="mips"
           sync-j="4"

然後push回server

步驟四:
接下來就可以照repo init & repo sync的動作來將整包source tree 都 checkout回來, 如
1. repo init -u ssh://ACCOUNT@SERVER:PORT/PROJECT_ROOT/manifests
2. repo sync

Reference:
https://groups.google.com/forum/?fromgroups=#!topic/repo-discuss/zpqpPpHAwSM
https://wiki.linaro.org/Platform/Infrastructure/GerritNotes
https://groups.google.com/forum/?fromgroups=#!topic/repo-discuss/qXBILfjVV04
https://groups.google.com/forum/?fromgroups=#!msg/repo-discuss/F8wQCreKv4c/L3DOAPPiQpMJ

2012年12月12日 星期三

指令:列出remote server有哪些projects

列出remote server有哪些projects

ssh -p port-number user-account@gerrit-server gerrit ls-projects

透過指令來創建遠端的git project


Create a new project called tools/gerrit:
$ ssh -p 29418 review.example.com gerrit create-project tools/gerrit.git
Create a new project with a description:
$ ssh -p 29418 review.example.com gerrit create-project tool.git --description "'Tools used by build system'"

詳情可以參考

https://review.openstack.org/Documentation/cmd-create-project.html

git clone時發生permission denied (publickey)

當我第一次使用git clone command時發生了 permission denied (publickey) 的錯誤訊息
但是明明我已經在Gerrit server上的個人設定指定好了SSH public key
後來經由同事的告知 才知道原因是因為client端的使用者帳號與server端的不一致所造成

參考這個網站 http://gerrit.googlecode.com/svn/documentation/2.2.1/error-permission-denied.html
其實就可以知道, 當在使用git clone時 是可以指定user account的

因此第一步如果要確認你的設定是否正確 可以使用這個指令來確認
ssh -vv -p port-number user-account@server-address

如果成功就會出現以下訊息

  ...

  debug1: Authentication succeeded (publickey).

  ...

  ****    Welcome to Gerrit Code Review    ****

  Hi John Doe, you have successfully connected over SSH.

  Unfortunately, interactive shells are disabled.
  To clone a hosted Git repository, use:

  git clone ssh://user-account@server-address:port-number/REPOSITORY_NAME.git

因此如果你的client端的user account與git server端的不一樣
那正確clone的指令是要在server-address前面加上user-account@

2012年12月11日 星期二

產生SSH key for Gerrit/Git server

在設定code review server (Gerrit + Git) 的帳號時 當使用的是SSH protocol則會需要設定好你自己的SSH public key, 設定方法如下

A. 產生SSH keys
  1. 檢查你的home目錄下是否存在.ssh資料夾, 如果存在就先備份該資料夾內的東西, 然後移除該資料夾
  2. 產生SSH keys
      ssh-keygen -t rsa -C "your_email@youremail.com"
     跳出提示問題時 直接按enter就好
 3. 接下來會要你輸入passphrase, 如果你在乎的話就輸入字串, 不然直接按enter也可以

B. 將public key內容複製貼上到Gerrit server上的SSH Public keys
     public key 位在 ~/ssh/id_rsa.pub

也可以參考此網站
https://help.github.com/articles/generating-ssh-keys