debian-mirror-gitlab/doc/api/branches.md

273 lines
8.2 KiB
Markdown
Raw Normal View History

2017-09-10 17:25:29 +05:30
# Branches API
2014-09-02 18:07:02 +05:30
## List repository branches
Get a list of repository branches from a project, sorted by name alphabetically.
2017-08-17 22:00:37 +05:30
This endpoint can be accessed without authentication if the repository is
publicly accessible.
2014-09-02 18:07:02 +05:30
```
GET /projects/:id/repository/branches
```
2016-04-02 18:10:28 +05:30
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-08-17 22:00:37 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
2018-03-27 19:54:05 +05:30
| `search` | string | no | Return list of branches matching the search criteria. |
2014-09-02 18:07:02 +05:30
2016-04-02 18:10:28 +05:30
```bash
2017-08-17 22:00:37 +05:30
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/5/repository/branches
2016-04-02 18:10:28 +05:30
```
Example response:
2014-09-02 18:07:02 +05:30
```json
[
{
2016-04-02 18:10:28 +05:30
"name": "master",
2017-08-17 22:00:37 +05:30
"merged": false,
2016-04-02 18:10:28 +05:30
"protected": true,
2016-08-24 12:49:21 +05:30
"developers_can_push": false,
"developers_can_merge": false,
2014-09-02 18:07:02 +05:30
"commit": {
2015-04-26 12:48:37 +05:30
"author_email": "john@example.com",
"author_name": "John Smith",
"authored_date": "2012-06-27T05:51:39-07:00",
"committed_date": "2012-06-28T03:44:20-07:00",
"committer_email": "john@example.com",
"committer_name": "John Smith",
2014-09-02 18:07:02 +05:30
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
2017-08-17 22:00:37 +05:30
"short_id": "7b5c3cc",
"title": "add projects API",
2014-09-02 18:07:02 +05:30
"message": "add projects API",
2015-04-26 12:48:37 +05:30
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
]
2016-04-02 18:10:28 +05:30
}
},
...
2014-09-02 18:07:02 +05:30
]
```
## Get single repository branch
2017-08-17 22:00:37 +05:30
Get a single project repository branch. This endpoint can be accessed without
authentication if the repository is publicly accessible.
2014-09-02 18:07:02 +05:30
```
GET /projects/:id/repository/branches/:branch
```
2016-04-02 18:10:28 +05:30
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-08-17 22:00:37 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
2016-04-02 18:10:28 +05:30
| `branch` | string | yes | The name of the branch |
2014-09-02 18:07:02 +05:30
2016-04-02 18:10:28 +05:30
```bash
2017-08-17 22:00:37 +05:30
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/5/repository/branches/master
2016-04-02 18:10:28 +05:30
```
Example response:
2014-09-02 18:07:02 +05:30
```json
{
2016-04-02 18:10:28 +05:30
"name": "master",
2017-08-17 22:00:37 +05:30
"merged": false,
2016-04-02 18:10:28 +05:30
"protected": true,
2016-08-24 12:49:21 +05:30
"developers_can_push": false,
"developers_can_merge": false,
2014-09-02 18:07:02 +05:30
"commit": {
2015-04-26 12:48:37 +05:30
"author_email": "john@example.com",
"author_name": "John Smith",
"authored_date": "2012-06-27T05:51:39-07:00",
"committed_date": "2012-06-28T03:44:20-07:00",
"committer_email": "john@example.com",
"committer_name": "John Smith",
2014-09-02 18:07:02 +05:30
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
2017-08-17 22:00:37 +05:30
"short_id": "7b5c3cc",
"title": "add projects API",
2014-09-02 18:07:02 +05:30
"message": "add projects API",
2015-04-26 12:48:37 +05:30
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
]
2016-04-02 18:10:28 +05:30
}
2014-09-02 18:07:02 +05:30
}
```
## Protect repository branch
2017-09-10 17:25:29 +05:30
>**Note:** This API endpoint is deprecated in favor of `POST /projects/:id/protected_branches`.
2016-04-02 18:10:28 +05:30
Protects a single project repository branch. This is an idempotent function,
protecting an already protected repository branch still returns a `200 OK`
status code.
2014-09-02 18:07:02 +05:30
```
PUT /projects/:id/repository/branches/:branch/protect
```
2016-04-02 18:10:28 +05:30
```bash
2017-08-17 22:00:37 +05:30
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/5/repository/branches/master/protect?developers_can_push=true&developers_can_merge=true
2016-04-02 18:10:28 +05:30
```
2014-09-02 18:07:02 +05:30
2016-04-02 18:10:28 +05:30
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-08-17 22:00:37 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
2016-04-02 18:10:28 +05:30
| `branch` | string | yes | The name of the branch |
2016-08-24 12:49:21 +05:30
| `developers_can_push` | boolean | no | Flag if developers can push to the branch |
| `developers_can_merge` | boolean | no | Flag if developers can merge to the branch |
2016-04-02 18:10:28 +05:30
Example response:
2014-09-02 18:07:02 +05:30
```json
{
"commit": {
2015-04-26 12:48:37 +05:30
"author_email": "john@example.com",
"author_name": "John Smith",
"authored_date": "2012-06-27T05:51:39-07:00",
"committed_date": "2012-06-28T03:44:20-07:00",
"committer_email": "john@example.com",
"committer_name": "John Smith",
2014-09-02 18:07:02 +05:30
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
2017-08-17 22:00:37 +05:30
"short_id": "7b5c3cc",
"title": "add projects API",
2014-09-02 18:07:02 +05:30
"message": "add projects API",
2015-04-26 12:48:37 +05:30
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
]
2014-09-02 18:07:02 +05:30
},
2015-04-26 12:48:37 +05:30
"name": "master",
2017-08-17 22:00:37 +05:30
"merged": false,
2016-08-24 12:49:21 +05:30
"protected": true,
"developers_can_push": true,
"developers_can_merge": true
2014-09-02 18:07:02 +05:30
}
```
## Unprotect repository branch
2017-09-10 17:25:29 +05:30
>**Note:** This API endpoint is deprecated in favor of `DELETE /projects/:id/protected_branches/:name`
2016-04-02 18:10:28 +05:30
Unprotects a single project repository branch. This is an idempotent function,
unprotecting an already unprotected repository branch still returns a `200 OK`
status code.
2014-09-02 18:07:02 +05:30
```
PUT /projects/:id/repository/branches/:branch/unprotect
```
2016-04-02 18:10:28 +05:30
```bash
2017-08-17 22:00:37 +05:30
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/5/repository/branches/master/unprotect
2016-04-02 18:10:28 +05:30
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-08-17 22:00:37 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
2016-04-02 18:10:28 +05:30
| `branch` | string | yes | The name of the branch |
2014-09-02 18:07:02 +05:30
2016-04-02 18:10:28 +05:30
Example response:
2014-09-02 18:07:02 +05:30
```json
{
"commit": {
2015-04-26 12:48:37 +05:30
"author_email": "john@example.com",
"author_name": "John Smith",
"authored_date": "2012-06-27T05:51:39-07:00",
"committed_date": "2012-06-28T03:44:20-07:00",
"committer_email": "john@example.com",
"committer_name": "John Smith",
2014-09-02 18:07:02 +05:30
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
2017-08-17 22:00:37 +05:30
"short_id": "7b5c3cc",
"title": "add projects API",
2014-09-02 18:07:02 +05:30
"message": "add projects API",
2015-04-26 12:48:37 +05:30
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
]
2014-09-02 18:07:02 +05:30
},
2015-04-26 12:48:37 +05:30
"name": "master",
2017-08-17 22:00:37 +05:30
"merged": false,
2016-08-24 12:49:21 +05:30
"protected": false,
"developers_can_push": false,
"developers_can_merge": false
2014-09-02 18:07:02 +05:30
}
```
## Create repository branch
```
POST /projects/:id/repository/branches
```
2016-04-02 18:10:28 +05:30
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-08-17 22:00:37 +05:30
| `id` | integer | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
| `branch` | string | yes | The name of the branch |
2016-04-02 18:10:28 +05:30
| `ref` | string | yes | The branch name or commit SHA to create branch from |
```bash
2017-08-17 22:00:37 +05:30
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/5/repository/branches?branch=newbranch&ref=master"
2016-04-02 18:10:28 +05:30
```
2014-09-02 18:07:02 +05:30
2016-04-02 18:10:28 +05:30
Example response:
2014-09-02 18:07:02 +05:30
```json
{
"commit": {
"author_email": "john@example.com",
2015-04-26 12:48:37 +05:30
"author_name": "John Smith",
"authored_date": "2012-06-27T05:51:39-07:00",
"committed_date": "2012-06-28T03:44:20-07:00",
"committer_email": "john@example.com",
"committer_name": "John Smith",
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
2017-08-17 22:00:37 +05:30
"short_id": "7b5c3cc",
"title": "add projects API",
2015-04-26 12:48:37 +05:30
"message": "add projects API",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
]
2014-09-02 18:07:02 +05:30
},
2016-04-02 18:10:28 +05:30
"name": "newbranch",
2017-08-17 22:00:37 +05:30
"merged": false,
2016-08-24 12:49:21 +05:30
"protected": false,
"developers_can_push": false,
"developers_can_merge": false
2014-09-02 18:07:02 +05:30
}
```
## Delete repository branch
```
DELETE /projects/:id/repository/branches/:branch
```
2016-04-02 18:10:28 +05:30
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-08-17 22:00:37 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
2016-04-02 18:10:28 +05:30
| `branch` | string | yes | The name of the branch |
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
In case of an error, an explaining message is provided.
2014-09-02 18:07:02 +05:30
2016-04-02 18:10:28 +05:30
```bash
2017-08-17 22:00:37 +05:30
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/5/repository/branches/newbranch"
2016-04-02 18:10:28 +05:30
```
2015-04-26 12:48:37 +05:30
2017-08-17 22:00:37 +05:30
## Delete merged branches
2015-04-26 12:48:37 +05:30
2017-08-17 22:00:37 +05:30
Will delete all branches that are merged into the project's default branch.
2017-09-10 17:25:29 +05:30
Protected branches will not be deleted as part of this operation.
2017-08-17 22:00:37 +05:30
```
DELETE /projects/:id/repository/merged_branches
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
```bash
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/5/repository/merged_branches"
2015-04-26 12:48:37 +05:30
```