foriequal0/git-trim

git trim doesn't delete a deleted branch on github

Closed this issue · 12 comments

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. merge PR on github and remove that branch
  2. run git trim

Expected behavior
remind me the branch on remote is deleted, ask me if delete it in local.

Actual behaviour
only show local branches: and remote references:

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

  • Arch linux
  • 0.3.0
  • git rev-parse --abbrev-ref HEAD master
  • git show-ref
6c6aba623be17d1cbf637c837c4f901bc9e89788 refs/heads/custom-connector
ec7f2041392a9bc82943cc6897e8f4d18761ee25 refs/heads/master
df43f07e84eadcaeb451518718697ca6332bcf69 refs/heads/mount.rfs
32ff3644e9c5e6650f1fb801866a07bf3ed1383a refs/heads/remove-tokio-runtime
40882474879687bc5a680bd229c81279a91ddca2 refs/heads/retry-middleware
6c6aba623be17d1cbf637c837c4f901bc9e89788 refs/remotes/origin/custom-connector
ec7f2041392a9bc82943cc6897e8f4d18761ee25 refs/remotes/origin/master
32ff3644e9c5e6650f1fb801866a07bf3ed1383a refs/remotes/origin/remove-tokio-runtime
9b115e534261b52be3fc99fcc9fb2f6e6f335372 refs/stash
da371a7f1e9805cb7f9fb1620c48585d97f71237 refs/tags/0.1.0
  • git config --get-regexp '(push|fetch|remote|branch|trim).*' | sort
branch.custom-connector.merge refs/heads/custom-connector
branch.custom-connector.remote origin
branch.master.merge refs/heads/master
branch.master.remote origin
branch.mount.rfs.merge refs/heads/mount.rfs
branch.mount.rfs.remote origin
branch.remove-tokio-runtime.merge refs/heads/remove-tokio-runtime
branch.remove-tokio-runtime.remote origin
remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
remote.origin.url git@github.com:Sherlock-Holo/rfs.git

Logs and stacktraces

正在获取 origin

Branches that will remain:
  local branches:
    master
    mount.rfs
    custom-connector
    remove-tokio-runtime
    retry-middleware
  remote references:
    refs/remotes/origin/master
    refs/remotes/origin/custom-connector
    refs/remotes/origin/remove-tokio-runtime

You've merged retry-middleware branch's PR, right?
It seems that you didn't set an upstream (git push -u origin retry-middleware or git branch -u origin/retry-middleware) for it. branch.retry-middleware.remote doesn't exists.
In that case, git trim can't relate local one and the remote one safely.

I might be able to relate a local branch and (not explicitly designated) remote branch with git config remote.pushDefault and git config push.default config.
But they'll make you lose some local temporary branches such as git branch HEAD~4 (I do a lot for rebasing or else) since they are ancestors of the base branch. However, they are branches that you don't want to lose.
Also, I suspect that they'll create some scenarios for classifying some wrong remote branches as stray remotes if names collide.
That's why I only do check for branches that explicitly set upstreams.

retry-middleware is just a local branch, it deson't push to github.

the problem branch is mount.rfs, I've merged and deleted it on github Sherlock-Holo/rfs#11

Can you attach logs that can be enabled by setting an environment variable RUST_LOG=trace ?

I think . in the branch name causes the problem. I'll escape them before passing them to the git.

Ah sorry. . is not the cause of the problem.
I didn't see that you're using 0.3.0.
0.3.0 contains a silly bug that caused by some inverted flags.
#90 This is the fix of the bug and it is included in 0.3.1.
Can you reproduce this after upgrading it to 0.3.1?
Would you upgrade or flag out-of-date this AUR package if you can? https://aur.archlinux.org/packages/git-trim/

log:

[2020-03-30T13:36:57Z INFO  git_trim] SEMVER: 0.3.0
[2020-03-30T13:36:57Z INFO  git_trim] SHA: c746cd1981839d56042ecc99009f7d13db504944
[2020-03-30T13:36:57Z INFO  git_trim] COMMIT_DATE: 2020-03-27
[2020-03-30T13:36:57Z INFO  git_trim] TARGET_TRIPLE: x86_64-unknown-linux-gnu
[2020-03-30T13:36:57Z INFO  git_trim] bases: Explicit { value: [], source: "trim.bases" }
[2020-03-30T13:36:57Z INFO  git_trim] protected: Explicit { value: [], source: "trim.protected" }
[2020-03-30T13:36:57Z INFO  git_trim] update: Implicit(true)
[2020-03-30T13:36:57Z INFO  git_trim] confirm: Implicit(true)
[2020-03-30T13:36:57Z INFO  git_trim] detach: Implicit(true)
[2020-03-30T13:36:57Z INFO  git_trim] filter: Implicit(DeleteFilter({MergedLocal, MergedRemote(Scoped("origin"))}))
[2020-03-30T13:36:57Z INFO  git_trim::subprocess] > git -C /home/sherlock/git/rfs/ remote update --prune
正在获取 origin

[2020-03-30T13:37:04Z TRACE git_trim] base_upstreams: []
[2020-03-30T13:37:04Z TRACE git_trim] protected_refs: {}
[2020-03-30T13:37:04Z DEBUG git_trim] Branch: Some("master")
[2020-03-30T13:37:04Z DEBUG git_trim] Branch: Some("mount.rfs")
[2020-03-30T13:37:04Z DEBUG git_trim] Branch: Some("custom-connector")
[2020-03-30T13:37:04Z DEBUG git_trim] Branch: Some("remove-tokio-runtime")
[2020-03-30T13:37:04Z DEBUG git_trim] Branch: Some("retry-middleware")
[2020-03-30T13:37:04Z DEBUG git_trim] Skip: the branch doesn't have a tracking remote: "retry-middleware"
[2020-03-30T13:37:04Z TRACE git_trim] base_refs: {}
[2020-03-30T13:37:04Z TRACE git_trim] protected_refs: {}
[2020-03-30T13:37:04Z TRACE git_trim] Before filter: MergedOrStrayAndKeptBacks {
        to_delete: MergedOrStray {
            merged_locals: {},
            stray_locals: {},
            merged_remotes: {},
            stray_remotes: {},
        },
        kept_backs: {},
        kept_back_remotes: {},
    }
[2020-03-30T13:37:04Z TRACE git_trim] Applying filter: DeleteFilter({MergedLocal, MergedRemote(Scoped("origin"))})
[2020-03-30T13:37:04Z TRACE git_trim] filter-out: stray local branches {}
Branches that will remain:
  local branches:
    master
    mount.rfs
    custom-connector
    remove-tokio-runtime
    retry-middleware
  remote references:
    refs/remotes/origin/master
    refs/remotes/origin/custom-connector
    refs/remotes/origin/remove-tokio-runtime

I've mark git-trim out-of-date in AUR

Thank you!
This part of the log is the symptoms of the bug.

[2020-03-30T13:36:57Z INFO  git_trim] bases: Explicit { value: [], source: "trim.bases" }
[2020-03-30T13:36:57Z INFO  git_trim] protected: Explicit { value: [], source: "trim.protected" }

It'll work when you get 0.3.1.

I will wait for AUR updating in a few days, if waits too long, I will try to build this AUR package myself

You can pass cli option --bases master,develop manually until then.

AUR has updated, tests and works well