Integrity Check When Using Git
Overview
When managing both Next Design project files and YAML files with Git, you need to maintain the consistency of those files.
The following explains how to maintain consistency using the Git command hook mechanism before a Git push.
By using a Git hook (pre-push), you can check that the project and YAML files are consistent by automatically executing yamlexchange. If only one has changed and is inconsistent, you can use the hook to automatically reconcile them.
Flow
-
Pull the latest state.
-
Edit the model in either the YAML file or Next Design and commit. When editing in Next Design, save before committing. You can also manually import or export and commit both.
-
Push. Before pushing, the hook checks and, if only one side has changed, it corrects the other side and stops the push.
-
When the hook corrects the changes, it verifies the result, commits, and pushes again.
What to put in Git
Put the following files in Git:
- Project file (including model and profile files if split)
- YAML file (main file and destination files)
contentsfolder (also required input for import)- Configuration file (
yamlexchange.ndycfg) - Metamodel information file (
nd.metamodel.yaml, used in the hook'svalidate) - Hooks (
.githooksfolder)
Hook behavior
The hook checks the YAML syntax with validate and compares the project and YAML file with diff. If there are no differences, the push will proceed as is.
If there are differences, the hook will behave as follows, depending on what has changed in the commit being pushed:
| Changes | Hook Behavior |
|---|---|
| YAML File Only | Imports the YAML file into the Next Design project (import --complete --prune --write-back) and stops the push. |
| Next Design Project Only | Exports the entire project to a YAML file (export --all) and stops the push. |
| Both (or Neither Changed) | Stops the push without doing anything. Decide which is correct, perform the import or export, commit, and then push again. |
The hook will not commit. The aligned results will remain in the working copy, so check the contents, commit, and push again.
The hook will also stop the push in the following cases:
- There are uncommitted changes in the project or
Yamlfolder (inspection is performed on the working copy) - You are trying to push to a branch other than the current branch (switch to that branch before pushing)
validatefound an error in the YAML syntax, ordiffcould not compare it
Setting up the hook
GitPushHookSample provides a sample Git hook (pre-push).
This sample assumes that there is one Next Design project in one repository.
Please check that the sample content is suitable for your environment and operations, and modify it as needed before using it.
-
Place
pre-pushin the.githooksfolder of your repository. -
Modify the three lines of "Settings" at the beginning of
pre-push(project file,Yamlfolder, and main file) to match your repository and commit the changes. Paths should be relative to the repository root, separated by/. TheYamlfolder specifies the export destination (theYamlfolder in the same folder as the project file) (see Exported File Structure for the main file name). -
Run the following command only once after cloning. The second line specifies the location of yamlexchange used by the hook. This is unnecessary if you have added the folder containing yamlexchange to your PATH environment variable (see How to use yamlexchange > Location of yamlexchange).
git config core.hooksPath .githooks
git config yamlexchange.cli "<full path to yamlexchange.exe>"
The path to the executable file changes when the YamlExchange package is updated. After updating the package, please also update the path included in the Git hook settings.
- Ensure that each user using the hook has the same version of yamlexchange included in the installed YamlExchange package.
- In environments where the metamodel information file is not exported (e.g., when the profile is protected),
validatewill fail, and pushes will stop every time. Please place the metamodel information file according to Restrictions > Export.
Notes on Using Hooks
Things to check before and after importing
-
When a hook imports, it aligns the contents of the YAML file with the contents of the YAML file. Models and references removed from the YAML file will also be removed from the Next Design project. If only a part of the project is in YAML, the parts not written in YAML will not change.
-
Save and close the project in Next Design before pushing.
-
The hook does not check if the project is open in Next Design and will perform the import without warning, overwriting the project.
Things to check when working with multiple people
- Do not have two people edit the same model. Divide the work between one person editing the YAML file and another editing in Next Design.
When there is a conflict and you need to align with the latest version, the id that was written back to the YAML file during your import will not be present in the latest project. Before importing, please change the id back to a value that starts with new-.