101-119-sharelocal4.rst 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. .. _sharelocal4:
  2. .. _update:
  3. Stay up to date
  4. ---------------
  5. All of what you have seen about sharing dataset was really
  6. cool, and for the most part also surprisingly intuitive.
  7. :dlcmd:`run` commands or file retrieval worked exactly as
  8. you imagined it to work, and you begin to think that slowly but
  9. steadily you are getting a feel about how DataLad really works.
  10. But to be honest, so far, sharing the dataset with DataLad was
  11. also remarkably unexciting given that you already knew most of
  12. the dataset magic that your room mate currently is still
  13. mesmerized about.
  14. To be honest, you are not yet certain whether
  15. sharing data with DataLad really improves your life up
  16. until this point. After all, you could have just copied
  17. your directory into your ``mock_user`` directory and
  18. this would have resulted in about the same output, right?
  19. What we will be looking into now is how shared DataLad
  20. datasets can be updated.
  21. Remember that you added some notes on :dlcmd:`clone`,
  22. :dlcmd:`get`, and :gitannexcmd:`whereis` into the
  23. original ``DataLad-101``?
  24. This is a change that is not reflected in your "shared"
  25. installation in ``../mock_user/DataLad-101``:
  26. .. runrecord:: _examples/DL-101-119-101
  27. :workdir: dl-101/mock_user/DataLad-101
  28. :notes: On updating dataset. How do we get the updated notes from the original dataset?
  29. :cast: 04_collaboration
  30. $ # Inside the installed copy, view the last 15 lines of notes.txt
  31. $ tail notes.txt
  32. But the original intention of sharing the dataset with
  33. your room mate was to give him access to your notes.
  34. How does he get the notes that you have added in the last
  35. two sections, for example?
  36. This installed copy of ``DataLad-101`` knows its ``origin``, i.e.,
  37. the place it was installed from. Using this information,
  38. it can query the original dataset whether any changes
  39. happened since the last time it checked, and if so, retrieve and
  40. integrate them.
  41. .. index::
  42. pair: update; DataLad command
  43. pair: update dataset with remote change; with DataLad
  44. This is done with the :dlcmd:`update --how merge`
  45. command.
  46. .. runrecord:: _examples/DL-101-119-102
  47. :language: console
  48. :workdir: dl-101/mock_user/DataLad-101
  49. :notes: retrieve and integrate changes from origin with datalad update --merge
  50. :cast: 04_collaboration
  51. $ datalad update --how merge
  52. Importantly, run this command either within the specific
  53. (sub)dataset you are interested in, or provide a path to
  54. the root of the dataset you are interested in with the
  55. ``-d``/``--dataset`` flag. If you would run the command
  56. within the ``longnow`` subdataset, you would query this
  57. subdatasets' ``origin`` for updates, not the original
  58. ``DataLad-101`` dataset.
  59. Let's check the contents in ``notes.txt`` to see whether
  60. the previously missing changes are now present:
  61. .. runrecord:: _examples/DL-101-119-103
  62. :language: console
  63. :workdir: dl-101/mock_user/DataLad-101
  64. :notes: let's check whether the updates are there
  65. :cast: 04_collaboration
  66. $ # view the last 15 lines of notes.txt
  67. $ tail notes.txt
  68. Wohoo, the contents are here!
  69. Therefore, sharing DataLad datasets by installing them
  70. enables you to update the datasets content should the
  71. original datasets' content change -- in only a single
  72. command. How cool is that?!
  73. Conclude this section by adding a note about updating a
  74. dataset to your own ``DataLad-101`` dataset:
  75. .. runrecord:: _examples/DL-101-119-104
  76. :language: console
  77. :workdir: dl-101/mock_user/DataLad-101
  78. :notes: note in original ds
  79. :cast: 04_collaboration
  80. $ # navigate back:
  81. $ cd ../../DataLad-101
  82. $ # write the note
  83. $ cat << EOT >> notes.txt
  84. To update a shared dataset, run the command "datalad update --how merge".
  85. This command will query its origin for changes, and integrate the
  86. changes into the dataset.
  87. EOT
  88. .. runrecord:: _examples/DL-101-119-105
  89. :language: console
  90. :workdir: dl-101/DataLad-101
  91. :notes:
  92. :cast: 04_collaboration
  93. $ # save the changes
  94. $ datalad save -m "add note about datalad update"
  95. PS: You might wonder what a plain :dlcmd:`update` command with no option does.
  96. If you are a Git-user and know about branches and merging you can read the
  97. ``Note for Git-users``. However, a thorough explanation
  98. and demonstration will be in the next section.
  99. .. index::
  100. pair: update; DataLad concept
  101. .. gitusernote:: Update internals
  102. :dlcmd:`update` is the DataLad equivalent of a :gitcmd:`fetch`,
  103. :dlcmd:`update --how merge` is the DataLad equivalent of a
  104. :gitcmd:`pull`.
  105. Upon a simple :dlcmd:`update`, the remote information
  106. is available on a branch separate from the main branch
  107. -- in most cases this will be ``remotes/origin/main``.
  108. You can :gitcmd:`checkout` this branch or run :gitcmd:`diff` to
  109. explore the changes and identify potential merge conflicts.
  110. .. only:: adminmode
  111. Add a tag at the section end.
  112. .. runrecord:: _examples/DL-101-119-106
  113. :language: console
  114. :workdir: dl-101/DataLad-101
  115. $ git branch sct_stay_up_to_date