orgzly-revived / orgzly-android-revived

Outliner for taking notes and managing to-do lists
https://www.orgzlyrevived.com
GNU General Public License v3.0
677 stars 42 forks source link

orgzly keeps syncing to a conflict branch even after the branch has been merged #237

Open wilderjds opened 7 months ago

wilderjds commented 7 months ago

Please complete the following information:

Device: Pixel 7
Android Version: 14 
Orgzly Revived Version: 
Repository type(s) used: git 

On a git repository, orgzly keep syncing to a merge-conflict branch even if the branch has been merged to master. No conflicts are present; I even removed the branch from the remote, but orgzly keeps creating it. This has worked OK for some time but with the last conflict it is not resetting to master.

amberin commented 7 months ago

I am currently testing a completely new git sync logic, so my memory of how the current logic works may be wrong, but I believe there is a bug which means that this will happen if you delete the conflict branch on the remote side before Orgzly has returned to the main branch. I think you need to resolve the conflict on the temp branch (i.e. merge main into it), leave it like that on the remote side, and trigger sync in Orgzly. Otherwise, Orgzly will simply push its view of the temp branch, and not attempt to return to the main branch. Once you're back on main, you can then safely delete the temp branch on the remote.

This is of course confusing and bad, but it is solved in my ongoing overhaul of the git sync logic.

Please try this and let me know if it works.

wilderjds commented 7 months ago

Thanks for your reply. It does not work as it should; here is what happens

I merge the conflict branch to master on my laptop, then push to the remote After that, I sync on Android Then I push some changes from the laptop to master After that, I sync on Android; changes are picked up, but the notebook is still on the same conflict branch If I make some changes from Android, they go to the same conflict branch, and not to master Even if the branch is deleted on the remote, changes pushed to master are picked up from Android, and then the branch is re-created upon sync'ing

amberin commented 7 months ago

Sounds very strange indeed... If you look at the repo settings, is the main branch name correct? (See #29.)

amberin commented 7 months ago

FYI, this is where you should end up in the code, but for some reason don't (or attemptReturnToMainBrach fails): https://github.com/orgzly-revived/orgzly-android-revived/blob/master/app/src/main/java/com/orgzly/android/git/GitFileSynchronizer.java#L318

But, as I was trying to express earlier, one known issue is that, if the current branch does not exist on the remote (because you have deleted the temp branch), you will end up here, and no attempt is done to return to the main branch: https://github.com/orgzly-revived/orgzly-android-revived/blob/master/app/src/main/java/com/orgzly/android/git/GitFileSynchronizer.java#L327

When you say you are receiving new changes on master, does the book status say "loaded from branch master"? Because that message means that the repo is on that branch. Any subsequent push of a temp branch should be a new one.

wilderjds commented 7 months ago

When you say you are receiving new changes on master, does the book status say "loaded from branch master"? Because that message means that the repo is on that branch. Any subsequent push of a temp branch should be a new one.

No, I get "loaded from branch merge-conflict-xxx", but the changes we re only pushed to master

wilderjds commented 7 months ago

Sounds very strange indeed... If you look at the repo settings, is the main branch name correct? (See #29.)

Yes, the branch is "master". Always had been.

stfl commented 7 months ago

I am seeing similar issues when rebasing master on top of merge-xyz.org-... branch. After I push to origin/master Orgzly updates the merge branch to master but stays on the merge branch.

Even though the merge branch can be fast-forwarded to master, either after a rebase or a merge, Orgzly creates a new merge branch.

stfl commented 7 months ago
5422c66 *   origin/master origin/merge-freelance.org-28ae343-2024-05-02_142716 origin/merge-freelance.org-28ae343-2024-05-02_140728 Merge remote-tracking branch 'origin/merge-freelance.org-28ae343-2024-05-02_140728'
        |\  
a07f3a3 | * Orgzly update: inbox.org
955a6b4 * | origin/merge-freelance.org-28ae343-2024-05-02_140123 changes from amsel on Thu May 2 02:06:53 PM CEST 2024
78304c9 * | changes from amsel on Thu May 2 02:06:48 PM CEST 2024
        |/  
4d3d93a * Orgzly update: inbox.org
e221d7e * Orgzly update: inbox.org
76640f8 * origin/merge-freelance.org-28ae343-2024-05-02_084944 changes from amsel on Thu May 2 01:19:29 PM CEST 2024
wilderjds commented 7 months ago

I probably figured out what was causing the issue for me (but I have no clue about how I ended up with that). I explored the Android repo with termux and found out that master had diverged from the remote (despite being on a conflict branch). Orgzly-revived was happily fetching updates from master and the conflict branch. But since master had diverged it refused to fast-forward. Since we were sitting on the conflict branch no action was taken, master was not in sync with the conflict and no "return to main branch" was happening.

I manually merged master with the remote and then orgzly was happy.

stfl commented 7 months ago

Yes. That makes sense. I am the end doing a rebase forces the other end to do a reset.

I am using git-sync for my other devices which rebases as the default sync procedure.

amberin commented 7 months ago

@wilderjds Interesting. I'd love to know how your master branch ended up in that diverged state...

wilderjds commented 7 months ago

@wilderjds Interesting. I'd love to know how your master branch ended up in that diverged state...

No idea tbh, but will report here if it happens again. Now that I found out that I can keep track of stuff in termux, it will be easier to see what is going on.