You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Thank you for this issue report @palves. Agreed that this is a problem.
The root of the issue is that the command line parsing for stg branch allows a branch argument to precede the subcommand argument (--delete in this case), but that preceding branch argument is not passed-to or otherwise recognized by the subcommand handler which leads to the subcommand parsing the remainder of the command line (and potentially executing) without any knowledge of the preceding branch argument.
There is a clap option that basically disallows arguments to precede subcommands, so turning on that option is my preferred approach for addressing this issue. That would turn the offending stg branch some_other_branch --delete into a command line parsing error. StGit would only allow the form stg branch --delete some_other_branch, which has always been the intended spelling.
I've got a fix in the works. Will have this resolved soon.
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
The text was updated successfully, but these errors were encountered: