### Clone Example Repository with Jujutsu
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Clone the example repository and perform a merge using Jujutsu.
```bash
jj git clone https://codeberg.org/mergiraf/example-repo
cd example-repo
jj new main other-branch@origin
jj resolve --tool mergiraf
```
--------------------------------
### Clone Example Repository
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Clone the example repository to test Mergiraf's functionality.
```bash
git clone https://codeberg.org/mergiraf/example-repo
cd example-repo
git merge origin/other-branch
```
--------------------------------
### Install Mergiraf from Source using Cargo
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/installation.md
Use this command to install Mergiraf directly from its source repository if you have Rust and Cargo installed.
```bash
cargo install --path .
```
--------------------------------
### Install Mergiraf using cargo-binstall
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/installation.md
Install pre-compiled Mergiraf binaries using the cargo-binstall tool. This assumes cargo-binstall is already set up.
```bash
cargo binstall mergiraf
```
--------------------------------
### Set up development environment with direnv and nix
Source: https://github.com/mergiraf/mergiraf/blob/main/CONTRIBUTING.md
Copy the example environment configuration file and allow direnv to set up the development shell with necessary tooling.
```bash
cp .envrc.example .envrc && direnv allow
```
--------------------------------
### Python Bookmaker Initialization and Compilation
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/injections/Base.md
Use this snippet to start a new project and compile it using the Bookmaker library in Python. Ensure the 'bookmaker' library is installed.
```python
from bookmaker import front_page, compile
def main():
compile()
```
--------------------------------
### Compact Conflict Presentation Example
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
An example of Mergiraf's compact conflict presentation, highlighting only the differing sections.
```diff
>>>>>> origin/main
>
```
--------------------------------
### Initial JSON Object
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/move_elements_between_code_blocks/Base.md
An example of a JSON object with three key-value pairs.
```json
{
"foo": 1,
"bar": 2,
"baz": 3
}
```
--------------------------------
### Run a single test case
Source: https://github.com/mergiraf/mergiraf/blob/main/CONTRIBUTING.md
Execute Mergiraf on a specific test case located in the examples directory to inspect its behavior and logs.
```bash
helpers/inspect.sh examples/java/working/add_same_import
```
--------------------------------
### Install Mergiraf from Crates.io using Cargo
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/installation.md
Install the latest stable version of Mergiraf from crates.io using Cargo. Ensure your Cargo.lock is up-to-date.
```bash
cargo install --locked mergiraf
```
--------------------------------
### Derive a minimal test case for panics
Source: https://github.com/mergiraf/mergiraf/blob/main/CONTRIBUTING.md
Generate a minimal example that reproduces a panic scenario by specifying the merge command and the expected exit code.
```bash
cargo minimize --expected-exit-code 134 /tmp/my_test_case/ "mergiraf merge $1/Base.xml $1/Left.xml $1/Right.xml"
```
--------------------------------
### Python Bookmaker Initialization and Compilation
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/injections/Right.md
Use this snippet to start a new project or compile an existing one with debugging enabled in Python.
```python
from bookmaker import front_page, compile
def main():
compile(debug=True)
```
--------------------------------
### Java Bookmaker Compilation
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/injections/Left.md
Basic Java example to add a Table of Contents and compile a book using the Bookmaker library.
```java
Bookmaker bm = new Bookmaker();
bookmaker.addTOC(new TableOfContents());
bookmaker.compile();
```
--------------------------------
### Python Bookmaker Compilation
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/injections/Left.md
Basic Python example to compile a book using the Bookmaker library. Requires importing necessary functions.
```python
from bookmaker import front_page, compile, table_of_contents
def main():
compile(toc=table_of_contents)
```
--------------------------------
### Example PCS Triples for a Rust Tree
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/architecture.md
Illustrates the conversion of a tree structure into a set of Parent-Child-Successor (PCS) triples. Each triple represents parent-child relationships and the order of children.
```text
(⊥, ⊣, source_file)
(⊥, source_file, ⊢)
(source_file, ⊣, struct_item)
(source_file, struct_item, ⊢)
(struct_item, ⊣, "struct")
(struct_item, "struct", "MyStruct")
(struct_item, "MyStruct", field_declaration_list)
(struct_item, field_declaration_list, ⊢)
(field_declaration_list, ⊣, "{")
(field_declaration_list, "{", field_declaration)
(field_declaration_list, field_declaration, "}")
(field_declaration_list, "}", ⊢)
(field_declaration, ⊣, "first")
(field_declaration, "first", ":")
(field_declaration, ":", "usize")
(field_declaration, "usize", ⊢)
```
--------------------------------
### Configure Language Injections
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/advanced-configuration.md
Specify tree-sitter queries to locate and handle text fragments in other languages within a host language. This example shows how to wire up the `INJECTIONS_QUERY` constant from a Rust crate.
```rust
injections: Some(tree_sitter_html::INJECTIONS_QUERY)
```
--------------------------------
### Compile Project with Table of Contents (Python)
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/injections/Expected.md
Use this snippet to compile a project with a table of contents in Python. Ensure the 'bookmaker' library is installed.
```python
from bookmaker import front_page, compile, table_of_contents
def main():
compile(toc=table_of_contents, debug=True)
```
--------------------------------
### Rust: Reformatting and Content Changes
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/conflicts.md
Demonstrates Mergiraf's attempt to preserve both new formatting and content when one side reformats a file and the other modifies its contents. This example involves a function declaration reformat on the left and an argument type change on the right.
```rust
fn foo(x: i32) -> i32 {
x + 1
}
```
```rust
fn foo(x: i32) -> i32 {
x + 1
}
```
```rust
fn foo(x: String) -> i32 {
x.len() as i32 + 1
}
```
```rust
fn foo(x: String) -> i32 {
x.len() as i32 + 1
}
```
--------------------------------
### Example of Commutative Merging in C#
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/enabling-commutative-merging.md
Illustrates how Mergiraf resolves conflicts for C# `using` statements when the `compilation_unit` is defined as a commutative parent. All unique `using` statements from left, base, and right versions are included in the merged result.
```csharp
using System;
using System.Collections.Generic;
```
```csharp
using System;
```
```csharp
using System;
using System.IO;
```
--------------------------------
### Debugging a Specific Test Case in Rust
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/testing.md
An example Rust integration test function that can be modified to debug a specific test case by changing the provided directory path. Useful with IDE breakpoints.
```rust
// use this test to debug a specific test case by changing the path in it.
#[test]
fn debug_test() {
run_test_from_dir(Path::new("examples/go/working/remove_and_add_imports"))
}
```
--------------------------------
### Define Children Groups with Custom Separators
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/enabling-commutative-merging.md
Configure a commutative parent with children groups and specify custom separators for each group. This example sets a single newline separator for `using_directive` nodes, while other groups use the default.
```rust
CommutativeParent::new("declaration_list", "{", "\n\n", "}")
.restricted_to(vec![
ChildrenGroup::with_separator(&["using_directive"], "\n"),
ChildrenGroup::new(&["namespace_declaration"]),
ChildrenGroup::new(&["global_attribute"]),
]),
```
--------------------------------
### Define Commutative Parent without Delimiters
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/enabling-commutative-merging.md
Define a commutative parent node type in the language profile. This example specifies a `compilation_unit` node with a newline as the separator and no surrounding delimiters.
```rust
LangProfile {
commutative_parents: vec![
CommutativeParent::without_delimiters("compilation_unit", "\n"),
],
..
},
```
--------------------------------
### Define Commutative Parent with Delimiters
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/enabling-commutative-merging.md
Define a commutative parent node type with specified delimiters and a separator. This example defines an `object` node, enclosed in curly braces `{}` with a comma and space `", "` as the separator between children.
```rust
CommutativeParent::new("object", "{", ", ", "}")
```
--------------------------------
### Rust: Moving and Editing Elements
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/conflicts.md
Illustrates Mergiraf's capability to detect when a code section is moved in one revision and modified in another, replaying the modifications at the new location. This example involves extracting a boolean condition into a method and modifying it.
```rust
struct Foo;
impl Foo {
fn is_red(&self) -> bool {
true
}
fn bar(&self) {
if self.is_red() {
println!("Red");
}
}
}
fn main() {
let foo = Foo;
foo.bar();
}
```
```rust
struct Foo;
impl Foo {
fn is_red(&self) -> bool {
true
}
fn bar(&self) {
if self.is_red() {
println!("Red");
}
}
}
fn main() {
let foo = Foo;
foo.bar();
}
```
```rust
struct Foo;
impl Foo {
fn is_blue(&self) -> bool {
true
}
fn bar(&self) {
if self.is_blue() {
println!("Blue");
}
}
}
fn main() {
let foo = Foo;
foo.bar();
}
```
```rust
struct Foo;
impl Foo {
fn is_blue(&self) -> bool {
true
}
fn bar(&self) {
if self.is_blue() {
println!("Blue");
}
}
}
fn main() {
let foo = Foo;
foo.bar();
}
```
--------------------------------
### Restrict Children Groups for Commutative Parent
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/enabling-commutative-merging.md
Define a commutative parent and restrict which children groups can commute together. This example shows how to ensure that `using_directive` nodes can only reorder with other `using_directive` nodes.
```rust
CommutativeParent::new("declaration_list", "{", "\n\n", "}")
.restricted_to_groups(&[
&["using_directive"]
])
```
--------------------------------
### Define Commutative Parent for Declaration Lists
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/enabling-commutative-merging.md
Define a commutative parent for `declaration_list` nodes within a class body. This example uses curly braces `{}` as delimiters and double newlines `\n\n` as the separator, allowing reordering of declarations.
```rust
CommutativeParent::new("declaration_list", "{", "\n\n", "}")
```
--------------------------------
### C# Sample File with Using Directives
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/enabling-commutative-merging.md
This C# code snippet demonstrates a typical file structure including multiple 'using' directives, a namespace, and a class. It serves as a sample for analyzing syntax tree parsing.
```csharp
using System;
using System.Collections.Generic;
using System.IO;
namespace HelloWorld {
public class SomeName {
}
}
```
--------------------------------
### Directory Structure for Full File Name Languages (pyproject.toml)
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/testing.md
Demonstrates the directory structure for testing languages defined by their full file name, such as 'pyproject.toml'. Requires a 'language' file with the specified name.
```text
Base.toml
Left.toml
Right.toml
Expected.toml
language // contains "pyproject.toml"
```
--------------------------------
### Generate Supported Extensions for Gitattributes
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Run this command to generate a list of supported file extensions for your .gitattributes file.
```bash
mergiraf languages --gitattributes
```
--------------------------------
### Directory Structure for Language Tests
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/testing.md
Illustrates the standard directory structure for creating end-to-end test cases for a new language configuration. Files should match the language's extension.
```text
examples/csharp/working/add_imports
```
```text
Base.cs
Left.cs
Right.cs
Expected.cs
```
--------------------------------
### Running an Individual Test Case
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/testing.md
Command to execute a single end-to-end test case for a language configuration. This helper script shows differences between expected and actual merge outputs.
```console
$ helpers/inspect.sh examples/csharp/working/add_imports
```
--------------------------------
### Configure Flattened Nodes
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/advanced-configuration.md
Flatten specific binary operators to prevent nested structures from hindering commutative merging. This example flattens 'union_type'.
```yaml
flattened_nodes:
- "union_type"
```
--------------------------------
### Directory Structure for Full File Name Languages (Makefile)
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/testing.md
Shows the directory structure for testing languages defined by their full file name, like 'Makefile'. Includes a 'language' file specifying the exact file name.
```text
Base
Left
Right
Expected
language // contains "Makefile" (without the quotes)
```
--------------------------------
### Compile Mergiraf
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language.md
Build your new version of Mergiraf using Cargo to generate the executable binary that includes support for the newly added language.
```bash
$ cargo build
```
--------------------------------
### Run a set of test cases
Source: https://github.com/mergiraf/mergiraf/blob/main/CONTRIBUTING.md
Execute Mergiraf on a collection of test cases defined within a specified directory.
```bash
helpers/suite.sh my_test_suite
```
--------------------------------
### Enable Mergiraf for All Files (Gitattributes)
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Add this line to your global gitattributes file to enable Mergiraf for all files.
```gitattributes
* merge=mergiraf
```
--------------------------------
### Inspect Mergiraf Merge Tool Configuration
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
View the current Jujutsu configuration for merge tools, specifically filtering for 'mergiraf', to understand how it's set up by default.
```bash
jj config list --include-defaults merge-tools | grep mergiraf
```
--------------------------------
### Register Mergiraf as Git Merge Driver (CLI)
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Use these commands to globally register Mergiraf as a Git merge driver.
```bash
git config --global merge.mergiraf.name mergiraf
git config --global merge.mergiraf.driver 'mergiraf merge --git %O %A %B -s %S -x %X -y %Y -p %P -l %L'
```
--------------------------------
### Initial JSON Object
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/move_elements_between_code_blocks/Left.md
An initial JSON object with three key-value pairs.
```json
{
"foo": 1,
"bar": 222,
"baz": 3
}
```
--------------------------------
### Create Language Profile
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language.md
Define a new language profile in `src/supported_langs.rs` to configure Mergiraf's support for the language. This includes setting names, file extensions, and the tree-sitter parser.
```rust
LangProfile {
name: "C#", // used for the --language CLI option, and generating the list of supported languages
alternate_names: &[], // other possible values for --language
extensions: &["cs"], // all file extensions for this language (note the lack of `.`!)
file_names: &[], // the full file names which should be handled with this language
language: tree_sitter_c_sharp::LANGUAGE.into(), // the tree-sitter parser
// optional settings, explained below
commutative_parents: vec![],
signatures: vec![],
atomic_nodes: &[],
injections: None,
flattened_nodes: &[],
extra_comment_nodes: &[],
allow_parse_errors: false,
}
```
--------------------------------
### Java Bookmaker Initialization and Compilation
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/injections/Base.md
This Java code demonstrates how to initialize the Bookmaker object and compile a project. Ensure the Bookmaker library is correctly included in your project dependencies.
```java
Bookmaker bm = new Bookmaker();
bookmaker.compile()
```
--------------------------------
### Enable diff3 Conflict Style (CLI)
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Use this command to globally configure Git to use the diff3 merge conflict style.
```bash
git config --global merge.conflictStyle diff3
```
--------------------------------
### Enable Mergiraf for Specific Languages (Gitattributes)
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Add these lines to your gitattributes file to enable Mergiraf for specific file types.
```gitattributes
*.py merge=mergiraf
*.java merge=mergiraf
```
--------------------------------
### C# Syntax Tree Representation
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/enabling-commutative-merging.md
This is a visual representation of the syntax tree for the provided C# sample file. It highlights the 'using_directive' nodes, which are candidates for commutative parent declaration.
```text
└compilation_unit
├using_directive
│ ├using
│ ├identifier System
│ └;
├using_directive
│ ├using
│ ├qualified_name
│ │ ├qualifier: qualified_name
│ │ │ ├qualifier: identifier System
│ │ │ ├.
│ │ │ └name: identifier Collections
│ │ ├.
│ │ └name: identifier Generic
│ └;
├using_directive
│ ├using
│ ├qualified_name
│ │ ├qualifier: identifier System
│ │ ├.
│ │ └name: identifier IO
│ └;
└namespace_declaration
├namespace
├name: identifier HelloWorld
└body: declaration_list
├{
├class_declaration
│ ├modifier
│ │ └public
│ ├class
│ ├name: identifier SomeName
│ └body: declaration_list
│ ├{
│ └}
└}
```
--------------------------------
### Compact Conflict Presentation
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Enable a more compact presentation of merge conflicts using the `--compact` option. This highlights only mismatching parts, potentially requiring reformatting.
```console
$ mergiraf merge -c
```
--------------------------------
### Register Mergiraf as Git Merge Driver (INI)
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Add this section to your ~/.config/git/config file to register Mergiraf as a merge driver.
```ini
[merge "mergiraf"]
name = mergiraf
driver = mergiraf merge --git %O %A %B -s %S -x %X -y %Y -p %P -l %L
```
--------------------------------
### Initial JSON Object
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/move_elements_between_code_blocks/Right.md
Represents the first state of a JSON object with specific key-value pairs.
```json
{
"foo": 1,
"baz": 3
}
```
--------------------------------
### Java Bookmaker Initialization and Compilation
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/injections/Right.md
This Java snippet shows how to initialize the Bookmaker object and compile a project with debugging enabled.
```java
Bookmaker bm = new Bookmaker();
bookmaker.compile(true);
```
--------------------------------
### Configure Git to use Mergiraf
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/introduction.md
Set up Git to use Mergiraf for merge operations, enhancing commands like `git merge`, `revert`, `rebase`, and `cherry-pick`.
```shell
git config --global merge.driver "mergiraf merge %O %A %B"
```
--------------------------------
### Compile Project with Table of Contents (Java)
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/injections/Expected.md
Use this snippet to compile a project with a table of contents in Java. Ensure the Bookmaker library is included in your project dependencies.
```java
Bookmaker bm = new Bookmaker();
bookmaker.addTOC(new TableOfContents());
bookmaker.compile(true);
```
--------------------------------
### Specify Language with gitattributes
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Associate a specific language with file paths using an .gitattributes file. This is an alternative to the command-line `--language` option.
```gitattributes
*.myjs linguist-language=javascript
*.myjs mergiraf.language=javascript
```
--------------------------------
### Inspect Mergiraf's parse tree
Source: https://github.com/mergiraf/mergiraf/blob/main/CONTRIBUTING.md
Use the 'cargo parse' command to examine how Mergiraf parses a given Java file.
```bash
cargo parse my_file.java
```
--------------------------------
### Inspect Resolved Conflict
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
After running `mergiraf solve`, inspect the modified file to verify the conflict resolution.
```yaml
restaurant:
tasks:
plates: 1
bowls: 4
```
--------------------------------
### Parsing C# Code with Cargo
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/enabling-commutative-merging.md
Use this command to parse a C# file and inspect its syntax tree structure. This helps in identifying nodes like 'using_directive' which can be declared as commutative parents.
```bash
$ cargo parse test_file.cs
```
--------------------------------
### Enable diff3 Conflict Style (INI)
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Add this section to your ~/.gitconfig file to enable the diff3 merge conflict style.
```ini
[merge]
conflictStyle = "diff3"
```
--------------------------------
### Report a Bad Merge with File Path
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Generate a bug report archive for a merge that resulted in conflicts. Provide the path to the conflicted file.
```console
$ mergiraf report src/lib/geolocation.cpp
```
--------------------------------
### Ordered Statement Additions in Java
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/conflicts.md
Illustrates a conflict requiring manual resolution due to differing insertions of statements within a Java block, where order is significant.
```java
{{#include ../../examples/java/working/statements/Left.java}}
```
```java
{{#include ../../examples/java/working/statements/Base.java}}
```
```java
{{#include ../../examples/java/working/statements/Right.java}}
```
--------------------------------
### Default Conflict Presentation
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Mergiraf's default conflict alignment to line boundaries for easier resolution in merge tools.
```diff
<<<<<<< HEAD
||||||| 15b798c
=======
>>>>>>> origin/main
```
--------------------------------
### Add Tree-sitter Parser Dependency
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language.md
Add the tree-sitter parser crate for the desired language to your Cargo.toml file. Ensure the parser version is compatible with Mergiraf's tree-sitter version.
```toml
[dependencies]
tree-sitter-csharp = "0.21.3"
```
--------------------------------
### Define Signatures for Node Types
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/enabling-commutative-merging.md
Define signatures for `using_directive`, `field_declaration`, and `method_declaration` nodes. The `using_directive` signature uses an empty path, `field_declaration` uses the 'name' field, and `method_declaration` uses both 'name' and parameter types.
```rust
signature("using_directive", vec![vec![]]),
signature("field_declaration", vec![vec![Field("name")]])
signature("method_declaration", vec![
vec![Field("name")],
vec![Field("parameters"), ChildType("parameter"), Field("type")]
]),
```
--------------------------------
### Commutative HTML Tag Attribute Order
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/conflicts.md
Demonstrates automatic resolution of differing attribute additions to an HTML input tag, leveraging the commutative nature of attribute order.
```xml
```
```xml
```
```xml
```
```xml
```
--------------------------------
### JSON: Line-based Merge Conflict with Duplicate Keys
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/conflicts.md
Highlights an exception to clean line-based merges where Git might produce a result with duplicate keys. Mergiraf detects this and outputs a conflict, demonstrating its signature mechanism for commutative parents.
```json
{
"new_letter": "left value",
"alpha": "α",
"beta": "β",
"gamma": "γ",
"delta": "δ"
}
```
```json
{
"new_letter": "right value",
"alpha": "α",
"beta": "β",
"gamma": "γ",
"delta": "δ"
}
```
```json
{
"new_letter": "left value",
"alpha": "α",
"beta": "β",
"gamma": "γ",
"delta": "δ"
}
```
```json
{
"new_letter": "right value",
"alpha": "α",
"beta": "β",
"gamma": "γ",
"delta": "δ"
}
```
--------------------------------
### Rust Code for Applying Patch to Wheel Inner Tube
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/architecture.md
This Rust code snippet demonstrates a sequence of operations for repairing a wheel's inner tube, including dismounting the tire, applying glue, waiting, and applying a patch. It's part of a larger process likely related to a merge or repair simulation.
```rust
dismountTire(&wheel);
applyGlueAroundPuncture(&wheel.innerTube);
wait(Duration::minutes(5)); // better wait a bit longer
applyPatch(&wheel.innerTube);
```
```rust
dismountTire(&wheel);
applyGlueAroundPuncture(&wheel.innerTube);
wait(Duration::minutes(2));
```
```rust
dismountTire(&wheel);
wheel.innerTube = InnerTube::new(); // otherwise I'll be late to pick up the kids
```
--------------------------------
### Final JSON Object
Source: https://github.com/mergiraf/mergiraf/blob/main/examples/markdown/working/move_elements_between_code_blocks/Base.md
A subsequent JSON object with different key-value pairs.
```json
{
"other": "a",
"final": "z"
}
```
--------------------------------
### Configure Extra Comment Nodes
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/advanced-configuration.md
Extend the heuristic for attaching comment nodes to also include custom node types that behave as comments but are not marked as 'extra' in the grammar.
```yaml
extra_comment_nodes:
- "custom_comment_type"
```
--------------------------------
### Attempt Automatic Conflict Resolution
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Use `mergiraf solve` to automatically attempt to resolve merge conflicts in a specified file after a manual merge fails.
```console
$ git merge origin/main
Auto-merging config.yml
CONFLICT (content): Merge conflict in config.yml
Automatic merge failed; fix conflicts and then commit the result.
$ cat config.yml
<<<<<<< HEAD
restaurant:
tasks:
plates: 1
bowls: 2
||||||| 15b798c
tasks:
plates: 1
bowls: 2
=======
tasks:
plates: 1
bowls: 4
>>>>>>> origin/main
$ mergiraf solve config.yml
Solved 1 conflict(s)
```
--------------------------------
### Manually invoke Mergiraf after conflicts
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/introduction.md
An alternative approach is to let Git handle merges and invoke Mergiraf only when conflicts are encountered.
```shell
git mergiraf merge %O %A %B
```
--------------------------------
### Resolve All Merge Conflicts with Mergiraf
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Use this command to resolve all merge conflicts in your working copy at once using Mergiraf as the conflict resolution tool.
```bash
jj resolve --tool mergiraf
```
--------------------------------
### Independent Syntax Element Changes
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/conflicts.md
Demonstrates automatic resolution of independent changes to a C function's argument type and return type.
```c
void notify_attendees(long status_code);
```
```c
void notify_attendees(int status_code);
```
```c
int notify_attendees(int status_code);
```
```c
int notify_attendees(long status_code);
```
--------------------------------
### Enable Merging with Syntax Errors via gitattributes
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Control whether Mergiraf attempts syntax-aware merging even if files contain syntax errors. This can be enabled or disabled using the `mergiraf.allow-parse-errors` attribute in .gitattributes.
```gitattributes
# enable the option
*.c mergiraf.allow-parse-errors
# disable the option
*.c -mergiraf.allow-parse-errors
```
--------------------------------
### Commutative Class Field Additions in Java
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/conflicts.md
Shows automatic resolution of differing attribute additions to a Java class where declaration order does not matter.
```java
{{#include ../../examples/java/working/class_fields/Left.java}}
```
```java
{{#include ../../examples/java/working/class_fields/Base.java}}
```
```java
{{#include ../../examples/java/working/class_fields/Right.java}}
```
```java
{{#include ../../examples/java/working/class_fields/Expected.java}}
```
--------------------------------
### Configure Atomic Nodes
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/advanced-configuration.md
Treat specific node types as atomic to ignore further structure. Useful for working around parser limitations.
```yaml
atomic_nodes:
- "type1"
- "type2"
```
--------------------------------
### Resolve a Single File Conflict with Mergiraf
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/usage.md
Use this command to resolve a specific file's merge conflicts by providing its path. Mergiraf will be used as the conflict resolution tool.
```bash
jj resolve --tool mergiraf
```
--------------------------------
### Define Commutative Parent from Tree-sitter Query
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/adding-a-language/enabling-commutative-merging.md
Use this snippet to define a commutative parent based on a tree-sitter query. The query selects specific nodes, and the `@commutative` capture group identifies which part of the match should be treated as commutative. This is useful for contexts like Python's `__all__` declarations where lists are contextually commutative.
```rust
CommutativeParent::from_query(
r#"(expression_statement (assignment
left: (identifier) @variable (#eq? @variable "__all__")
right: (list) @commutative)
)"#,
"[", ", ", "]",
)
```
--------------------------------
### JSON: Mergiraf Conflict Output for Duplicate Keys
Source: https://github.com/mergiraf/mergiraf/blob/main/doc/src/conflicts.md
The resulting merge output from Mergiraf when a line-based merge would create duplicate keys in JSON. This showcases Mergiraf's conflict resolution for commutative elements using signatures.
```json
{
"alpha": "α",
"beta": "β",
"gamma": "γ",
"delta": "δ",
"new_letter": [
"left value",
"right value"
]
}
```