[EMF Compare CLI] Documentation of the 'logicalcherry-pick command'
[EMFCompare2.git] / plugins / org.eclipse.emf.compare.doc / src / user / git-commands-involving-models.mediawiki
blob1261b944c13122c0ec9942f96209d019d0530296
1 = Git commands involving models =\r
2 \r
3 When a user wants to compare or merge EMF models from the git command line interface, the operation is doing in a textual way. \r
4 If he wants to compare or merge EMF models the needs in a logical way, he needs to do that in an Eclipse environment similar to the one he used to create these models.\r
5 As such, the environment requires some plugins to be installed but it may also requires some preferences to be set, some perspective to be activated etc..\r
6 Among these plugins, there are the mandatory ones that will be use to do the compare/merge operation: EMF Compare and EGit.\r
7 \r
8 EMF Compare provides additional git commands in order to compare and merge models on the command line. These commands will use an Eclipse as an headless application (no Graphical User Interface) including EMF Compare and Egit to compare models in a logical way. To provisioned such Eclipse environment, the new git commands will call a program using Oomph.\r
9 \r
10 Oomph [https://wiki.eclipse.org/Eclipse_Oomph_Installer Oomph] is a technology that provisions a set of plugins in an Eclipse IDE, clones Git repositories, binds Git repositories to this IDE, checks projects, sets workspace preferences... The configuration is model driven, with files called Oomph setup model files.\r
12 == Add new Git commands in you system ==\r
14 The basics git commands don't allow to compare or merge EMF models in a logical way. Additional git commands must be added to your system. Each git command is a shell script describing its behaviour. So, to add a new git command, a new script has to be developed.\r
15 The new scripts corresponding to the git commands are:\r
16 * git logicalmerge: the "models compatible" version of the git merge command\r
17 * git logicaldiff: the "models compatible" version of the git diff command\r
18 * git logicalmergetool: the "models compatible" version of the git mergtool command\r
19 These scripts must be added on each computer that need to do "models compatible" git operations from command line interface, to enable them.\r
21 You can find the scripts at the following address: [https://hudson.eclipse.org/emfcompare/job/cli-master-nightly/lastSuccessfulBuild/artifact/packaging/org.eclipse.emf.compare.git.pgm.scripts/scripts/ EMF Compare Git Scripts].\r
23 Note that the location of these scripts must be on your PATH environment variable. Also, they must have execution permission.\r
25 These scripts will execute a program named ''emfcompare-git-pgm''. You also have to retrieve this program on your system.\r
26 Once retrieved, you will have to export a variable named EMF_COMPARE_GIT_PGM_PATH with the path of folder containing the program ''emfcompare-git-pgm'' as value.\r
28 You can find the program at the following address: [https://hudson.eclipse.org/emfcompare/job/cli-master-nightly/lastSuccessfulBuild/artifact/packaging/org.eclipse.emf.compare.git.pgm.products/target/products/ EMF Compare Git PGM]. Download the one corresponding to your system.\r
30 == Create a setup file ==\r
32 === Installation ===\r
34 The setup file will allow you to configure the headless application used by your command. To create a setup file you need an Eclipse environment with the Setup Model for EMF Compare's Git commands Wizard plugin installed. \r
35 Add the following p2 repository (update-site) in your update manager (in Eclipse, ''Help Menu > Install New Software...'', ''Add...'' button on the top right corner): \r
36 [https://hudson.eclipse.org/emfcompare/job/cli-master-nightly/lastSuccessfulBuild/artifact/packaging/org.eclipse.emf.compare.git.pgm.update/target/repository/ EMF Compare's Git commands Wizard plugin update-site]\r
38 Then, select the ''EMF Compare Git PGM Wizards > EMF Compare Git PGM Oomph Wizard Feature'' and click on ''Finish''.\r
40 This tool requires Oomph 1.0.0 or later. You may need to add the Oomph update site to the list of the available update sites to be able install and/or update Oomph:\r
41 [http://download.eclipse.org/oomph/updates]\r
43 === Basic usage ===\r
45 To create a new setup model for EMF Compare's git commands, select ''File > New > Other ... > Oomph > Setup Model for EMF Compare's Git commands''. Then click ''Next >''.\r
47 [[Image:./../images/EMF_Compare_GitPGM_NewWizard_01.png|center|Setup Model for EMF Compare's Git commands wizard]]\r
49 The first page of the wizard asks you to select the project that will contain the setup model, and name that setup model. Then click ''Next >''.\r
51 [[Image:./../images/EMF_Compare_GitPGM_NewWizard_02.png|center|Setup Model for EMF Compare's Git commands wizard]]\r
53 The last page of the wizard asks you to set:\r
54 * The model's root object name.\r
55 * The workspace location (absolute or relative to the setup file). If you select the ''Default'' checkbox, a workspace will be created in the temporary folder of your system.\r
56 * The installation location (absolute or relative to the setup file). If you select the ''Default'' checkbox, the Eclipse environment will be created in the temporary folder of your system.\r
57 * The projects to import in the workspace. You have to import in the workspace all project holding [[./../developer/logical-model.html#What_is_a_logical_model_.3F|interconnected models]] in the git command you want to execute. The ''Import All Projects found In Current Repository'' checkbox is selected by default. If you unchecked it, you will have to specify in the setup model which projects you want to import.\r
59 Once all parameters have been set, click ''Finish''.\r
61 [[Image:./../images/EMF_Compare_GitPGM_NewWizard_03.png|center|Setup Model for EMF Compare's Git commands wizard]]\r
63 Once created, you will able to modify the setup model. You can also create a setup model file from scratch if you prefer. This setup model can contains:\r
65 * The path (absolute or relative to the setup file) where the workspace will be created. It corresponds to a ''Variable task'' in the setup model editor. To create a ''Variable task'', right-click on the ''Project element'' (the root element) and then select ''New Child > Variable''. In the Properties View, you have to fill the ''Name'' field with the value "workspace.location" and the ''Value'' field with the path. If you don't provide such ''Variable task'' in your setup model, a workspace will be created in the temporary folder of your system.\r
67 * The path (absolute or relative to the setup file) where the Eclipse environment will be provisioned. To create an ''Variable task'', right-click on the ''Project element'' (the root element) and then select ''New Child > Variable''. In the Properties View, you have to fill the ''Name'' field with the value "installation.location" and the ''Value'' field with the path. If you don't provide such ''Variable task'' in your setup model, the Eclipse environment will be created in the temporary folder of your system.\r
69 * The paths (absolute or relative to the setup file) of the projects involved in the git command to execute. These projects will be imported in the workspace. First, you have to create a ''Projects Import task''. Right-click on the root element and then select ''New Child > Projects Import''. Then, right-click on the newly created ''Projects Import task'' and then select ''New Child > Source Locator''. In the Properties View, you have to fill the ''Root Folder'' field with the path of the project to import. If you don't give any projects, then all projects found in the git repository will be imported in the workspace. In the example below, two projects will be imported: ''/your/project/location'' and ''/another/project/location''. Note that the ''Locate Nested Projects'' allows to import every projects found under the given location."\r
70 [[Image:./../images/EMF_Compare_GitPGM_Edit_01.png|center|Setup Model for EMF Compare's Git commands wizard]]\r
71 * The additional plugins to install in the provisioned Eclipse environment. By default, only EMF Compare and EGit are provisioned in the Eclipse environment because it is the minimum and mandatory set of plugins required to execute the git command. But, you may have to add additionnal set of plugins/features. For example, you might need GMF for merging diagrams, UML2 or any specific metamodel implementation, Papyrus, etc... To do that, you have to create a ''P2 Director task''. Right-click on the root element and then select ''New Child > P2 Director''. Then, right-click on the newly created ''P2 Director task'' and then select ''New Child > Repository'' to add a new repository or ''New Child > Requirement'' to add a new plugin/feature. In the example below, the repository ''http://download.eclipse.org/releases/luna/201406250900'' allows to add ''org.eclipse.uml2.feature.group'' and ''org.eclipse.papyrus.sdk.feature.feature.group'' (UML2 and Papyrus). The repository ''http://download.eclipse.org/modeling/emf/compare/updates/nightly/latest/'' has been added. It allows to add the ''org.eclipse.emf.compare.uml2.feature.group'' and ''org.eclipse.emf.compare.diagram.papyrus.feature.group'' features (EMF compare's extensions to handle UML2 models and Papyrus Diagrams).\r
73 [[Image:./../images/EMF_Compare_GitPGM_Edit_02.png|center|Setup Model for EMF Compare's Git commands wizard]]\r
75 Please visit [http://www.eclipse.org/oomph Oomph website] for more details about Oomph.\r
77 You can find an example of setup model file for EMF compare's Git commands here: [http://git.eclipse.org/c/emfcompare/org.eclipse.emf.compare-cli.git/tree/examples/SetupExamples Setup Example]\r
78 This example contains a workspace location to edit, an installation location to edit, and additional plugins to take into account for the git command to execute. These additional plugins are Papyrus, UML2, GMF, and EMF Compare extensions.\r
80 == Git diff command with models : git logicaldiff ==\r
82 The logicaldiff command is the "models compatible" version of the git diff command. To see a full description of the git diff command, please visit [http://git-scm.com/docs/git-diff].\r
84 The command is specified as below:\r
86 <span style="background:#dcdcdc">\r
87 git logicaldiff <nowiki>[</nowiki>--git-dir ''<path>''<nowiki>]</nowiki> ''<setup>'' ''<commit>'' <nowiki>[</nowiki>''<commit>''<nowiki>]</nowiki> <nowiki>[</nowiki>-- ''<path>''<nowiki>]</nowiki>\r
88 </span>\r
90 To see the changes between a revision and the HEAD revision, you should omit the second commit.\r
92 <span style="background:#dcdcdc">\r
93 git logicaldiff <nowiki>[</nowiki>--git-dir ''<path>''] ''<setup>'' ''<commit>'' <nowiki>[</nowiki>--<nowiki>]</nowiki> <nowiki>[</nowiki>''<path>''...<nowiki>]</nowiki>\r
94 </span>\r
96 In all cases, ''<commit>''  can refers to a branch name or a commit id.\r
97 In all cases, <nowiki>[</nowiki>-- ''<path>''<nowiki>]</nowiki> option allows to filter the diff command only on files that match the <path>.\r
98 In all cases, <nowiki>[</nowiki>--git-dir ''<path>''<nowiki>]</nowiki> option allows to specify a git repository (if the command is not run inside a repository)\r
100 === Others options available ===\r
102 <span style="background:#dcdcdc"> <nowiki>[</nowiki>--show-stack-trace<nowiki>]</nowiki> </span>\r
104 Use this option to display java stack trace in console on error.\r
106 <span style="background:#dcdcdc"> <nowiki>[</nowiki>--help (or -h)<nowiki>]</nowiki> </span>\r
108 Dispays help for this command.\r
110 == Git merge command with models : git logicalmerge ==\r
112 The logicalmerge command is the "models compatible" version of the git merge command. To see a full description of the git merge command, please visit [http://git-scm.com/docs/git-merge].\r
114 The command is specified as below:\r
116 <span style="background:#dcdcdc">\r
117 git logicalmerge <nowiki>[</nowiki>--git-dir ''<path>''<nowiki>]</nowiki> ''<setup>'' ''<commit>''\r
118 </span>\r
120 Assume the following history exists and the current branch is master:\r
122 <span style="background:#dcdcdc">\r
123          A---B---C      topic  \r
124         /                      \r
125    D---E---F---G        master \r
126 </span>\r
128 Then git logicalmerge mySetupModel.setup topic will replay the changes made on the topic branch since it diverged from master (i.e., E) until its current commit (C) on top of master, and record the result in a new commit along with the names of the two parent commits and a log message from the user describing the changes.\r
130 <span style="background:#dcdcdc">\r
131          A---B---C       topic  \r
132         /         \             \r
133    D---E---F---G---H     master \r
134 </span>\r
136 You can also replace the topic branch name by his commit id: \r
138 <span style="background:#dcdcdc">\r
139 git logicalmerge ''mySetupModel.setup'' ''87ad5ff''\r
140 </span>\r
142 In all cases, ''<commit>''  can refers to a branch name or a commit id.\r
143 In all cases, <nowiki>[</nowiki>--git-dir ''<path>''<nowiki>]</nowiki> option allows to specify a git repository (if the command is not run inside a repository)\r
145 === Others options available ===\r
146 <span style="background:#dcdcdc"> <nowiki>[</nowiki>-m message<nowiki>]</nowiki> </span>\r
148 Set the commit message to be used for the merge commit (in case one is created).\r
149                                                 \r
150 <span style="background:#dcdcdc"> <nowiki>[</nowiki>--show-stack-trace<nowiki>]</nowiki> </span>\r
152 Use this option to display java stack trace in console on error.\r
154 <span style="background:#dcdcdc"> <nowiki>[</nowiki>--help (or -h)<nowiki>]</nowiki> </span>\r
156 Dispays help for this command.\r
158 == Git mergetool command with models : git logicalmergetool ==\r
160 The logicalmergetool command is the "models compatible" version of the git mergetool command. To see a full description of the git mergetool command, please visit [http://git-scm.com/docs/git-mergetool].\r
162 Here is the constructions allowed for the git logicalmergetool:\r
164 <span style="background:#dcdcdc">\r
165 git logicalmergetool ''<setup>''\r
166 </span>\r
168 Run logical merge conflict resolution tools to resolve logical merge conflicts. In our case, it will launch an Eclipse platform with all the tools needed to resolve the conflict(s) induced by the merge. To do so, in the Eclipse environment, select the conflicting file(s) and open the contextual menu ''Team > Merge Tool''. Once the conflict has been resolved, add the file to the index (staged area). And then commit.\r
170 == Git cherry-pick with models : git logicalcherry-pick ==\r
172 The ''logicalcherry-pick'' command is the logical version of the git cherry pick command. To see a full description of the git cherry-pick command, please visit [http://git-scm.com/docs/git-cherry-pick].\r
174 The command is specified as below:\r
176 <span style="background:#dcdcdc">\r
177 git logicalcherry-pick ''<setup>'' ''<commit>...''\r
178 </span>\r
180 Assume the following history exists and the current branch is ''master'':<code><pre>\r
181           A---B---C topic\r
182          /\r
183     D---E---F---G master,HEAD</pre></code>\r
185 Then <code>git logicalcherry-pick mySetupModel.setup A B C</code> will pick A,B and C commits on top of the current HEAD (in the order defined by the command).<code><pre>\r
186           A---B---C topic\r
187          /\r
188     D---E---F---G---A---B---C master,HEAD</pre></code>\r
189     \r
190 In all cases, ''<commit>''  can refers to a branch name or a commit id.\r
192 === Conflicts ===\r
193 ==== Resolve a conflict ====\r
195 If cherry-picking a commit introduces a conflict, you will have to choose how to handle it. The first option is to resolve it by using:\r
197 <span style="background:#dcdcdc">\r
198 git logicalmergetool ''<setup>''\r
199 </span>\r
201 It opens an Eclipse platform in which you will be able to merge the differences using the merge tool (see [[#Git mergetool command with models : git logicalmergetool| Git mergetool command with models : git logicalmergetool]]). Once you have resolved all the conflicts, add the related file to the index and close your platform. To do so you can:\r
202 * Use the contextual menu "Team > Add to Index" \r
204 :[[Image:../images/AddToIndexMenu.png]]\r
206 * Drag and drop the files from the "Unstaged changes" area to the "Staged changes" area in the "Git Staging" view . \r
208 :[[Image:../images/StagedChanges.png]]\r
210 By the way, you can notice in the top right corner there is an '''Abort''','''Skip Commit''' and '''Continue''' button. This simply means that there is a interactive rebase in progress. Indeed, in EGit, cherry-picking commits is equivalent to doing an interactive rebase with only pick actions. From now on, you can either choose to continue with in UI mode (that is to say using those buttons) or go back to command line tool by closing the Eclipse platform. This documentation only describes the mechanism of the command line tool.\r
212 ==== Continue ====\r
213 Once you have resolved all the conflicts, please hit:\r
215 <span style="background:#dcdcdc">\r
216 git logicalcherry-pick ''<setup>'' ''<nowiki>[</nowiki>--continue<nowiki>]</nowiki>''\r
217 </span>\r
219 This command will continue an in going cherry-pick. Be careful you have to resolve all conflicts before using this command otherwise you might get the following message:\r
220 <code><pre>fatal: Some files are in conflict:\r
221         project/file.ecore\r
222         project/file2.ecore\r
223 hint: You must edit all merge conflicts and then\r
224 hint: mark them as resolved using git add.</pre></code>\r
226 There is a major diffference with the merge workflow. While cherry-picking you should not commit by yourself the files but only add them to the index. If you do, you might receive the following message when you use the ''--continue'' option.\r
227 <code>\r
228 <pre>\r
229 No changes detected\r
231 If there is nothing left to stage, chances are that something\r
232 else already introduced the same changes; you might want to skip\r
233 this patch using git logicalcherry-pick --quit\r
234 </pre>\r
235 </code>\r
237 You can simply use the ''--quit'' option to continue your cherry-pick operation (see [[#Quit | Quit option]]).\r
238 === Abort ===\r
240 A second solution while encountering a conflict is to abort the whole cherry-pick operation. To do so please hit:\r
242 <span style="background:#dcdcdc">\r
243 git logicalcherry-pick ''<setup>'' ''<nowiki>[</nowiki>--abort<nowiki>]</nowiki>''\r
244 </span>\r
246 It reverts all the commits already cherry-picked to retrieve the state before the cherry-pick command.\r
248 === Quit ===\r
250 The last solution you have while facing a conflict would be to "skip" the current commit and go on with the remaining commits. To do so please hit:\r
252 <span style="background:#dcdcdc">\r
253 git logicalcherry-pick ''<setup>'' ''<nowiki>[</nowiki>--quit<nowiki>]</nowiki>''\r
254 </span>\r
256 The ''--quit'' option is quite different than the ''--quit'' option of the cherry-pick command in CGit. Instead of quitting an in going cherry-pick, it skips the current commit. Indeed, as mentionned above, in EGit a cherry-pick is replaced by a interactive rebase. This is why the ''--quit'' option is more like the ''--skip'' option of an interactive rebase.\r
258 === Others options available ===\r
259 <span style="background:#dcdcdc"> <nowiki>[</nowiki>--git-dir ''<path>''<nowiki>]</nowiki>  </span>\r
261 To specify the .git folder of a repository. This can be use to execute a command outside a git repository.\r
263 <span style="background:#dcdcdc"> <nowiki>[</nowiki>--show-stack-trace<nowiki>]</nowiki> </span>\r
265 Use this option to display java stack trace in console on error.\r
267 <span style="background:#dcdcdc"> <nowiki>[</nowiki>--help (or -h)<nowiki>]</nowiki> </span>\r
269 Dispay help for this command.\r
271 <span style="background:#dcdcdc"> <nowiki>[</nowiki>--debug (or -d)<nowiki>]</nowiki> </span>\r
273 Give the opportinity to connect a remote debugger to the logical cherry-pick application (using port 8123).