Skip to content

Commit

Permalink
catch when there are no changes in revert (#7308)
Browse files Browse the repository at this point in the history
* catch when there are no changes in revert

* added flag to allow empty reverts

* pr changes
  • Loading branch information
lynnro314 authored Feb 7, 2024
1 parent f545705 commit eab29ed
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 12 deletions.
4 changes: 4 additions & 0 deletions api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ components:
force:
type: boolean
default: false
allow_empty:
type: boolean
default: false
description: allow empty commit (revert without changes)

CherryPickCreation:
type: object
Expand Down
5 changes: 5 additions & 0 deletions clients/java-legacy/api/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/java-legacy/docs/RevertCreation.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions clients/java/api/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/java/docs/RevertCreation.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/python-legacy/docs/BranchesApi.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/python-legacy/docs/RevertCreation.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions clients/python-legacy/lakefs_client/model/revert_creation.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/python/docs/RevertCreation.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions clients/python/lakefs_sdk/models/revert_creation.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion clients/python/test/test_revert_creation.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cmd/lakectl/cmd/branch_revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var branchRevertCmd = &cobra.Command{
fmt.Println("Branch:", u)
hasParentNumber := cmd.Flags().Changed(ParentNumberFlagName)
parentNumber := Must(cmd.Flags().GetInt(ParentNumberFlagName))
allowEmptyRevert := Must(cmd.Flags().GetBool(allowEmptyCommit))
if hasParentNumber && parentNumber <= 0 {
Die("parent number must be number greater than 0, if specified", 1)
}
Expand All @@ -46,6 +47,7 @@ var branchRevertCmd = &cobra.Command{
resp, err := clt.RevertBranchWithResponse(cmd.Context(), u.Repository, u.Ref, apigen.RevertBranchJSONRequestBody{
ParentNumber: parentNumber,
Ref: commitRef,
AllowEmpty: &allowEmptyRevert,
})
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusNoContent)
fmt.Printf("commit %s successfully reverted\n", commitRef)
Expand All @@ -58,6 +60,7 @@ func init() {
AssignAutoConfirmFlag(branchRevertCmd.Flags())

branchRevertCmd.Flags().IntP(ParentNumberFlagName, "m", 0, "the parent number (starting from 1) of the mainline. The revert will reverse the change relative to the specified parent.")
branchRevertCmd.Flags().Bool(allowEmptyCommit, false, "allow empty commit (revert without changes)")

branchCmd.AddCommand(branchRevertCmd)
}
4 changes: 4 additions & 0 deletions docs/assets/js/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ components:
force:
type: boolean
default: false
allow_empty:
type: boolean
default: false
description: allow empty commit (revert without changes)

CherryPickCreation:
type: object
Expand Down
7 changes: 4 additions & 3 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1648,9 +1648,10 @@ lakectl branch revert lakefs://example-repo/example-branch commitA
{:.no_toc}

```
-h, --help help for revert
-m, --parent-number int the parent number (starting from 1) of the mainline. The revert will reverse the change relative to the specified parent.
-y, --yes Automatically say yes to all confirmations
--allow-empty-commit allow empty commit (revert without changes)
-h, --help help for revert
-m, --parent-number int the parent number (starting from 1) of the mainline. The revert will reverse the change relative to the specified parent.
-y, --yes Automatically say yes to all confirmations
```


Expand Down
1 change: 1 addition & 0 deletions pkg/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3301,6 +3301,7 @@ func (c *Controller) RevertBranch(w http.ResponseWriter, r *http.Request, body a
Reference: body.Ref,
Committer: user.Committer(),
ParentNumber: body.ParentNumber,
AllowEmpty: swag.BoolValue(body.AllowEmpty),
}, graveler.WithForce(swag.BoolValue(body.Force)))
if c.handleAPIError(ctx, w, r, err) {
return
Expand Down
6 changes: 4 additions & 2 deletions pkg/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ type RevertParams struct {
Reference string // the commit to revert
ParentNumber int // if reverting a merge commit, the change will be reversed relative to this parent number (1-based).
Committer string
AllowEmpty bool // allow empty commit (revert without changes)
}

type CherryPickParams struct {
Expand Down Expand Up @@ -1638,8 +1639,9 @@ func (c *Catalog) Revert(ctx context.Context, repositoryID string, branch string
branchID := graveler.BranchID(branch)
reference := graveler.Ref(params.Reference)
commitParams := graveler.CommitParams{
Committer: params.Committer,
Message: fmt.Sprintf("Revert %s", params.Reference),
Committer: params.Committer,
Message: fmt.Sprintf("Revert %s", params.Reference),
AllowEmpty: params.AllowEmpty,
}
parentNumber := params.ParentNumber
if err := validator.Validate([]validator.ValidateArg{
Expand Down
Loading

0 comments on commit eab29ed

Please sign in to comment.