palves · GitHub

I wanted to delete a branch I know is empty. I happened to put the "--delete" after the branch name, like so:

$ stg branch some-branch --delete
error: delete not permitted: the series still contains patches (override with --force)

Hmm, this is surprising, I know the branch has no patches... Let me double-check:

$ stg series -b some-branch
$

Indeed, empty! What is going on? I created a new empty git project to create a reproducer, and I saw:

$ git init
Initialized empty Git repository in /tmp/stgit-bug/.git/
$ echo foo > foo
$ git add foo
$ git commit -m "initial"
[master (root-commit) 9c785a1] initial
1 file changed, 1 insertion(+)
create mode 100644 foo
$ stg init
$ stg branch --create abranch
info: Recording as a local branch
$ stg branch master
$ stg branch abranch --delete
error: cannot delete the current branch without a known parent branch

Oh wow, note "current branch" is mentioned.

I see what was going on then. "stg branch --delete" deletes the current branch. Above, when I tried "stg branch some-branch --delete", it said that the series still contains patches, but it was referring to the current branch, not "some-branch"!

Going back to the tree with "some-branch", to test the hypothesis, indeed I see:

$ stg branch some-branch --delete
error: delete not permitted: the series still contains patches (override with --force)
$ stg branch some-branch --delete --force
$ git status
On branch parent-of-some-branch

Ouch, it deleted the current branch, and because a parent was set, it switched to it.

"stg branch some_other_branch --delete" should either be an error, or do the expected thing. Deleting the current branch is just not good.

$ stg version
Stacked Git 2.4.6
Copyright (C) 2005-2024 StGit authors
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
SPDX-License-Identifier: GPL-2.0-only
git version 2.43.2

Read the original on github.com ↗