stgit icon indicating copy to clipboard operation
stgit copied to clipboard

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

Open jrajahalme opened this issue 1 year ago • 7 comments

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 avatar Nov 28 '23 14:11 jrajahalme

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

jrajahalme avatar Nov 28 '23 14:11 jrajahalme

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.

jpgrayson avatar Nov 29 '23 03:11 jpgrayson

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 avatar Nov 29 '23 08:11 jrajahalme

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

jrajahalme avatar Nov 29 '23 09:11 jrajahalme

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.

jpgrayson avatar Nov 29 '23 14:11 jpgrayson

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 :-)

jrajahalme avatar Nov 30 '23 06:11 jrajahalme