-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bb407b8
Showing
25 changed files
with
1,401 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Release | ||
on: [push] | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
env: | ||
VERSION: ${{ github.ref_name }} | ||
steps: | ||
- name: Checkout git repo | ||
uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '21' | ||
|
||
- uses: extractions/setup-just@v1 | ||
|
||
- uses: DeLaGuardo/[email protected] | ||
with: | ||
cli: latest | ||
|
||
- name: Build | ||
run: | | ||
just build | ||
- name: Release | ||
if: ${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }} | ||
env: | ||
CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }} | ||
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }} | ||
run: | | ||
just release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
|
||
.build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"diagnostics.globals": ["vim", "describe", "it", "before_each", "after_each"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
column_width = 120 | ||
line_endings = "Unix" | ||
indent_type = "Spaces" | ||
indent_width = 2 | ||
quote_style = "AutoPreferDouble" | ||
call_parentheses = "Always" | ||
collapse_simple_statement = "Never" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
build: | ||
clojure -T:build build | ||
|
||
release: | ||
clojure -T:build release | ||
|
||
[macos] | ||
prepare-nvim channel: | ||
#!/usr/bin/env sh | ||
set -eo pipefail | ||
NVIM_DIR=".build/nvim/{{ channel }}" | ||
test -d $NVIM_DIR || { | ||
mkdir -p $NVIM_DIR | ||
|
||
curl -L https://github.com/neovim/neovim/releases/download/{{ channel }}/nvim-macos-$(arch).tar.gz > ./.build/nvim-macos.tar.gz | ||
xattr -c ./.build/nvim-macos.tar.gz | ||
tar xzf ./.build/nvim-macos.tar.gz -C $NVIM_DIR --strip-components=1 | ||
rm ./.build/nvim-macos.tar.gz | ||
} | ||
|
||
[linux] | ||
prepare-nvim channel: | ||
#!/usr/bin/env sh | ||
set -eo pipefail | ||
NVIM_DIR=".build/nvim/{{ channel }}" | ||
test -d $NVIM_DIR || { | ||
mkdir -p $NVIM_DIR | ||
|
||
curl -L https://github.com/neovim/neovim/releases/download/{{ channel }}/nvim-linux64.tar.gz > ./.build/nvim-linux64.tar.gz | ||
tar xzf ./.build/nvim-linux64.tar.gz -C $NVIM_DIR --strip-components=1 | ||
rm ./.build/nvim-linux64.tar.gz | ||
} | ||
|
||
prepare-dependencies: | ||
#!/usr/bin/env sh | ||
set -eo pipefail | ||
test -d .build/dependencies || { | ||
mkdir -p ./.build/dependencies | ||
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ./.build/dependencies/plenary.nvim | ||
git clone --depth 1 https://github.com/MunifTanjim/nui.nvim ./.build/dependencies/nui.nvim | ||
} | ||
prepare channel: (prepare-nvim channel) prepare-dependencies | ||
|
||
test channel="stable" file="": (prepare channel) | ||
#!/usr/bin/env sh | ||
NVIM_DIR=".build/nvim/{{ channel }}" | ||
./$NVIM_DIR/bin/nvim --version | ||
./$NVIM_DIR/bin/nvim \ | ||
--headless \ | ||
--noplugin \ | ||
-u tests/config.lua \ | ||
-c "PlenaryBustedDirectory tests/difftool/{{ file }} { minimal_init='tests/config.lua', sequential=true }" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Julien Vincent | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<div align="center"> | ||
<h1>difftool.nvim</h1> | ||
</div> | ||
|
||
<div align="center"> | ||
<p> | ||
A tool for editing diffs in Neovim | ||
</p> | ||
</div> | ||
|
||
--- | ||
|
||
This is a Neovim tool for splitting/editing diffs. It operates over a `left` and `right` directory, producing a diff of | ||
the two which can subsiquently be inspected and modified. The `DiffEditor` allows selecting changes by file, hunk or | ||
individual line to produce a new partial diff. | ||
|
||
This was primarilly built to be used with [jujutsu](https://github.com/martinvonz/jj) as an alternative diff-editor to | ||
it's `:builtin` option, but it's designed generically enough that it can be used for other usecases. | ||
|
||
To use it you need to give it two to three directories: a `left`, a `right`, and optionally and `output` directory. | ||
These directories will then be read in by the diffeditor and used to produce a set of diffs between the two directories. | ||
You will then be presented with the left and right side of each file and can select the lines from each diff hunk you | ||
would like to keep. | ||
|
||
When you are happy with your selection you can accept changes and the diffeditor will modify the `output` directory (or | ||
the `right` directory if no output is provided) to match your selection. | ||
|
||
## Installation | ||
|
||
### Using [folke/lazy.vim](https://github.com/folke/lazy.nvim) | ||
|
||
```lua | ||
{ | ||
"julienvincent/difftool.nvim", | ||
cmd = { "DiffEditor" }, | ||
config = function() | ||
require("difftool").setup() | ||
end, | ||
dependencies = { | ||
{ "MunifTanjim/nui.nvim" } | ||
} | ||
} | ||
``` | ||
|
||
## Configuration | ||
|
||
```lua | ||
local difftool = require("difftool") | ||
difftool.setup({ | ||
keys = { | ||
global = { | ||
quit = { "q" }, | ||
accept = { "<leader><Cr>" }, | ||
}, | ||
|
||
tree = { | ||
expand_node = { "l", "<Right>" }, | ||
collapse_node = { "h", "<Left>" }, | ||
|
||
open_file = { "<Cr>" }, | ||
|
||
toggle_file = { "a" }, | ||
}, | ||
|
||
diff = { | ||
toggle_line = { "a" }, | ||
toggle_hunk = { "A" }, | ||
}, | ||
}, | ||
|
||
icons = { | ||
selected = "", | ||
deselected = "", | ||
}, | ||
|
||
hooks = { | ||
on_tree_mount = function() end, | ||
on_diff_mount = function() end, | ||
} | ||
}) | ||
``` | ||
|
||
## Configuring Jujutsu | ||
|
||
Add the following to your jujutsu `config.toml`: | ||
|
||
```toml | ||
[ui] | ||
diff-editor = ["nvim", "-c", "DiffEditor $left $right $output"] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
local diff = require("difftool.api.diff") | ||
local utils = require("difftool.utils") | ||
local fs = require("difftool.api.fs") | ||
|
||
local M = {} | ||
|
||
local function merge_lists(a, b) | ||
local seen = {} | ||
|
||
local function add_unique(list) | ||
for _, item in ipairs(list) do | ||
if not seen[item] then | ||
seen[item] = true | ||
end | ||
end | ||
end | ||
|
||
add_unique(a) | ||
add_unique(b) | ||
|
||
return utils.get_keys(seen) | ||
end | ||
|
||
function M.load_changeset(left, right) | ||
local left_files = fs.list_files_recursively(left) | ||
local right_files = fs.list_files_recursively(right) | ||
local files = merge_lists(left_files, right_files) | ||
|
||
local changeset = {} | ||
|
||
for _, file in ipairs(files) do | ||
local has_left = utils.included_in_table(left_files, file) | ||
local has_right = utils.included_in_table(right_files, file) | ||
|
||
local type = "modified" | ||
if not has_left then | ||
type = "added" | ||
end | ||
if not has_right then | ||
type = "deleted" | ||
end | ||
|
||
local left_filepath = left .. "/" .. file | ||
local right_filepath = right .. "/" .. file | ||
|
||
changeset[file] = { | ||
type = type, | ||
|
||
left_filepath = left_filepath, | ||
right_filepath = right_filepath, | ||
filepath = file, | ||
|
||
selected = false, | ||
selected_lines = { | ||
left = {}, | ||
right = {}, | ||
}, | ||
hunks = diff.diff_file(left_filepath, right_filepath), | ||
} | ||
end | ||
|
||
return changeset, files | ||
end | ||
|
||
function M.write_changeset(changeset, output_dir) | ||
vim.fn.mkdir(output_dir, "p") | ||
|
||
for _, change in pairs(changeset) do | ||
local any_selected = utils.any_lines_selected(change) | ||
local output_file = output_dir .. "/" .. change.filepath | ||
|
||
if change.type == "deleted" and not change.selected and not any_selected then | ||
-- copy file from left to output | ||
vim.fn.system("cp " .. change.left_filepath .. " " .. output_file) | ||
elseif change.type ~= "deleted" and change.selected then | ||
-- copy file from right to output | ||
vim.fn.system("cp " .. change.right_filepath .. " " .. output_file) | ||
elseif change.type == "deleted" and utils.all_lines_selected(change) then | ||
vim.fn.system("rm " .. output_file) | ||
elseif any_selected then | ||
local left_file_content = fs.read_file_as_lines(change.left_filepath) | ||
local right_file_content = fs.read_file_as_lines(change.right_filepath) | ||
local result = diff.apply_diff(left_file_content, right_file_content, change) | ||
fs.write_file(output_dir .. "/" .. change.filepath, result) | ||
return | ||
else | ||
if change.type == "added" then | ||
vim.fn.system("rm " .. output_file) | ||
else | ||
vim.fn.system("cp " .. change.left_filepath .. " " .. output_file) | ||
end | ||
end | ||
end | ||
end | ||
|
||
return M |
Oops, something went wrong.