Skip to content

Commit

Permalink
Add merge strategy (#2922)
Browse files Browse the repository at this point in the history
* add merge strategy

* add merge strategy

* generate files

* Adding merge strategies support to merge test

* refactoring merge test running engine to external function

* merge strategies - completing conflict handling

* merge strategy tests

* Adding explanations of conflicts and their resolution to non trivial conflict tests

* Updating description for merge-strategy flag

* Additional test - merge conflict resolved by strategies

* Adding documentation to handleAll function, to explain the new strategyToInclude parameter

* changing 'theirs' and 'ours' to 'source-wins' and 'dest-wins'

* renaming lakectl test functions for easier isolated run

* lakectl tests - parameterizing file name, checksum and commit message

* lakectl test for merge strategies

* fixing merge issues in lakectl test

Co-authored-by: Itai David <itai.david@treeverse.io>
Co-authored-by: itai-david <90712874+itai-david@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 2, 2022
1 parent 4726a32 commit d2db61c
Show file tree
Hide file tree
Showing 37 changed files with 1,297 additions and 512 deletions.
3 changes: 3 additions & 0 deletions api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ components:
type: object
additionalProperties:
type: string
strategy:
description: In case of a merge conflict, this option will force the merge process to automatically favor changes from the dest branch ('dest-wins') or from the source branch('source-wins'). In case no selection is made, the merge process will fail in case of a conflict
type: string

BranchCreation:
type: object
Expand Down
7 changes: 7 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/Merge.md

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

33 changes: 31 additions & 2 deletions clients/java/src/main/java/io/lakefs/clients/api/model/Merge.java

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/docs/Merge.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/docs/RefsApi.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/lakefs_client/model/merge.py

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

8 changes: 7 additions & 1 deletion cmd/lakectl/cmd/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ var mergeCmd = &cobra.Command{
client := getClient()
sourceRef := MustParseRefURI("source ref", args[0])
destinationRef := MustParseRefURI("destination ref", args[1])
strategy := MustString(cmd.Flags().GetString("strategy"))
Fmt("Source: %s\nDestination: %s\n", sourceRef.String(), destinationRef)
if destinationRef.Repository != sourceRef.Repository {
Die("both references must belong to the same repository", 1)
}

resp, err := client.MergeIntoBranchWithResponse(cmd.Context(), destinationRef.Repository, sourceRef.Ref, destinationRef.Ref, api.MergeIntoBranchJSONRequestBody{})
if strategy != "dest-wins" && strategy != "source-wins" && strategy != "" {
Die("Invalid strategy value. Expected \"dest-wins\" or \"source-wins\"", 1)
}

resp, err := client.MergeIntoBranchWithResponse(cmd.Context(), destinationRef.Repository, sourceRef.Ref, destinationRef.Ref, api.MergeIntoBranchJSONRequestBody{Strategy: &strategy})
if resp != nil && resp.JSON409 != nil {
Die("Conflict found.", 1)
}
Expand All @@ -52,4 +57,5 @@ var mergeCmd = &cobra.Command{
//nolint:gochecknoinits
func init() {
rootCmd.AddCommand(mergeCmd)
mergeCmd.Flags().String("strategy", "", "In case of a merge conflict, this option will force the merge process to automatically favor changes from the dest branch (\"dest-wins\") or from the source branch(\"source-wins\"). In case no selection is made, the merge process will fail in case of a conflict")
}
2 changes: 1 addition & 1 deletion cmd/lakefs/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func runImport(cmd *cobra.Command, args []string) (statusCode int) {
if withMerge {
fmt.Printf("Merging import changes into lakefs://%s/%s/\n", repoName, repo.DefaultBranch)
msg := fmt.Sprintf(onboard.CommitMsgTemplate, stats.CommitRef)
commitLog, err := c.Merge(ctx, repoName, onboard.DefaultImportBranchName, repo.DefaultBranch, CommitterName, msg, nil)
commitLog, err := c.Merge(ctx, repoName, onboard.DefaultImportBranchName, repo.DefaultBranch, CommitterName, msg, nil, "")
if err != nil {
fmt.Printf("Merge failed: %s\n", err)
return 1
Expand Down
3 changes: 3 additions & 0 deletions docs/assets/js/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ components:
type: object
additionalProperties:
type: string
strategy:
description: In case of a merge conflict, this option will force the merge process to automatically favor changes from the dest branch ('dest-wins') or from the source branch('source-wins'). In case no selection is made, the merge process will fail in case of a conflict
type: string

BranchCreation:
type: object
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,8 @@ lakectl merge <source ref> <destination ref> [flags]
{:.no_toc}

```
-h, --help help for merge
-h, --help help for merge
--strategy string In case of a merge conflict, this option will force the merge process to automatically favor changes from the dest branch ("dest-wins") or from the source branch("source-wins"). In case no selection is made, the merge process will fail in case of a conflict
```


Expand Down
Binary file added nessie/files/ro_1k
Binary file not shown.
Binary file added nessie/files/ro_1k_other
Binary file not shown.
2 changes: 2 additions & 0 deletions nessie/golden/lakectl_branch_create.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Source ref: lakefs://${REPO}/${SOURCE_BRANCH}
created branch '${DEST_BRANCH}' <COMMIT_ID>
2 changes: 1 addition & 1 deletion nessie/golden/lakectl_commit.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Branch: lakefs://${REPO}/${BRANCH}
Commit for branch "${BRANCH}" completed.

ID: <COMMIT_ID>
Message: nessie_lakectl:TestCommit
Message: ${MESSAGE}
Timestamp: <DATE> <TIME> <TZ>
Parents: <COMMIT_ID>

1 change: 1 addition & 0 deletions nessie/golden/lakectl_fs_ls_1_file.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
object <DATE> <TIME> <TZ> 1.0 kB ${FILE_PATH}
2 changes: 2 additions & 0 deletions nessie/golden/lakectl_fs_ls_2_file.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
object <DATE> <TIME> <TZ> 1.0 kB ${FILE_PATH_1}
object <DATE> <TIME> <TZ> 1.0 kB ${FILE_PATH_2}
7 changes: 0 additions & 7 deletions nessie/golden/lakectl_fs_second_upload.golden

This file was deleted.

8 changes: 4 additions & 4 deletions nessie/golden/lakectl_fs_upload.golden
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Path: upload_file1.txt
Path: ${FILE_PATH}
Modified Time: <DATE> <TIME> <TZ>
Size: 20 bytes
Human Size: 20 B
Size: 1024 bytes
Human Size: 1.0 kB
Physical Address: ${STORAGE}/<OBJECT_KEY>
Checksum: bcd52aa37b0c6151513579d6f21c4414
Checksum: <CHECKSUM>
Content-Type: application/octet-stream
2 changes: 1 addition & 1 deletion nessie/golden/lakectl_log_with_commit.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ID: <COMMIT_ID>
Author: nessie
Date: <DATE> <TIME> <TZ>

nessie_lakectl:TestCommit
${MESSAGE}


ID: <COMMIT_ID>
Expand Down
4 changes: 4 additions & 0 deletions nessie/golden/lakectl_merge_conflict.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Source: lakefs://${REPO}/${SOURCE_BRANCH}
Destination: lakefs://${REPO}/${DEST_BRANCH}
Conflict found.
Error executing command.
3 changes: 3 additions & 0 deletions nessie/golden/lakectl_merge_source_wins.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Source: lakefs://${REPO}/${SOURCE_BRANCH}
Destination: lakefs://${REPO}/${DEST_BRANCH}
Merged "${SOURCE_BRANCH}" into "${DEST_BRANCH}" to get "<COMMIT_ID>".
Loading

0 comments on commit d2db61c

Please sign in to comment.