foriequal0 / git-trim

Automatically trims your branches whose tracking remote refs are merged or stray
MIT License
490 stars 14 forks source link

Panic if branches are deleted between when the command starts running and `git push --delete` is called #205

Open jyn514 opened 1 year ago

jyn514 commented 1 year ago

Describe the bug git-trim assumes that no other git commands are run at the same time and panics if that's not the case.

To Reproduce

  1. Run git trim --delete 'remote:*' in one terminal
  2. While that runs, simultaneously run git branch -a --merged | grep personal | tail -n+2 | cut -d/ -f3- | xargs git push personal --delete --no-verify in another terminal (which does essentially the same thing but faster)

Expected behavior The git-trim command is a no-op, because the branches don't exist to delete.

Actual behaviour

Error: Failed to classify #5: NonUpstreamBranchClassificationRequest {
    base: RemoteTrackingBranch {
        refname: "refs/remotes/origin/master",
    },
    remote: RemoteTrackingBranch {
        refname: "refs/remotes/personal/autolabel",
    },
}

Caused by:
    reference 'refs/remotes/personal/autolabel' not found; class=Reference (4); code=NotFound (-3)

Stack backtrace:
   0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
   1: git_trim::merge_tracker::MergeTracker::check_and_track
   2: <git_trim::core::NonUpstreamBranchClassificationRequest as git_trim::core::ClassificationRequest>::classify
   3: core::ops::function::FnOnce::call_once{{vtable.shim}}
   4: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
   5: <rayon_core::job::HeapJob<BODY> as rayon_core::job::Job>::execute
   6: rayon_core::registry::WorkerThread::wait_until_cold
   7: rayon_core::scope::ScopeBase::complete
   8: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
   9: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
  10: rayon_core::registry::WorkerThread::wait_until_cold
  11: rayon_core::registry::ThreadBuilder::run
  12: std::sys_common::backtrace::__rust_begin_short_backtrace
  13: core::ops::function::FnOnce::call_once{{vtable.shim}}
  14: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/8a97b4812a7a46bb5206487c2455b9c5bfcbd1b9/library/alloc/src/boxed.rs:2000:9
  15: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/8a97b4812a7a46bb5206487c2455b9c5bfcbd1b9/library/alloc/src/boxed.rs:2000:9
  16: std::sys::unix::thread::Thread::new::thread_start
             at /rustc/8a97b4812a7a46bb5206487c2455b9c5bfcbd1b9/library/std/src/sys/unix/thread.rs:108:17
  17: start_thread
             at ./nptl/./nptl/pthread_create.c:442:8
  18: clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81