diff options
author | Memphiz <memphis@machzwo.de> | 2013-08-22 23:50:28 +0200 |
---|---|---|
committer | Memphiz <memphis@machzwo.de> | 2013-08-22 23:50:28 +0200 |
commit | 32bfe5162527f76057779575f011ab95436ae70a (patch) | |
tree | b9341f20cd5517ac4f59dcbb9242cac30a3f3866 /project | |
parent | e276ddf16e851acb7adffaa5726cc6aa28969f5b (diff) |
[jenkins] - fixed approach for detecting the current branch once and for all (works for attached and detached heads and also for pull requests)
Diffstat (limited to 'project')
-rw-r--r-- | project/Win32BuildSetup/BuildSetup.bat | 10 | ||||
-rw-r--r-- | project/Win32BuildSetup/getbranch.bat | 48 |
2 files changed, 51 insertions, 7 deletions
diff --git a/project/Win32BuildSetup/BuildSetup.bat b/project/Win32BuildSetup/BuildSetup.bat index e3d29dc5e1..29fbd8ec20 100644 --- a/project/Win32BuildSetup/BuildSetup.bat +++ b/project/Win32BuildSetup/BuildSetup.bat @@ -76,13 +76,9 @@ IF %comp%==vs2010 ( set EXE= "..\VS2010Express\XBMC\%buildconfig%\XBMC.exe" set PDB= "..\VS2010Express\XBMC\%buildconfig%\XBMC.pdb" - :: when building with jenkins there's no branch. First git command gets the branch even there - :: but is empty in a normal build environment. Second git command gets the branch there. - for /f "tokens=3 delims=/" %%a in ('git branch -r --contains HEAD') do set BRANCH=%%a - IF %BRANCH%==na ( - for /f "tokens=* delims= " %%a in ('git rev-parse --abbrev-ref HEAD') do set BRANCH=%%a - ) - + :: sets the BRANCH env var + call getbranch.bat + rem CONFIG END rem ------------------------------------------------------------- diff --git a/project/Win32BuildSetup/getbranch.bat b/project/Win32BuildSetup/getbranch.bat new file mode 100644 index 0000000000..f1a2b97712 --- /dev/null +++ b/project/Win32BuildSetup/getbranch.bat @@ -0,0 +1,48 @@ +@echo off +rem this gets the current branch from either the branchname (if we attached) or +rem by using scientific branch fetching algorithms [tm] git is in detached HEAD state +rem result will be in env var %BRANCH% +SET BRANCH=na +SET DETACHED=1 +:: detect detached head +git symbolic-ref HEAD >nul 2>&1 +IF %ERRORLEVEL%==0 ( + SET DETACHED=0 +) +rem find the branchname - if current branch is a pr we have to take this into account aswell +rem (would be refs/pulls/pr/number/head then) +rem normal branch would be refs/heads/branchname +IF %DETACHED%==0 ( + FOR /f "tokens=3,4 delims=/" %%a IN ('git symbolic-ref HEAD') DO ( + IF %%a==pr ( + SET BRANCH=PR%%b + ) ELSE ( + SET BRANCH=%%a + ) + ) + GOTO branchfound +) + +:: when building with jenkins there's no branch. First git command gets the branch even there +:: it ignores all branches in the pr/ scope (pull requests) and finds the first non pr branch +:: (this mimics what the linux side does via sed and head -n1 +:: but is empty in a normal build environment. Second git command gets the branch there. +FOR /f "tokens=2,3 delims=/" %%a IN ('git branch -r --contains HEAD') DO ( + :: ignore pull requests + IF NOT %%a==pr ( + rem our branch could be like origin/Frodo (we need %%a here) + rem or our branch could be like origin/HEAD -> origin/master (we need %%b here) + rem if we have %%b - use it - else use %%a + IF NOT "%%b"=="" ( + :: we found the first non-pullrequest branch - gotcha + SET BRANCH=%%b + ) ELSE ( + SET BRANCH=%%a + ) + GOTO branchfound + ) +) +IF "%BRANCH%"=="na" ( + FOR /f "tokens=* delims= " %%a IN ('git rev-parse --abbrev-ref HEAD') DO SET BRANCH=%%a +) +:branchfound |