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

Sync Improvement - merge snippets instead of overwrite #57

Open
brpaz opened this issue Oct 5, 2017 · 12 comments
Open

Sync Improvement - merge snippets instead of overwrite #57

brpaz opened this issue Oct 5, 2017 · 12 comments

Comments

@brpaz
Copy link

brpaz commented Oct 5, 2017

Hi.
First of all, congratulations for building this tool I am using it everyday.

I added lots of snippets in the last days, and today I decided to run pet sync in order to synchronize to my snippets gist. But I didn´t specify the -u flag, so it downloaded the contents of the gist file and replaced all my newly created snippets! fortunately I had a backup. I was not aware of this behavior. I think sync should merge the contents of local and remote files and not replacing them like this. The current behavior is more of a backup, than a sync really. It I have pet running of two machines and add snippets In both of then, there is no way to sync automatically without losing data.

Hope this can be improved.

Keep up the good work!

@kpron
Copy link

kpron commented Jan 30, 2018

+1

@knqyf263
Copy link
Owner

@brpaz I'm sorry for the too late reply!
I released v0.3.0.
https://github.com/knqyf263/pet/releases/tag/v0.3.0

I changed the behavior of pet sync.
pet sync compares the local file and gist with the update date and download or upload automatically.
So -u option is deprecated.
Please see https://github.com/knqyf263/pet#sync

In addition, auto_sync is added.
https://github.com/knqyf263/pet#auto-sync

@patrik-bartak
Copy link
Contributor

patrik-bartak commented Jun 10, 2024

The sync feature is great, but I think there is still an issue with auto_sync that happened to me today. Let's say I have auto_sync on both machines A and B. I add a snippet on machine A and it syncs the gist. Now I add a snippet on machine B. It will add the snippet, making the local file newer, then upload, and overwrite the snippet added by machine A.

In my opinion, it makes more sense to do this when running pet new with auto_sync on:

  • sync with the gist to get any new commands
  • add the command
  • sync again to upload the command

@RamiAwar
Copy link
Collaborator

The sync feature is great, but I think there is still an issue with auto_sync that happened to me today. Let's say I have auto_sync on both machines A and B. I add a snippet on machine A and it syncs the gist. Now I add a snippet on machine B. It will add the snippet, making the local file newer, then upload, and overwrite the snippet added by machine A.

In my opinion, it makes more sense to do this when running pet new with auto_sync on:

  • sync with the gist to get any new commands
  • add the command
  • sync again to upload the command

You mean as in merge the changes?

@patrik-bartak
Copy link
Contributor

patrik-bartak commented Jun 12, 2024

@RamiAwar A merge is one option but not necessary.

I just mean it would be great if it didn't overwrite previously added commands from some other machine when I forget to pet sync before pet new. To achieve that it might be simpler to download (if remote is newer), add the command locally, then upload, no? With the same gist configured you can then add commands from any machine without touching pet sync with auto sync turned on, and none of them get lost.

I guess a question would be what would happen with pet edit. Would it also download first, then let you modify it, and then upload? Possibly, which to me sounds better than losing commands. If someone does not want this they can just disable auto sync or sync to different gists on different machines.

@RamiAwar
Copy link
Collaborator

RamiAwar commented Jun 20, 2024

@patrik-bartak sorry missed this.

Let me see if I understand correctly. So you're saying:

  • If autosync is on, if no local snippet file, download it first
  • Add the new snippet
  • If autosync is on, sync

For 'merging' changes i.e. if you already have a local file, you're saying we compare modified at as well. (local file system modification vs sync client last update date)

  • if autosync is on, if local snippet file, check if remote is newer. if so, download it.
  • add the new snippet
  • if autosync is on, sync

@patrik-bartak
Copy link
Contributor

@RamiAwar Yes that is what I had in mind. Do you agree this streamlines the use of pet, even if it is more complicated to implement? I imagine this will be useful for those that regularly switch computers.

@RamiAwar
Copy link
Collaborator

Yess I think it's definitely worth doing, makes sense!

@patrik-bartak
Copy link
Contributor

patrik-bartak commented Jun 20, 2024

The logic itself seems quite simple. Can I have a go at it or do you have time?

@RamiAwar
Copy link
Collaborator

Yess please do! 🙂 Don't have much time these days 😄

@patrik-bartak
Copy link
Contributor

I'm on it. Can I link this issue or make a new one? I think this issue should have already been resolved.

@RamiAwar
Copy link
Collaborator

@patrik-bartak You can just use this issue! We can add more details in the PR description 🙂 Thanks!

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