Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<a href="#workflow">Workflow</a> •
<a href="#installation">Installation</a> •
<a href="#usage">Usage</a> •
<a href="#development">Development</a> •
<a href="#contribution">Contribution</a> •
<a href="#roadmap">Roadmap</a><br>
</p>
Expand Down Expand Up @@ -74,6 +75,7 @@ Lists the worktrees that exist under the worktrees directory.
| `Ctrl + N` or `Down Arrow` | Move down in the list |
| `Ctrl + P` or `Up Arrow` | Move up in the list |
| `Ctrl + D` | Switch to `Repositories Mode` |
| `Ctrl + X` | Delete the selected worktree |
| `Enter` | Copy the full path of the selected worktree to the clipboard and exit |

### Repositories Mode
Expand All @@ -94,14 +96,62 @@ Creates new worktree in the selected repository.
| ------------- | ------------- |
| `Enter` | Create new worktree with the provided branch name in the selected repository and switch to `Worktrees Mode` |

# Development

To enable debugging in this project, you need to set the `RUST_LOG` environment variable. The project uses the `tracing` library for logging, and the log level is configured via this environment variable.

### Set the `RUST_LOG` Environment Variable

You can set the `RUST_LOG` environment variable to control the verbosity of the logs. Here are a few examples:

- **To see all `info` level logs (the default):**
```bash
export RUST_LOG=info
```

- **To enable `debug` level logging for all crates:**
```bash
export RUST_LOG=debug
```

- **To enable `debug` level logging only for the `devspace` crate:**
```bash
export RUST_LOG=devspace=debug
```

- **For the most verbose logging, you can use `trace`:**
```bash
export RUST_LOG=trace
```

### Run the Application

After setting the environment variable, run the application as you normally would:

```bash
devspace
```

### View the Logs

The log output is written to a file named `devspace.log`. This file is located in the application's data directory. On Linux, this is typically `~/.local/share/devspace/devspace.log`.

You can view the logs in real-time by using the `tail` command:

```bash
tail -f ~/.local/share/devspace/devspace.log
```

By adjusting the `RUST_LOG` environment variable, you can control the level of detail in the logs, which is very helpful for debugging.

# Contribution

So far there are no specific rules for contributions. Pull requests are very welcome. Feel free to checkout the repo and submit new PRs for fixes or new feature requests.

# Roadmap

- [x] Create new worktrees.
- [ ] Delete worktrees.
- [x] Delete worktrees.
- [ ] Show the status of worktrees (e.g. stale, active ...etc.).
- [ ] Add metadata to worktrees, e.g. JIRA links, PR links ...etc.

Expand Down
23 changes: 18 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,20 @@ impl App {
Focus::Worktrees => {
let result = self.worktrees.handle_key(key);
if result == EventState::Consumed {
result
} else if key.modifiers == KeyModifiers::CONTROL && key.code == KeyCode::Char('d') {
return result;
}

if key.modifiers == KeyModifiers::CONTROL && key.code == KeyCode::Char('d') {
self.focus = Focus::Repositories;
EventState::Consumed
} else {
EventState::NotConsumed
return EventState::Consumed;
}

if key.modifiers == KeyModifiers::CONTROL && key.code == KeyCode::Char('x') {
self.worktrees.delete_selected_worktree();
return EventState::Consumed;
}

EventState::NotConsumed
}
Focus::Repositories => {
let result = self.repositories.handle_key(key);
Expand Down Expand Up @@ -117,3 +124,9 @@ impl App {
area
}
}

impl Default for App {
fn default() -> Self {
Self::new()
}
}
File renamed without changes.
17 changes: 15 additions & 2 deletions src/components/worktrees.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::git;
use arboard::Clipboard;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use ratatui::{
Expand Down Expand Up @@ -112,10 +113,22 @@ impl WorktreesComponent {
self.selected_index = new_worktree_index;
}

pub fn selected_worktree(&mut self) -> Option<&Worktree> {
pub fn delete_selected_worktree(&mut self) {
if let Some(selected_worktree) = self.selected_worktree() {
if let Err(error) = git::delete_worktree(&selected_worktree) {
error!("Could not delete the worktree. Error: {}", error);
} else {
self.worktrees.retain(|w| !w.path().eq(selected_worktree.path()));
self.state.select(None);
self.selected_index = None;
}
}
}

pub fn selected_worktree(&mut self) -> Option<Worktree> {
match self.selected_index {
Some(index) => match self.filtered_items().get(index) {
Some(worktree) => Some(worktree),
Some(worktree) => Some((*worktree).clone()),
None => None,
},
None => None,
Expand Down
Loading