2016-08-24 100 views
1

我正在嘗試爲我正在處理的基於buildroot的項目自動生成版本號。目前有一個meta-repo包含了buildroot,包的配置和腳本來從頭開始構建項目。第二個存儲庫包含構建爲buildroot包之一的特定於應用程序的源代碼。如何讓git描述如遠程存儲庫的輸出

當buildroot運行時,它會在指定的分支頭執行軟件包回購的淺層克隆。我想要一種運行git的方式來描述這一點,而無需對存儲庫進行完整的克隆。

目前該項目能夠使用git describe生成相當準確的內部版本號。我們用主版本和次版本來標記版本,然後我們需要自構建過程中添加標籤以來的提交數量。

我已經設法使用git ls-remote來生成SHA1哈希,但是我無法獲得提交計數,是否有人知道實現此目的的方法?

+1

獲得的唯一方式提交*計數*是有自己的提交。 *最簡單*的方法是做一個完整的克隆。 (使用'--reference'並保留一個參考克隆來加快速度。)*最快*的方式可能是讓遠程服務器首先獲得'git describe'字符串。 – torek

回答

0

因此經過很多努力和搜索,我放棄了遠程獲取它,並將以下部分寫入我的Makefile以生成我想要的字符串。 GIT_SITE是遠程倉庫的地址,GIT_BRANCH是被克隆的分支的名稱,例如:releaseCandidate/4.0

GIT_COMMIT_NUMBER = $(shell git clone $(GIT_SITE) -n -q temp && cd temp && git rev-list --count master..origin/$(GIT_BRANCH) && cd .. && rm -fr temp) 

# This was easier to do, pulls the hash from the remote repo and cuts it down to be 7 characters long (same as would come out of git describe) 
GIT_HASH = $(shell git ls-remote $(GIT_SITE) $(GIT_VERSION) | cut -f 1 | awk '{print substr($$0,1,7) }') 

# This cuts down the branch name given to us by buildroot so that we cas use it in the build string generation 
GIT_BRANCH_FLAG = $(shell echo $(GIT_BRANCH) | cut -f 1 -d '/') 
GIT_BRANCH_VERSION = $(shell echo $(GIT_BRANCH) | cut -f 2 -d '/') 

# Finally we put those bits together to get the outputs we want 
VERSION ?= $(GIT_BRANCH_VERSION) 
GIT_DESCRIBE ?= $(GIT_BRANCH_VERSION)-$(GIT_COMMIT_NUMBER)-g$(GIT_HASH)-$(GIT_BRANCH_FLAG)