foriequal0/git-trim

Do not delete the checked-out branch (also don't delete master/main).

Opened this issue · 3 comments

Check your version before submitting the bug
git-trim is still 0.x version and I do make a lot of silly bugs.
Some bugs might be fixed on upstream version. Please update it and make sure that you're using the upstream version
especially you've installed git-trim other than cargo install such as Homebrew or AUR.

Describe the bug
It seems to have issues with having an 'upstream' and an 'origin' remote (as created by gh pr create). After my PR got merged, git-trim determined that the master branch could be deleted.

To Reproduce

  1. Minimal reproducible git repo if available:
    upstream: foriequal0/git-trim, origin: foriequal0/git-trim
  2. CLI command and configs
    See below. Just 'git trim'
  3. Steps to reproduce the behavior

Run git-trim in this very repo, while having "master" checked out. However master tracks my forked repo and my PR got merged. Hence, there's no need for the master-branch exactly anymore.

Expected behavior
Git-trim should not try to remove the master branch.

Actual behaviour

git-trim tries to delete the master branch. Git refuses because the branch is currently checked out. And git-trim exits with an error.

If applicable, add logs and stacktraces to help explain your problem.

Additional context and logs & dumps if necessary
You should remove sensitive informations before put them here.

  • OS: Ubuntu 18.04
  • Version:
  • git rev-parse --abbrev-ref HEAD: master
  • git show-ref (see below)
  • git config --get-regexp '(push|fetch|remote|branch|trim).*' | sort
branch.master.merge refs/heads/master
branch.master.remote origin
remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
remote.origin.url https://siedentop@github.com/siedentop/git-trim.git
remote.upstream.fetch +refs/heads/*:refs/remotes/upstream/*
remote.upstream.gh-resolved base
remote.upstream.url https://github.com/foriequal0/git-trim.git

Logs and stacktraces if necessary
You should remove sensitive informations before put them here.
You can get more detailed and clean logs by setting some environment variable with follwing command

export RUST_LOG=trace
export RAYON_NUM_THREADS=1
export RUST_BACKTRACE=full
git trim --no-confirm 2>&1 | tee <log_file>

--> Attached
git-trim-bug.log

git show-ref:

148f55753db6052755b451f63a0e710bc53ca5cc refs/heads/master
148f55753db6052755b451f63a0e710bc53ca5cc refs/remotes/origin/master
385d8818e3b8db9a73b0f32993f53d1ba0d31386 refs/remotes/upstream/HEAD
385d8818e3b8db9a73b0f32993f53d1ba0d31386 refs/remotes/upstream/master
97a7bad4cadb3c6f0894a574f313c8732819ec89 refs/tags/v0.1.0
4e05e2478cd5a210728f840497ec14ba492792df refs/tags/v0.1.1
251751283e579b8bf10f6853772fdc3d432b858b refs/tags/v0.1.2
ee6ab9212a5d425d17890bb412a58eaae2c43516 refs/tags/v0.1.3
327fdc706d7ebc2d276db1d101c62259788f0b3d refs/tags/v0.1.4
d516cc7a32ff6a4b2e02edbfe8a1c3fd04173852 refs/tags/v0.1.5
29cb02632501c774e7151547509bf1ff016f3b0a refs/tags/v0.2.0
f711e1b9b48fb490f75ccea3b39f57984339df15 refs/tags/v0.2.1
68d3d506dc3b394b563277ac2c471cc9a7aa0cc6 refs/tags/v0.2.2
e425a9f67fa357be44f3e901183c4156298af9b3 refs/tags/v0.2.3
331f74d4adb64e01ddad950ecfd9bc62aab4571e refs/tags/v0.2.4
50d06cf4985577da7c51e93e486ee912fd9c308f refs/tags/v0.2.5
b066877b1a913648a53fce2ab745c396bb1c3298 refs/tags/v0.3.0
0612c818337bcd3ad99f23580d7d230ba58e1f3d refs/tags/v0.3.1
bba3d0967fd4f785e7c5c7e64b537dd31bb1a543 refs/tags/v0.3.2
17d975773913fa0261fe8df5c56563af49cfef85 refs/tags/v0.4.0
4ab4cad8994d3c3c0c0a258c7cd44740cd7b78f2 refs/tags/v0.4.0-alpha.1
761f81046c7843bb8ac0e985c910e1a2998da31e refs/tags/v0.4.0-alpha.2
9b5e2c6e28482bc8a9390b456c5cf2a53262b4be refs/tags/v0.4.0-alpha.3
61b60c6d6c5cf83a5a10043cae6c37d27d076efc refs/tags/v0.4.0-alpha.4
58d3ee9ddbd23edd85756b4718e7cdd8b026882b refs/tags/v0.4.1
eb9dcc574e6d90140c98ea36a30f5b594162e392 refs/tags/v0.4.2

Deleting checked-out branch is an expected behavior (you can turn it off with --no-detach flag or git config trim.detach false)
Also you can protect a branch with --protected master flag or git config trim.protected master to protect all branches named 'master'.
Technically, git doesn't know whether branch a is somewhat connected with branch b except a and b is tracking/upstream relationship.
However in this case, I think git trim should have deduced that both origin/master and upstream/master are (unrelated) bases. I'll prepare fixes.

Why is "no-detach" not the default?

All the branch management strategy that I've used think feature branches are ephemeral. I've intended git-trim to trim these feature branches, and users should move on to other branch (such as master or other feature branches)