| 210 | === Git === |
| 211 | |
| 212 | Projects that use git may be handled similarly but they have their own specifics. There is currently no real-life example of such a project in our repositories but let's assume there is a project called `foobar` with a remote repository at `git://mygitserver.com`. |
| 213 | |
| 214 | Paste this block after the main keyword block and before the `%description` field for the main package: |
| 215 | {{{ |
| 216 | %define git_url git://mygitserver.com/foobar.git |
| 217 | %define git_rev mytag |
| 218 | |
| 219 | Source: %{name}-%{git_rev}.zip |
| 220 | |
| 221 | BuildRequires: gcc make git zip |
| 222 | }}} |
| 223 | |
| 224 | Paste this block instead of the usual `%prep / %setup / %patch` sequence: |
| 225 | {{{ |
| 226 | %prep |
| 227 | %if %(sh -c 'if test -f "%{_sourcedir}/%{name}-%{git_rev}.zip" ; then echo 1 ; else echo 0 ; fi') |
| 228 | %setup -q |
| 229 | %else |
| 230 | %setup -n "%{name}-%{version}" -Tc |
| 231 | rm -f "%{_sourcedir}/%{name}-%{git_rev}.zip" |
| 232 | git archive --format zip --output "%{_sourcedir}/%{name}-%{git_rev}.zip" --prefix "%{name}-%{version}/" --remote "%{git_url}" "%{git_rev}" |
| 233 | unzip "%{name}-%{git_rev}.zip" -d .. |
| 234 | %endif |
| 235 | }}} |
| 236 | |
| 237 | Note that you may use your local clone instead of the remote repository as well as with SVN to save some traffic. The URL in this case should be something like `file://D:/Coding/foobar`. |
| 238 | |
| 239 | === Github === |
| 240 | |
| 241 | If a project is hosted at [http://github.com github], we will need to use `curl` instead of `git archive` because github does not support the `archive` command and instead provides a special URL for downloading ZIPs of the tree at any given commit or tag. The snippets below are based on this real-life [http://trac.netlabs.org/rpm/browser/spec/trunk/SPECS/libkai.spec?rev=576 spec file]. |
| 242 | |
| 243 | Paste this block after the main keyword block and before the `%description` field for the main package: |
| 244 | {{{ |
| 245 | %define github_name kai |
| 246 | %define github_url https://github.com/komh/%{github_name}/archive |
| 247 | %define github_rev kai-%{version} |
| 248 | |
| 249 | Source: %{github_name}-%{github_rev}.zip |
| 250 | |
| 251 | BuildRequires: gcc make curl zip |
| 252 | }}} |
| 253 | |
| 254 | Paste this block instead of the usual `%prep / %setup / %patch` sequence: |
| 255 | {{{ |
| 256 | %prep |
| 257 | %if %(sh -c 'if test -f "%{_sourcedir}/%{github_name}-%{github_rev}.zip" ; then echo 1 ; else echo 0 ; fi') |
| 258 | %setup -n "%{github_name}-%{github_rev}" -q |
| 259 | %else |
| 260 | %setup -n "%{github_name}-%{github_rev}" -Tc |
| 261 | rm -f "%{_sourcedir}/%{github_name}-%{github_rev}.zip" |
| 262 | curl -sSL "%{github_url}/%{github_rev}.zip" -o "%{_sourcedir}/%{github_name}-%{github_rev}.zip" |
| 263 | unzip "%{_sourcedir}/%{github_name}-%{github_rev}.zip" -d .. |
| 264 | %endif |
| 265 | }}} |
| 266 | |
| 267 | Note that due to github naming specifics (and especially if the github's project name doesn't match the RPM package name, (like `kai` vs `libkai` in the example above), the source ZIP will have a name that differs from the usual `%{name}-%{version}` scheme (in the example above it will be `kai-kai-1.1.4.zip` rather than `libkai-1.1.4.zip`). |
| 268 | |
| 269 | You could use your local clone instead of the remote repository here as well but in this case magic github URLs for downloading ZIPs won't work so you will have to use the `git archive` command as in the [#Git] section above which is not very practical because you will have to make a lot of temporary changes to your `.spec` file which you will have to revert before committing it to the SPEC repo. |
| 270 | |