Skip to content

Commit 814527f

Browse files
authored
Merge pull request #487 from a-kenji/ke-fix-pin-unpin
inputs/pin: skip inputs without URL
2 parents 76bf7c6 + 94e9fd9 commit 814527f

13 files changed

+148
-23
lines changed

src/update.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ impl Updater {
176176
pub fn new(text: Rope, map: InputMap) -> Self {
177177
let mut inputs = vec![];
178178
for (_id, input) in map {
179+
// Skip inputs without a URL (e.g. expanded type/owner/repo/ref format
180+
// or follows-only stubs) — there is no quoted URL value to modify.
181+
if input.url.is_empty() || input.range.start == 0 && input.range.end == 0 {
182+
continue;
183+
}
179184
inputs.push(UpdateInput { input });
180185
}
181186
Self {

src/walk/inputs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub fn insert_with_ctx(
5454
if let Some(node) = inputs.get_mut(&id) {
5555
if !input.url.to_string().is_empty() {
5656
node.url = input.url;
57+
node.range = input.range;
5758
}
5859
if !input.flake {
5960
node.flake = input.flake;
@@ -380,7 +381,7 @@ fn handle_nested_input(
380381
for binding in attr.children() {
381382
if binding.to_string() == "url" {
382383
let url = binding.next_sibling().unwrap();
383-
let input = Input::with_url(id_str.clone(), url.to_string(), input_id.text_range());
384+
let input = Input::with_url(id_str.clone(), url.to_string(), url.text_range());
384385
insert_with_ctx(inputs, id_str.clone(), input, ctx);
385386
}
386387
if should_remove_input(change, ctx, &id_str) {

tests/snapshots/edit__flake_edit_list@completely_flat_toplevel_alt.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ crane:
2020
- rust-overlay
2121
- "\"rust-overlay\""
2222
range:
23-
start: 0
24-
end: 0
23+
start: 466
24+
end: 488
2525
flake-utelinos:
2626
id: flake-utelinos
2727
flake: true
@@ -50,5 +50,5 @@ rust-overlay:
5050
- nixpkgs
5151
- "\"nixpkgs\""
5252
range:
53-
start: 0
54-
end: 0
53+
start: 256
54+
end: 285

tests/snapshots/edit__flake_edit_list@completely_flat_toplevel_not_a_flake_nested.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ not-a-flake:
4444
url: "\"github:a-kenji/not-a-flake\""
4545
follows: []
4646
range:
47-
start: 585
48-
end: 596
47+
start: 611
48+
end: 639
4949
rust-overlay:
5050
id: rust-overlay
5151
flake: true

tests/snapshots/edit__flake_edit_list@one_level_nesting_flat_not_a_flake.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ also-not-a-flake:
1111
url: "\"github:a-kenji/also-not-a-flake\""
1212
follows: []
1313
range:
14-
start: 72
15-
end: 88
14+
start: 131
15+
end: 164
1616
crane:
1717
id: crane
1818
flake: true

tests/snapshots/edit__flake_edit_list@toplevel_nesting.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ crane:
2020
- rust-overlay
2121
- "\"rust-overlay\""
2222
range:
23-
start: 272
24-
end: 277
23+
start: 292
24+
end: 314
2525
nixpkgs:
2626
id: nixpkgs
2727
flake: true
@@ -42,5 +42,5 @@ rust-overlay:
4242
- nixpkgs
4343
- "\"nixpkgs\""
4444
range:
45-
start: 111
46-
end: 123
45+
start: 138
46+
end: 167
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: tests/update.rs
3+
expression: updater.get_changes()
4+
---
5+
{
6+
inputs = {
7+
myInput = {
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
url = "github:foo/bar/abc123";
10+
};
11+
};
12+
13+
outputs = { self, myInput }: { };
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
source: tests/update.rs
3+
expression: updater.get_changes()
4+
---
5+
{
6+
inputs = {
7+
myInput = {
8+
type = "github";
9+
owner = "NixOS";
10+
repo = "nixpkgs";
11+
ref = "nixos-25.11";
12+
};
13+
pinned.url = "github:foo/bar";
14+
};
15+
16+
outputs = { self, myInput, pinned }: { };
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: tests/update.rs
3+
expression: updater.get_changes()
4+
---
5+
{
6+
inputs = {
7+
myInput = {
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
url = "github:foo/bar";
10+
};
11+
};
12+
13+
outputs = { self, myInput }: { };
14+
}

tests/snapshots/walker__walker_list_inputs@completely_flat_toplevel_alt.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ crane:
2020
- rust-overlay
2121
- "\"rust-overlay\""
2222
range:
23-
start: 0
24-
end: 0
23+
start: 466
24+
end: 488
2525
flake-utelinos:
2626
id: flake-utelinos
2727
flake: true
@@ -50,5 +50,5 @@ rust-overlay:
5050
- nixpkgs
5151
- "\"nixpkgs\""
5252
range:
53-
start: 0
54-
end: 0
53+
start: 256
54+
end: 285

0 commit comments

Comments
 (0)