Skip to content

Commit

Permalink
Breaking Change: Update commit ref to commit URI for `lakectl tag…
Browse files Browse the repository at this point in the history
… create` command (#3017)
  • Loading branch information
mishraprafful authored Mar 9, 2022
1 parent 1e09430 commit 0bc0b0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions cmd/lakectl/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,26 @@ var tagListCmd = &cobra.Command{
}

var tagCreateCmd = &cobra.Command{
Use: "create <tag uri> <commit ref>",
Use: "create <tag uri> <commit uri>",
Short: "Create a new tag in a repository",
Example: "lakectl tag create lakefs://example-repo/example-tag 2397cc9a9d04c20a4e5739b42c1dd3d8ba655c0b3a3b974850895a13d8bf9917",
Example: "lakectl tag create lakefs://example-repo/example-tag lakefs://example-repo/2397cc9a9d04c20a4e5739b42c1dd3d8ba655c0b3a3b974850895a13d8bf9917",
Args: cobra.ExactArgs(tagCreateRequiredArgs),
Run: func(cmd *cobra.Command, args []string) {
tagURI := MustParseRefURI("tag", args[0])
tagURI := MustParseRefURI("tag uri", args[0])
commitURI := MustParseRefURI("commit uri", args[1])
Fmt("Tag ref: %s\n", tagURI.String())

client := getClient()
commitRef := args[1]
ctx := cmd.Context()
force, _ := cmd.Flags().GetBool("force")

if tagURI.Repository != commitURI.Repository {
Die("both references must belong to the same repository", 1)
}

if force {
// checking validity of the commitRef before deleting the old one
res, err := client.GetCommitWithResponse(ctx, tagURI.Repository, commitRef)
res, err := client.GetCommitWithResponse(ctx, tagURI.Repository, commitURI.Ref)
DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK)

resp, err := client.DeleteTagWithResponse(ctx, tagURI.Repository, tagURI.Ref)
Expand All @@ -88,7 +93,7 @@ var tagCreateCmd = &cobra.Command{

resp, err := client.CreateTagWithResponse(ctx, tagURI.Repository, api.CreateTagJSONRequestBody{
Id: tagURI.Ref,
Ref: commitRef,
Ref: commitURI.Ref,
})
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusCreated)

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2558,14 +2558,14 @@ Create delete and list tags within a lakeFS repository
Create a new tag in a repository

```
lakectl tag create <tag uri> <commit ref> [flags]
lakectl tag create <tag uri> <commit uri> [flags]
```

#### Examples
{:.no_toc}

```
lakectl tag create lakefs://example-repo/example-tag 2397cc9a9d04c20a4e5739b42c1dd3d8ba655c0b3a3b974850895a13d8bf9917
lakectl tag create lakefs://example-repo/example-tag lakefs://example-repo/2397cc9a9d04c20a4e5739b42c1dd3d8ba655c0b3a3b974850895a13d8bf9917
```

#### Options
Expand Down

0 comments on commit 0bc0b0c

Please sign in to comment.