altsem / altsem/gitu

Panic when filename of staged file contains non-ASCII character

Open
#384 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.9k
Forks
164
PR merge metrics
No merged PRs in 30d

Description

Description

In some situations with non-ASCII file names, gitu panics.

Reproduction

  1. Check out master branch (tested with commit 5dbf6ed).
  2. Run the following shell commands
touch 'bläh'
git add 'bläh'
RUST_BACKTRACE=1 cargo -q run 2>err; echo "exit code: $?; error:"; cat err

The following panic backtrace is printed:

exit code: 101; error:

thread 'main' panicked at src/git/mod.rs:156:64:
called `Result::unwrap()` on an `Err` value: Expected "<diff header path prefix (' a/...' or ' b/...')>" at byte 11
stack backtrace:
   0: rust_begin_unwind
             at /rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library/std/src/panicking.rs:692:5
   1: core::panicking::panic_fmt
             at /rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library/core/src/panicking.rs:75:14
   2: core::result::unwrap_failed
             at /rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library/core/src/result.rs:1704:5
   3: core::result::Result<T,E>::unwrap
             at ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:1109:23
   4: gitu::git::diff_staged
             at ./src/git/mod.rs:156:21
   5: gitu::screen::status::create::{{closure}}
             at ./src/screen/status.rs:94:26
   6: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:2007:9
   7: gitu::screen::Screen::update
             at ./src/screen/mod.rs:208:22
   8: gitu::screen::Screen::new
             at ./src/screen/mod.rs:58:9
   9: gitu::screen::status::create
             at ./src/screen/status.rs:18:5
  10: gitu::state::State::create
             at ./src/state.rs:76:26
  11: gitu::run
             at ./src/lib.rs:83:21
  12: gitu::main
             at ./src/main.rs:34:5
  13: core::ops::function::FnOnce::call_once
             at ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/git/mod.rs at diff_staged and reproduce the panic with the shell commands in the issue. Trace how src/screen/status.rs calls it and inspect the staged-diff parsing path. Done means gitu no longer panics and correctly handles a staged file whose name contains non-ASCII characters.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.