External Sync / How to... / Resolving conflicts / Name Space Conflicts / Different Elements With Same UID in Same Namespace

Different elements with the same UID in the same namespace (e.g., Page Store)

Table of contents

This scenario demonstrates how to resolve a conflict that occurs when multiple developers create different types of elements with UIDs within the same namespace in their local versions of the project.

Using an example from the Page Store, we will specifically demonstrate what happens when a folder and page element are created simultaneously with the same UID. In this scenario, one developer creates a folder in the Page Store while another developer creates a page with an identical UID, leading to a UID conflict within the namespace as pages and folders within the Page Store now share a namespace.

During conventional project development – using just one working instance of the project – FirstSprint's internal automatic resolution is normally used for UID conflicts within a namespace (see IDProvider$UidType in the FirstSpirit Access API documentation): If a page template with the UID my_new_element has been created in the Page Store and this UID has already been used for another page template or a folder in the Page Store, the new page is automatically issued with a UID with a numerical suffix, e.g., my_new_element_1).

During distributed development, FirstSpirit’s internal UID conflict resolution function cannot be used as the working instances of the project are synchronized using Git.
In each working instance, one page or one folder with the same UID can be created in the Page Store. When synchronizing the project data between the two project instances, the UID conflict must be resolved outside of FirstSpirit. In this case, the user must decide which element in the Page Store (the one transferred into the repository first or the local version) should be kept.

How the conflict occurs

Developer A

  1. Creating a FirstSpirit element
    Developer A creates a folder with the UID page_new directly in the Page Store root folder.
  2. Exporting changes into the file system
    Developer A uses fs-cli to export the current version of the project into the local file system (Git repository)
    fs-cli -p DevProject -sd "D:\Git\DevProject" export pagestore
  3. Transferring changes to the Git repository
    Developer A transfers the changes to the Git repository
    git commit -a -m "created page_new"
    git push

Developer B

  1. Creating a FirstSpirit element
    Developer B creates a page with the UID page_new directly in the Page Store root folder.
  2. Exporting changes into the file system
    Developer B uses fs-cli to export the current version of the project into the local file system
    fs-cli -p DevProject -sd "D:\Git\DevProject" export pagestore
  3. Transferring changes to the Git repository
    Developer B transfers the changes to the Git repository
    git commit -a -m "created page_new"
    git push

He receives the following log report:

$ git push
To ssh://firstspirit.example/externalsync
! [rejected] myBranch -> ts/sync-test (non-fast-forward)
error: failed to push some refs to 'ssh://fsgit@ssh://test.domain.com/git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

This report warns Developer B that the repository already contains newer data than the local data. In this case, the push cannot be performed until the local working version has been updated with a pull.

Conflict resolution

Update

Updating the working directory against the Git repository
Developer B updates the local working version so that it is in line with the repository:
git pull

When attempting to update the working version, Developer B receives the following messages:

$ git pull
Auto-merging PageStore/page_new/StoreElement.xml
CONFLICT (add/add): Merge conflict in PageStore/page_new/StoreElement.xml
Auto-merging PageStore/page_new/FS_References.txt
CONFLICT (add/add): Merge conflict in PageStore/page_new/FS_References.txt
Auto-merging PageStore/page_new/FS_Info.txt
CONFLICT (add/add): Merge conflict in PageStore/page_new/FS_Info.txt
Auto-merging PageStore/StoreElement.xml
CONFLICT (add/add): Merge conflict in PageStore/StoreElement.xml
Auto-merging PageStore/FS_References.txt
CONFLICT (add/add): Merge conflict in PageStore/FS_References.txt
Automatic merge failed; fix conflicts and then commit the result.
Finished 'git pull -no-edit' with return code 1

Resolving the Git conflict

The resolution of this conflict requires manual intervention as the Git client is unable to decide which page_new element (page or Page Store folder) it should keep. In this case, the two developers must work together to decide how to resolve the conflict.

At this point Developer B decides, for example, to keep the folder created by Developer A. To do this, he performs a check-out using the Git client so that the files in the remote repository are adopted for the conflicting case:

git checkout --theirs *

The affected files in the PageStore/page_new directory with the changes made by Developer B are therefore seen as “to be discarded” for the conflicting case and are overwritten with the data from the remote repository.

Import

Importing out of the file system
After the conflict has been resolved at file system level (Git), Developer B must then import the version from the file system to FirstSpirit
fs-cli -p DevProject -sd "D:\Git\DevProject" import

When attempting to import the data in the local file system into his local project instance, Developer B receives an error message, e.g.:

$ fs-cli -p DevProject -sd "D:\Git\DevProject" import
30.03.2017 13:16:08.958 [ERROR SimpleResult] Import operation not successful
de.espirit.firstspirit.store.access.nexport.exceptions.SyncOperationException: [ExternalSync -
Import] failed: UID conflict: 'x' (de.espirit.firstspirit.store.access.pagestore.PageImpl),
is used by element of different class
(de.espirit.firstspirit.store.access.pagestore.PageFolderImpl)
at de.espirit.firstspirit.store.access.nexport.operations.ImportOperationImpl.perform(ImportOperationImpl.java:117)
at com.espirit.moddev.cli.commands.ImportCommand.call(ImportCommand.java:112)
at com.espirit.moddev.cli.commands.ImportCommand.call(ImportCommand.java:48)
at com.espirit.moddev.cli.Cli.executeCommand(Cli.java:232)
at com.espirit.moddev.cli.Cli.execute(Cli.java:148)
at com.espirit.moddev.cli.Cli.main(Cli.java:105)
Caused by: de.espirit.firstspirit.store.access.feature.ReferenceMismatchException: UID
conflict: 'x' (de.espirit.firstspirit.store.access.pagestore.PageImpl), is used by element of
different class (de.espirit.firstspirit.store.access.pagestore.PageFolderImpl)
at de.espirit.firstspirit.store.access.feature.FeatureUtil.getElement(FeatureUtil.java:235)
at de.espirit.firstspirit.store.access.nexport.AbstractImportContext.getLocalElement(AbstractImportContext.java:68)
at de.espirit.firstspirit.store.access.nexport.importer.ReferencesImporter.fillIdMap(ReferencesImporter.java:122)
at de.espirit.firstspirit.store.access.nexport.importer.ReferencesImporter.sourceInit(ReferencesImporter.java:84)
at de.espirit.firstspirit.store.access.nexport.ExportUtil.initImportElement(ExportUtil.java:1447)
at de.espirit.firstspirit.store.access.nexport.ExportUtil.initImportElement(ExportUtil.java:1466)
at de.espirit.firstspirit.store.access.nexport.ElementFileSystemSync.refresh(ElementFileSystemSync.java:134)
at de.espirit.firstspirit.store.access.nexport.ElementFileSystemSync.getRootImportElements(ElementFileSystemSync.java:168)
at de.espirit.firstspirit.store.access.nexport.operations.ImportOperationImpl.performImport(ImportOperationImpl.java:134)
at de.espirit.firstspirit.store.access.nexport.operations.ImportOperationImpl.perform(ImportOperationImpl.java:115)
... 5 more

This error message occurs because the project instance still contains the page created by Developer B with the UID page_new and cannot be overwritten with the UID page_new by the folder now present in the file system.

Resolving the FirstSpirit conflict

Developer B must now manually resolve this error in the project by manually deleting the page with the UID page_new. He can then import the data again.

Export

Exporting changes into the file system
In the next step, Developer B uses fs-cli to export the current version of the project into the local file system
fs-cli -p DevProject -sd "D:\Git\DevProject" export pagestore

Commit / Push

Transferring changes to the Git repository
Developer B has resolved the conflict and can now transfer the changes to the Git repository
git commit -a -m "created page_new"
git push

Next steps

The conflict is resolved. Neither Developer A nor Developer B has to do anything else at this point; the version of the project on both developers’ FirstSpirit Servers matches the one in the repository.

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.13 | Data privacy