Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to remove stgit metadata from git when stgit messes itself and does not work. #388

Open
jrajahalme opened this issue Nov 28, 2023 · 10 comments

Comments

@jrajahalme
Copy link

There should be some documentation on how to remove stgit metadata form a git branch when stgit messes it's metadata and can't recover.

My branch is showing this type of error on every stgit command:

error: The reference "refs/patches/dns-proxy-use-original-source-address-and-port-redux-v1.14/dnsproxy-use-original-source" should have content ffbf7dae5804f57563499e75242587fb9d994beb, actual content was 67cdf152accc2dd8b5f042396cf4bb4e86227fdf

When I try to fix this with git update-ref to the wanted reference, it complains about another reference in the branch in the same manner. If I fix that up, it gives the first error again, and so it goes in an infinite loop.

Nothing works (stg branch --cleanup, stg branch --delete, stg repair) all give the same error.

I would appreciate if stg init had a --force flag to reinitialize stgit metadata for the current branch!

@jrajahalme
Copy link
Author

I wonder if deleting my git branch gets rid of all stgit metadata for it?

@jpgrayson
Copy link
Collaborator

I'm sorry that is bug is affecting you. Thank you for reporting.

I'd be very interested in knowing more details about how the repo might have gotten into this state. Any details would be appreciated; a reproducing case would be amazing.

The stack metadata associated with a branch is kept in a special ref: refs/stacks/<branchname>. So for your case, it would be refs/stacks/dns-proxy-use-original-source-address-and-port-redux-v1.14. It can be deleted like any other ref:

git update-ref -d refs/stacks/dns-proxy-use-original-source-address-and-port-redux-v1.14

Alternatively, one can checkout the stack metadata ref and inspect or even modify the metadata.

git checkout refs/stacks/dns-proxy-use-original-source-address-and-port-redux-v1.14

There is some information about this in the stg-init(1) man page.

@jrajahalme
Copy link
Author

Commits on the metadata branch:

$ git log
commit 892808fcbad158a60411cf1f8a09826aee06350a (HEAD)
Merge: 3c3df21d5d 85184d95fa c329a5813d
Author: Jarno Rajahalme <[email protected]>
Date:   Tue Nov 28 16:30:49 2023 +0200

    rebase (reapply)

commit 3c3df21d5dcd5646088d98cd3c429dca2da61189
Author: Jarno Rajahalme <[email protected]>
Date:   Tue Nov 28 16:30:49 2023 +0200

    rebase (reapply)

commit 85184d95fa05027b46b786d9a561df3d5b385b28
Author: Jarno Rajahalme <[email protected]>
Date:   Tue Nov 28 10:18:18 2023 +0200

    option: Add --dnsproxy-enable-transparent
...

This is the commit that seems to have broken the metadata:

$ git show 3c3df21d5dcd5646088d98cd3c429dca2da61189
commit 3c3df21d5dcd5646088d98cd3c429dca2da61189
Author: Jarno Rajahalme <[email protected]>
Date:   Tue Nov 28 16:30:49 2023 +0200

    rebase (reapply)

diff --git a/patches/dnsproxy-do-not-use-original-1 b/patches/dnsproxy-do-not-use-original-1
index 10ce364964..e1c943dedf 100644
--- a/patches/dnsproxy-do-not-use-original-1
+++ b/patches/dnsproxy-do-not-use-original-1
@@ -1,7 +1,7 @@
-Bottom: f19ba00ba50fabdc1e09157b33c73b7733abf1fc
-Top:    95aad8a0325f01ef6d623145fd5322b0ec934cb7
+Bottom: 8cb1d9d8f69b9e73343cd3388347db7bf3a0f1b8
+Top:    24bbf8d0663fe28b4c2e25956ac76315612c5141
 Author: Jarno Rajahalme <[email protected]>
-Date:   2023-11-22 15:39:38 +0200
+Date:   2023-11-28 16:30:49 +0200
 
 dnsproxy: Do not use original source when not possible
 
diff --git a/patches/dnsproxy-use-original-source b/patches/dnsproxy-use-original-source
index 7d8a2969c9..aef9a2d403 100644
--- a/patches/dnsproxy-use-original-source
+++ b/patches/dnsproxy-use-original-source
@@ -1,7 +1,7 @@
-Bottom: ccccb52a6662e7d3c5c1dfb009e4ae28a3389ef1
-Top:    f19ba00ba50fabdc1e09157b33c73b7733abf1fc
+Bottom: 986fa955faae17edd2462ef07c45ce9fe5e63214
+Top:    8cb1d9d8f69b9e73343cd3388347db7bf3a0f1b8
 Author: Jarno Rajahalme <[email protected]>
-Date:   2023-11-22 12:48:01 +0200
+Date:   2023-11-28 16:30:48 +0200
 
 dnsproxy: Use original source address in connections to dns servers
 
diff --git a/patches/option-add-dnsproxy-enable b/patches/option-add-dnsproxy-enable
index 5431dad125..caa76a1048 100644
--- a/patches/option-add-dnsproxy-enable
+++ b/patches/option-add-dnsproxy-enable
@@ -1,7 +1,7 @@
-Bottom: 95aad8a0325f01ef6d623145fd5322b0ec934cb7
-Top:    9c95dccb645537d94e1c374ef42394aa05b63a73
+Bottom: 24bbf8d0663fe28b4c2e25956ac76315612c5141
+Top:    4e91b9efbcb0d7c515490434af23ec11d642d34e
 Author: Jarno Rajahalme <[email protected]>
-Date:   2023-11-28 16:19:11 +0200
+Date:   2023-11-28 16:30:49 +0200
 
 option: Add --dnsproxy-enable-transparent-mode (default false)
 
diff --git a/stack.json b/stack.json
index db011b579f..e480664021 100644
--- a/stack.json
+++ b/stack.json
@@ -1,12 +1,13 @@
 {
   "version": 5,
-  "prev": "bc5b3eb005a17d77e5ce9875f67d0a8313527880",
-  "head": "d3eb130fccc233a3703adfef9fae537a3451d651",
-  "applied": [],
-  "unapplied": [
+  "prev": "c329a5813d4be802bfabccc932db10bd24bda10f",
+  "head": "85184d95fa05027b46b786d9a561df3d5b385b28",
+  "applied": [
     "dnsproxy-use-original-source",
     "dnsproxy-do-not-use-original-1",
-    "option-add-dnsproxy-enable",
+    "option-add-dnsproxy-enable"
+  ],
+  "unapplied": [
     "refresh-temp",
     "dnsproxy-do-not-use-original"
   ],
@@ -16,13 +17,13 @@
       "oid": "6500b2a7fada0920f3ec66ed4ec5ee3ac6e42c5a"
     },
     "dnsproxy-do-not-use-original-1": {
-      "oid": "7ba68aaaa4964a64961b309baf32115aecb02d2e"
+      "oid": "afc56ec702b8c4307115d9d61400563844e9e94c"
     },
     "dnsproxy-use-original-source": {
-      "oid": "ffbf7dae5804f57563499e75242587fb9d994beb"
+      "oid": "67cdf152accc2dd8b5f042396cf4bb4e86227fdf"
     },
     "option-add-dnsproxy-enable": {
-      "oid": "15f9bcb90c40e32d31b82936514e745ba0eedbd6"
+      "oid": "85184d95fa05027b46b786d9a561df3d5b385b28"
     },
     "refresh-temp": {
       "oid": "d7ea1d138e9d0c9066c0da978ce0f89c32fbc724"

Topmost commit seems empty, I must have rebased twice:

$ git show 892808fcbad158a60411cf1f8a09826aee06350a
commit 892808fcbad158a60411cf1f8a09826aee06350a
Merge: 3c3df21d5d 85184d95fa c329a5813d
Author: Jarno Rajahalme <[email protected]>
Date:   Tue Nov 28 16:30:49 2023 +0200

    rebase (reapply)

Tried updating the stacks reference to to remove the top two commits, but then it fails due to "stack metedata not found" :-)

After removing the stack reference, stg init complains with the same error as before:

$ git update-ref -d refs/stacks/dns-proxy-use-original-source-address-and-port-redux-v1.14

$ stg init                                                                                
error: The reference "refs/patches/dns-proxy-use-original-source-address-and-port-redux-v1.14/dnsproxy-do-not-use-original" should have content 6500b2a7fada0920f3ec66ed4ec5ee3ac6e42c5a, actual content was ffbf7dae5804f57563499e75242587fb9d994beb

After git reset --hard <upstream branch> stg init complains that error: StGit stack already initialized for branch dns-proxy-use-original-source-address-and-port-redux-v1.14`. It goes on:

$ git update-ref -d refs/stacks/dns-proxy-use-original-source-address-and-port-redux-v1.14

$ git reset --hard origin/dns-proxy-use-original-source-address-and-port-redux-v1.14      
HEAD is now at 36ef55e988 option: Add --dnsproxy-enable-transparent-mode (default false)
$ stg init                                                                                
error: The reference "refs/patches/dns-proxy-use-original-source-address-and-port-redux-v1.14/dnsproxy-do-not-use-original" should have content 6500b2a7fada0920f3ec66ed4ec5ee3ac6e42c5a, actual content was ffbf7dae5804f57563499e75242587fb9d994beb
$ 

@jrajahalme
Copy link
Author

If I create a new branch and then reset to my upstream branch I can init stgit again. IMO this shows that git update-ref -d did not remove the stgit metadata.

So this works:

$ git checkout v1.14
$ git checkout -b stgit-test
$ git reset --hard origin/dns-proxy-use-original-source-address-and-port-redux-v1.14
$ stg init
$ stg repair
$ stg uncommit -n 3

@jpgrayson
Copy link
Collaborator

I appreciate the details, thank you. It appears that something may be wrong with stg rebase.

If I create a new branch and then reset to my upstream branch I can init stgit again. IMO this shows that git update-ref -d did not remove the stgit metadata.

You're right and I was too hasty with my reply. In addition to refs/stacks/<branch>, there are also per-patch refs found in refs/patches/<branch>/<patchname>.

The patches refs found in refs/patches/<branch>/ are meant to reconcile with the patch commit ids found in refs/stacks/<branch>:stack.json.

It seems clear that part of the problem at play is that the stack.json metadata has gotten out-of-sync with the refs/patches/<branch>.

I should have recommended deleting all the refs/patches/<branch/* refs. That would have triggered StGit to recreate those patches refs based on the main stack metadata (refs/stacks/<branch>:stack.json).

The procedure that worked for you makes sense to me too.

@jrajahalme
Copy link
Author

jrajahalme commented Nov 30, 2023

Finally got to a clean state after removing all refs under 'refs/patches/dns-proxy-use-original-source-address-and-port-redux-v1.14' as well as refs/stacks/dns-proxy-use-original-source-address-and-port-redux-v1.14, thanks!

After the refs removal stg init worked again :-)

@mattiasflodin
Copy link

mattiasflodin commented Oct 3, 2024

Just to add a data point, I started seeing this error after simply pushing a couple of patches on the stack. Haven't done a rebase in several hours (and these patches have all been pushed before). Not sure if it might be relevant but this is on a separate worktree.

@arthurp
Copy link

arthurp commented Oct 30, 2024

I have repeatedly hit this issue when doing rebases using manual complex rebases using git. This is definitely not the right way to work with stg, but it would still be nice to just have a deinit command that does the delete above so I can then uncommit the stuff I would like to have on the stack. If nothing else this makes it easier to recover when my fingers perform a rebase without asking my higher brain function first. ;-)

@jnsnow
Copy link
Contributor

jnsnow commented Jan 28, 2025

Heya @jpgrayson - I'm running into this issue with stgit 2.4.12 from the Fedora 40 repo.

My setup is that I've got a branch (sphinx-domain) set to track origin/master that's got some 30-40+ patches in it, and the stack is somewhere 80% to the end; with various WIP/debugging patches unapplied at the end. This is a pretty usual type of stack for me :)

I have a second branch sphinx-domain-qapidoc set to track sphinx-domain, with another 40-50 patches on top.

I switched to the first branch (git checkout sphinx-domain) and tried to run stg rebase "@{u}" -- which doesn't seem to work anymore -- it used to -- but then re-ran stg rebase origin/master to update that dependency branch. All seems well.

Then, I switched to the second and tried to run stg rebase sphinx-domain and it started failing. I can remove .git/refs/patches/sphinx-domain-qapidoc and stg will work for precisely one command before failing again. If I also remove .git/refs/stacks/sphinx-domain-qapidoc, things start working again, but it's with the rebase partially-undone and with all of the modified files pending commit. I can fix all of this with git reset --hard HEAD and stg repair to get back to some normalcy, but if I try to stg rebase again ... it breaks again.

Can you kindly suggest what types of information you'd like to see to help diagnose what's going wrong with the rebase, as I am seemingly able to reproduce this at the moment?

Thanks,
--js

@jpgrayson
Copy link
Collaborator

I appreciate the offer to help diagnose this @jnsnow. I'm not sure I have enough bandwidth to git deep into this problem right now though.

From reading your description of steps, I do have some immediate questions:

Then, I switched to the second and tried to run stg rebase sphinx-domain and it started failing.

What is the failure signature? I.e. what is printed to stderr?

I can remove .git/refs/patches/sphinx-domain-qapidoc and stg will work for precisely one command before failing again.

That's an interesting clue. But what made you decide to delete that particular ref?

If I also remove .git/refs/stacks/sphinx-domain-qapidoc, things start working again, but it's with the rebase partially-undone and with all of the modified files pending commit. I can fix all of this with git reset --hard HEAD and stg repair to get back to some normalcy, but if I try to stg rebase again ... it breaks again.

I'm trying to decide if that means the index is correct? Or the working tree? Or neither?

Apologies in advance if this issue continues to linger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants