Commit 4dfe5e1
authored
Fetch using short commit SHA (#160)
## Description
This relates to woodpecker-ci/woodpecker#3965
and closes woodpecker-ci/woodpecker#3932.
The Bitbucket Pull Request Hook returns a short commit SHA. The git
fetch command requires a full-length SHA. Add a clause to detect when
the SHA1 has less than 40 characters. Fetch & switch the branch to reset
the expected commit.
Raise an error if the branch value is not defined.
## Test
Run script:
```shell
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on
export CI_REPO_CLONE_URL=https://{User}:{Token}@bitbucket.org/{Workspace}/{Project}.git
export CI_WORKSPACE=./woodpecker
export CI_BUILD_EVENT=push
export CI_COMMIT_SHA=692972aabfec
export CI_COMMIT_BRANCH=test
./release/linux/amd64/plugin-git
```
Output:
```shell
+ git init -b test
Initialised empty Git repository in /home/pc415/bit2me/plugin-git/woodpecker/.git/
+ git config --global --replace-all safe.directory ./woodpecker
+ git remote add origin https://{User}:{Token}@bitbucket.org/{Workspace}/{Project}.git
+ git fetch --no-tags --depth=1 --filter=tree:0 origin +test:
warning: filtering not recognized by server, ignoring
From https://bitbucket.org/{Workspace}/{Project}.git
* branch test -> FETCH_HEAD
* [new branch] test -> origin/test
+ git switch -q test
+ git reset --hard -q 692972aabfec
+ git submodule update --init --recursive --depth=1 --recommend-shallow
+ git lfs fetch
```1 parent 7ac9615 commit 4dfe5e1
2 files changed
+59
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
84 | 93 | | |
85 | 94 | | |
86 | 95 | | |
| |||
256 | 265 | | |
257 | 266 | | |
258 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
259 | 278 | | |
260 | 279 | | |
261 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
101 | 112 | | |
102 | 113 | | |
103 | 114 | | |
| |||
143 | 154 | | |
144 | 155 | | |
145 | 156 | | |
| 157 | + | |
146 | 158 | | |
147 | 159 | | |
148 | 160 | | |
| |||
190 | 202 | | |
191 | 203 | | |
192 | 204 | | |
| 205 | + | |
193 | 206 | | |
194 | 207 | | |
195 | 208 | | |
| |||
372 | 385 | | |
373 | 386 | | |
374 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
375 | 415 | | |
376 | 416 | | |
377 | 417 | | |
| |||
0 commit comments