Skip to content

Commit 85c8e21

Browse files
authored
feat: untrack files (#146)
1 parent b0bcb1a commit 85c8e21

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ https://github.com/Cretezy/lazyjj/assets/2672503/b5e6b4f1-ebdb-448f-af9e-361e86f
2222
- See a change's files from the log tab with `Enter`
2323
- View conflicts list in current change
2424
- Toggle between color words and git diff with `w`
25+
- Untrack file with `x`
2526
- Bookmarks
2627
- View list of bookmarks, including from all remotes with `a`
2728
- Create with `c`, rename with `r`, delete with `d`, forget with `f`

src/commander/files.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,30 @@ impl Commander {
159159

160160
self.execute_jj_command(args, true, true).map(Some)
161161
}
162+
163+
#[instrument(level = "trace", skip(self))]
164+
pub fn untrack_file(&self, current_file: &File) -> Result<Option<String>, CommandError> {
165+
let Some(path) = current_file.path.as_ref() else {
166+
return Ok(None);
167+
};
168+
169+
let path = if let Some(DiffType::Renamed) = current_file.diff_type
170+
&& let Some(captures) = RENAME_REGEX.captures(path)
171+
{
172+
match captures.get(2) {
173+
Some(path) => path.as_str(),
174+
None => return Ok(None),
175+
}
176+
} else {
177+
path
178+
};
179+
180+
Ok(Some(self.execute_jj_command(
181+
vec!["file", "untrack", path],
182+
false,
183+
true,
184+
)?))
185+
}
162186
}
163187

164188
#[cfg(test)]

src/ui/files_tab.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::vec;
2+
13
use anyhow::Result;
24
use tracing::instrument;
35

@@ -11,7 +13,7 @@ use crate::{
1113
env::{Config, DiffFormat},
1214
ui::{
1315
Component, ComponentAction, details_panel::DetailsPanel, help_popup::HelpPopup,
14-
utils::tabs_to_spaces,
16+
message_popup::MessagePopup, utils::tabs_to_spaces,
1517
},
1618
};
1719

@@ -143,6 +145,14 @@ impl FilesTab {
143145
Ok(())
144146
}
145147

148+
pub fn untrack_file(&mut self, commander: &mut Commander) -> Result<()> {
149+
self.file
150+
.as_ref()
151+
.map(|current_file| commander.untrack_file(current_file))
152+
.transpose()?;
153+
Ok(())
154+
}
155+
146156
fn scroll_files(&mut self, commander: &mut Commander, scroll: isize) -> Result<()> {
147157
if let Ok(files) = self.files_output.as_ref() {
148158
let current_file_index = self.get_current_file_index();
@@ -318,6 +328,19 @@ impl Component for FilesTab {
318328
self.diff_format = self.diff_format.get_next(self.config.diff_tool());
319329
self.refresh_diff(commander)?;
320330
}
331+
KeyCode::Char('x') => {
332+
// this works even for deleted files because jj doesn't return error in that case
333+
if self.untrack_file(commander).is_err() {
334+
return Ok(ComponentInputResult::HandledAction(
335+
ComponentAction::SetPopup(Some(Box::new(MessagePopup {
336+
title: "Can't untrack file".into(),
337+
messages: "Make sure that file is ignored".into(),
338+
text_align: None,
339+
}))),
340+
));
341+
}
342+
self.set_head(commander, &commander.get_current_head()?)?;
343+
}
321344
KeyCode::Char('R') | KeyCode::F(5) => {
322345
self.head = commander.get_head_latest(&self.head)?;
323346
self.refresh_files(commander)?;
@@ -333,6 +356,7 @@ impl Component for FilesTab {
333356
vec![
334357
("j/k".to_owned(), "scroll down/up".to_owned()),
335358
("J/K".to_owned(), "scroll down by ½ page".to_owned()),
359+
("x".to_owned(), "untrack file".to_owned()),
336360
("@".to_owned(), "view current change files".to_owned()),
337361
],
338362
vec![

0 commit comments

Comments
 (0)