20_Mercurial_and_Gitlab.ipynb 48.1 KB
Newer Older
paugier's avatar
paugier committed
1
2
3
4
{
 "cells": [
  {
   "cell_type": "markdown",
paugier's avatar
paugier committed
5
6
7
8
9
10
11
12
13
14
15
16
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Introduction to source control management with Mercurial and Gitlab\n",
    "\n",
    "## Why?\n",
    "\n",
    "### Why source control management?\n",
    "\n",
17
18
19
20
21
22
23
24
25
26
27
    "Essential tool for scientists and developers!!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
paugier's avatar
paugier committed
28
29
30
31
32
33
    "### Why Mercurial?\n",
    "\n",
    "- https://www.mercurial-scm.org/ \n",
    "\n",
    "- https://fluiddyn.readthedocs.io/en/latest/mercurial_bitbucket.html\n",
    "\n",
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    "Why not Git?"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "<div align=\"middle\">\n",
    "<img src=\"./fig/git.png\"  style=\"width: 30%; margin-top: -30px; margin-bottom: -20px\"> &nbsp;\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "Git is really too complicated for what we need as scientists / students / teachers / developers of most scientific programs.\n",
paugier's avatar
paugier committed
55
    "\n",
56
    "[Mercurial is more adapted for us in academics.](http://www.legi.grenoble-inp.fr/people/Pierre.Augier/mercurial-as-a-great-version-source-control-management-tool-in-academics.html)"
paugier's avatar
paugier committed
57
58
59
60
61
62
63
64
65
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
paugier's avatar
paugier committed
66
   "source": [
paugier's avatar
paugier committed
67
68
69
    "### Why Gitlab?\n",
    "\n",
    "https://gricad-gitlab.univ-grenoble-alpes.fr\n",
paugier's avatar
paugier committed
70
    "\n",
paugier's avatar
paugier committed
71
    "### Warning! Gitlab does not natively support Mercurial!\n",
paugier's avatar
paugier committed
72
    "\n",
paugier's avatar
paugier committed
73
    "For now, we'll have to use a Mercurial extension (hg-git) and it won't be as nice as if we could use a platform natively supporting Mercurial (as for example Bitbucket).\n",
paugier's avatar
paugier committed
74
    "\n",
75
    "But [Heptapod (Gitlab with Mercurial support)](https://octobus.net/blog/2018-09-18-heptapod-announce.html) is coming."
paugier's avatar
paugier committed
76
77
78
79
80
81
82
83
84
85
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
paugier's avatar
paugier committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
    "## Level 0: commands `help`, `init`, `status`, `add`, `remove`, `addremove`, `commit`, `log` and `summary`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mercurial Distributed SCM\n",
      "\n",
      "list of commands:\n",
      "\n",
paugier's avatar
paugier committed
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
      "Repository creation:\n",
      "\n",
      " clone         make a copy of an existing repository\n",
      " init          create a new repository in the given directory\n",
      "\n",
      "Remote repository management:\n",
      "\n",
      " incoming      show new changesets found in source\n",
      " outgoing      show changesets not found in the destination\n",
      " paths         show aliases for remote repositories\n",
      " pull          pull changes from the specified source\n",
      " push          push changes to the specified destination\n",
      " serve         start stand-alone webserver\n",
      "\n",
      "Change creation:\n",
      "\n",
      " absorb        incorporate corrections into the stack of draft changesets\n",
      " commit        commit the specified files or all outstanding changes\n",
      "\n",
      "Change manipulation:\n",
      "\n",
paugier's avatar
paugier committed
123
      " backout       reverse effect of earlier changeset\n",
paugier's avatar
paugier committed
124
125
126
127
128
129
      " graft         copy changes from other branches onto the current branch\n",
      " merge         merge another revision into working directory\n",
      " rebase        move changeset (and descendants) to a different branch\n",
      "\n",
      "Change organization:\n",
      "\n",
paugier's avatar
paugier committed
130
131
132
      " bookmarks     create a new bookmark or list existing bookmarks\n",
      " branch        set or show the current branch name\n",
      " branches      list repository named branches\n",
paugier's avatar
paugier committed
133
134
135
136
137
138
139
      " phase         set or show the current phase name\n",
      " tag           add one or more tags for the current or given revision\n",
      " tags          list repository tags\n",
      "\n",
      "File content management:\n",
      "\n",
      " annotate      show changeset information by line for each file\n",
paugier's avatar
paugier committed
140
141
142
      " cat           output the current or given revision of files\n",
      " copy          mark files as copied for the next commit\n",
      " diff          diff repository (or selected files)\n",
paugier's avatar
paugier committed
143
      " extdiff       use external program to diff repository (or selected files)\n",
paugier's avatar
paugier committed
144
      " grep          search revision history for a pattern in specified files\n",
paugier's avatar
paugier committed
145
146
147
148
149
      " meld          use external program to diff repository (or selected files)\n",
      "\n",
      "Change navigation:\n",
      "\n",
      " bisect        subdivision search of changesets\n",
paugier's avatar
paugier committed
150
151
152
      " heads         show branch heads\n",
      " identify      identify the working directory or specified revision\n",
      " log           show revision history of entire repository or files\n",
paugier's avatar
paugier committed
153
154
155
156
157
158
159
      "\n",
      "Working directory management:\n",
      "\n",
      " add           add the specified files on the next commit\n",
      " addremove     add all new files, delete all missing files\n",
      " files         list tracked files\n",
      " forget        forget the specified files on the next commit\n",
paugier's avatar
paugier committed
160
161
162
163
164
      " remove        remove the specified files on the next commit\n",
      " rename        rename files; equivalent of copy + remove\n",
      " resolve       redo merges or set/view the merge status of files\n",
      " revert        restore files to their checkout state\n",
      " root          print the root (top) of the current working directory\n",
paugier's avatar
paugier committed
165
      " shelve        save and set aside changes from the working directory\n",
paugier's avatar
paugier committed
166
167
      " status        show changed files in the working directory\n",
      " summary       summarize working directory state\n",
paugier's avatar
paugier committed
168
      " unshelve      restore a shelved change to the working directory\n",
paugier's avatar
paugier committed
169
      " update        update working directory (or switch revisions)\n",
paugier's avatar
paugier committed
170
171
172
173
174
175
176
177
178
179
180
181
182
183
      "\n",
      "Change import/export:\n",
      "\n",
      " archive       create an unversioned archive of a repository revision\n",
      " bundle        create a bundle file\n",
      " export        dump the header and diffs for one or more changesets\n",
      " import        import an ordered set of patches\n",
      " unbundle      apply one or more bundle files\n",
      "\n",
      "Repository maintenance:\n",
      "\n",
      " churn         histogram of changes to the repository\n",
      " manifest      output the current or given revision of the project manifest\n",
      " recover       roll back an interrupted transaction\n",
paugier's avatar
paugier committed
184
      " verify        verify the integrity of the repository\n",
paugier's avatar
paugier committed
185
186
187
188
189
      "\n",
      "Help:\n",
      "\n",
      " config        show combined config settings from all hgrc files\n",
      " help          show help for a given topic or a help overview\n",
paugier's avatar
paugier committed
190
191
      " version       output version and copyright information\n",
      "\n",
paugier's avatar
paugier committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
      "Uncategorized commands:\n",
      "\n",
      " amend         combine a changeset with updates and replace it with a new one\n",
      " evolve        solve troubled changesets in your repository\n",
      " fold          fold multiple revisions into a single one\n",
      " gclear        clear out the Git cached data\n",
      " gexport       export commits from Mercurial to Git\n",
      " gimport       import commits from Git to Mercurial\n",
      " git-cleanup   clean up Git commit map after history editing\n",
      " gverify       verify that a Mercurial rev matches the corresponding Git rev\n",
      " metaedit      edit commit information\n",
      " next          update to next child revision\n",
      " obslog        show the obsolescence history of the specified revisions\n",
      " pdiff         show diff combining committed and uncommited changes\n",
      " pick          move a commit on the top of working directory parent and\n",
      "               updates to it.\n",
      " previous      update to parent revision\n",
      " prune         mark changesets as obsolete or succeeded by another changeset\n",
      " pstatus       show status combining committed and uncommited changes\n",
      " rewind        rewind a stack of changesets to a previous state\n",
      " split         split a changeset into smaller changesets\n",
      " stack         list all changesets in a topic and other information\n",
      " topics        View current topic, set current topic, change topic for a set\n",
      "               of revisions, or see all topics.\n",
      " touch         create successors identical to their predecessors but the\n",
      "               changeset ID\n",
      " uncommit      move changes from parent revision to working directory\n",
      "\n",
paugier's avatar
paugier committed
220
221
      "enabled extensions:\n",
      "\n",
paugier's avatar
paugier committed
222
223
      " churn         command to display statistics about repository history\n",
      " evolve        extends Mercurial feature related to Changeset Evolution\n",
paugier's avatar
paugier committed
224
225
      " extdiff       command to allow external programs to compare revisions\n",
      " hggit         push and pull from a Git server\n",
paugier's avatar
paugier committed
226
227
228
      " rebase        command to move sets of revisions to a different ancestor\n",
      " shelve        save and restore changes to the working directory\n",
      " topic         support for topic branches\n",
paugier's avatar
paugier committed
229
230
231
      "\n",
      "additional help topics:\n",
      "\n",
paugier's avatar
paugier committed
232
233
234
235
236
237
238
239
240
241
      "Mercurial identifiers:\n",
      "\n",
      " filesets      Specifying File Sets\n",
      " hgignore      Syntax for Mercurial Ignore Files\n",
      " patterns      File Name Patterns\n",
      " revisions     Specifying Revisions\n",
      " urls          URL Paths\n",
      "\n",
      "Mercurial output:\n",
      "\n",
paugier's avatar
paugier committed
242
243
244
      " color         Colorizing Outputs\n",
      " dates         Date Formats\n",
      " diffs         Diff Formats\n",
paugier's avatar
paugier committed
245
246
247
248
249
      " templating    Template Usage\n",
      "\n",
      "Mercurial configuration:\n",
      "\n",
      " config        Configuration Files\n",
paugier's avatar
paugier committed
250
251
      " environment   Environment Variables\n",
      " extensions    Using Additional Features\n",
paugier's avatar
paugier committed
252
      " flags         Command-line flags\n",
paugier's avatar
paugier committed
253
254
255
      " hgweb         Configuring hgweb\n",
      " merge-tools   Merge Tools\n",
      " pager         Pager Support\n",
paugier's avatar
paugier committed
256
257
258
259
260
      "\n",
      "Concepts:\n",
      "\n",
      " bundlespec    Bundle File Formats\n",
      " glossary      Glossary\n",
paugier's avatar
paugier committed
261
262
      " phases        Working with Phases\n",
      " subrepos      Subrepositories\n",
paugier's avatar
paugier committed
263
264
265
266
267
268
269
270
271
272
273
      "\n",
      "Miscellaneous:\n",
      "\n",
      " deprecated    Deprecated Features\n",
      " internals     Technical implementation topics\n",
      " scripting     Using Mercurial from scripts and automation\n",
      "\n",
      "Uncategorized topics:\n",
      "\n",
      " evolution     Safely Rewriting History\n",
      " git           Working with Git Repositories\n",
paugier's avatar
paugier committed
274
275
276
277
278
279
280
281
282
283
284
285
286
      "\n",
      "(use 'hg help -v' to show built-in aliases and global options)\n"
     ]
    }
   ],
   "source": [
    "hg help"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
paugier's avatar
paugier committed
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hg init [-e CMD] [--remotecmd CMD] [DEST]\n",
      "\n",
      "create a new repository in the given directory\n",
      "\n",
      "    Initialize a new repository in the given directory. If the given directory\n",
      "    does not exist, it will be created.\n",
      "\n",
      "    If no directory is given, the current directory is used.\n",
      "\n",
      "    It is possible to specify an \"ssh://\" URL as the destination. See 'hg help\n",
      "    urls' for more information.\n",
      "\n",
      "    Returns 0 on success.\n",
      "\n",
      "options:\n",
      "\n",
      " -e --ssh CMD       specify ssh command to use\n",
      "    --remotecmd CMD specify hg command to run on the remote side\n",
      "    --insecure      do not verify server certificate (ignoring web.cacerts\n",
      "                    config)\n",
      "\n",
      "(some details hidden, use --verbose to show complete help)\n"
     ]
    }
   ],
   "source": [
    "hg help init"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
paugier's avatar
paugier committed
325
326
327
328
329
330
331
332
   "outputs": [],
   "source": [
    "# cleanup\n",
    "rm -rf /tmp/myrepos"
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
333
   "execution_count": 4,
paugier's avatar
paugier committed
334
335
336
337
338
339
340
341
342
343
   "metadata": {},
   "outputs": [],
   "source": [
    "mkdir -p /tmp/myrepos/myrepo0\n",
    "cd /tmp/myrepos/myrepo0\n",
    "touch file0.txt"
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
344
   "execution_count": 5,
paugier's avatar
paugier committed
345
346
347
348
349
350
351
352
   "metadata": {},
   "outputs": [],
   "source": [
    "hg init"
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;35;1;4m? \u001b[0m\u001b[0;35;1;4mfile0.txt\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "hg status"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;35;1;4m? \u001b[0m\u001b[0;35;1;4mfile0.txt\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "# equivalent command (shorter)\n",
    "hg st"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;32madding file0.txt\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "hg add"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;32;1mA \u001b[0m\u001b[0;32;1mfile0.txt\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "hg st"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "hg commit -m \"First commit\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "hg st"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "touch file1.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;35;1;4m? \u001b[0m\u001b[0;35;1;4mfile1.txt\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "hg st"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "rm -f file0.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;36;1;4m! \u001b[0m\u001b[0;36;1;4mfile0.txt\u001b[0m\n",
      "\u001b[0;35;1;4m? \u001b[0m\u001b[0;35;1;4mfile1.txt\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "hg st"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;31mremoving file0.txt\u001b[0m\n",
      "\u001b[0;32madding file1.txt\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "hg addremove\n",
    "# or \n",
    "# hg addre"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;32;1mA \u001b[0m\u001b[0;32;1mfile1.txt\u001b[0m\n",
      "\u001b[0;31;1mR \u001b[0m\u001b[0;31;1mfile0.txt\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "hg st"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "hg commit -m \"Remove file0 and add file1\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "hg st"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file1.txt\n"
     ]
    }
   ],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;33mparent: 1:4c7dfaebb15e \u001b[0mtip\n",
      " Remove file0 and add file1\n",
      "branch: default\n",
      "commit: (clean)\n",
      "update: (current)\n",
      "phases: 2 draft\n"
     ]
    }
   ],
   "source": [
    "hg sum"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Mercurial tells us that we are in the branch \"default\", which is... the default \"named branch\". Note that Mercurial \"named branches\" are used only for long term features or versions of software (for example \"pypy2.7\" and \"pypy3.6\" in Pypy repository) and not for feature branches like branches in Git. For this tutorial, we won't use other named branches and we'll always work in the default branch."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;33mchangeset:   1:4c7dfaebb15e\u001b[0m\n",
      "tag:         tip\n",
      "user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "date:        Thu May 23 14:28:56 2019 +0200\n",
      "summary:     Remove file0 and add file1\n",
      "\n",
      "\u001b[0;33mchangeset:   0:8879044fa44a\u001b[0m\n",
      "user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "date:        Thu May 23 14:28:54 2019 +0200\n",
      "summary:     First commit\n",
      "\n"
     ]
    }
   ],
   "source": [
    "hg log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "@  \u001b[0;33mchangeset:   1:4c7dfaebb15e\u001b[0m\n",
      "|  tag:         tip\n",
      "|  user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "|  date:        Thu May 23 14:28:56 2019 +0200\n",
      "|  summary:     Remove file0 and add file1\n",
      "|\n",
      "o  \u001b[0;33mchangeset:   0:8879044fa44a\u001b[0m\n",
      "   user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "   date:        Thu May 23 14:28:54 2019 +0200\n",
      "   summary:     First commit\n",
      "\n"
     ]
    }
   ],
   "source": [
    "hg log --graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "@  \u001b[0;33mchangeset:   1:4c7dfaebb15e\u001b[0m\n",
      "|  tag:         tip\n",
      "|  user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "|  date:        Thu May 23 14:28:56 2019 +0200\n",
      "|  summary:     Remove file0 and add file1\n",
      "|\n",
      "o  \u001b[0;33mchangeset:   0:8879044fa44a\u001b[0m\n",
      "   user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "   date:        Thu May 23 14:28:54 2019 +0200\n",
      "   summary:     First commit\n",
      "\n"
     ]
    }
   ],
   "source": [
    "hg log -G"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Level 1.0: command `revert`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file1.txt\n"
     ]
    }
   ],
   "source": [
    "echo file1.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "echo \"Something wrong\" > file1.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;34;1mM \u001b[0m\u001b[0;34;1mfile1.txt\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "hg st"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "hg revert file1.txt\n",
    "# or to revert all files:\n",
    "# hg revert --all"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file1.txt  file1.txt.orig\n"
     ]
    }
   ],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;35;1;4m? \u001b[0m\u001b[0;35;1;4mfile1.txt.orig\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "hg st"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "rm -f file1.txt.orig"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Level 1.1: command `update`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 files updated, 0 files merged, 1 files removed, 0 files unresolved\n"
     ]
    }
   ],
   "source": [
    "hg update 0\n",
    "# `update` or just `up`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;33mparent: 0:8879044fa44a \u001b[0m\n",
      " First commit\n",
      "branch: default\n",
      "commit: (clean)\n",
      "update: 1 new changesets (update)\n",
      "phases: 2 draft\n"
     ]
    }
   ],
   "source": [
    "hg sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file0.txt\n"
     ]
    }
   ],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
paugier's avatar
paugier committed
853
854
855
856
857
858
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
859
      "1 files updated, 0 files merged, 1 files removed, 0 files unresolved\n"
paugier's avatar
paugier committed
860
861
862
863
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
864
    "hg up"
paugier's avatar
paugier committed
865
866
867
868
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
869
   "execution_count": 36,
paugier's avatar
paugier committed
870
871
872
873
874
875
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
876
877
878
879
880
881
      "\u001b[0;33mparent: 1:4c7dfaebb15e \u001b[0mtip\n",
      " Remove file0 and add file1\n",
      "branch: default\n",
      "commit: (clean)\n",
      "update: (current)\n",
      "phases: 2 draft\n"
paugier's avatar
paugier committed
882
883
884
885
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
886
    "hg sum"
paugier's avatar
paugier committed
887
888
889
890
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
891
   "execution_count": 37,
paugier's avatar
paugier committed
892
893
894
895
896
897
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
898
      "file1.txt\n"
paugier's avatar
paugier committed
899
900
901
902
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
903
    "ls"
paugier's avatar
paugier committed
904
905
906
907
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
908
   "execution_count": 38,
paugier's avatar
paugier committed
909
910
911
   "metadata": {},
   "outputs": [],
   "source": [
paugier's avatar
paugier committed
912
    "touch file2.txt"
paugier's avatar
paugier committed
913
914
915
916
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
917
   "execution_count": 39,
paugier's avatar
paugier committed
918
   "metadata": {},
paugier's avatar
paugier committed
919
920
921
922
923
924
925
926
927
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;35;1;4m? \u001b[0m\u001b[0;35;1;4mfile2.txt\u001b[0m\n"
     ]
    }
   ],
paugier's avatar
paugier committed
928
929
930
931
932
933
   "source": [
    "hg st"
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
934
   "execution_count": 40,
paugier's avatar
paugier committed
935
936
937
938
939
940
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
941
      "\u001b[0;32madding file2.txt\u001b[0m\n"
paugier's avatar
paugier committed
942
943
944
945
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
946
    "hg add"
paugier's avatar
paugier committed
947
948
949
950
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
951
   "execution_count": 41,
paugier's avatar
paugier committed
952
953
954
   "metadata": {},
   "outputs": [],
   "source": [
paugier's avatar
paugier committed
955
    "hg commit -m \"Add file 2\""
paugier's avatar
paugier committed
956
957
958
959
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
960
   "execution_count": 42,
paugier's avatar
paugier committed
961
962
963
964
965
966
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
      "@  \u001b[0;33mchangeset:   2:c67605445601\u001b[0m\n",
      "|  tag:         tip\n",
      "|  user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "|  date:        Thu May 23 14:29:01 2019 +0200\n",
      "|  summary:     Add file 2\n",
      "|\n",
      "o  \u001b[0;33mchangeset:   1:4c7dfaebb15e\u001b[0m\n",
      "|  user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "|  date:        Thu May 23 14:28:56 2019 +0200\n",
      "|  summary:     Remove file0 and add file1\n",
      "|\n",
      "o  \u001b[0;33mchangeset:   0:8879044fa44a\u001b[0m\n",
      "   user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "   date:        Thu May 23 14:28:54 2019 +0200\n",
      "   summary:     First commit\n",
      "\n"
paugier's avatar
paugier committed
983
984
985
986
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
987
    "hg log -G"
paugier's avatar
paugier committed
988
989
990
   ]
  },
  {
paugier's avatar
paugier committed
991
992
993
994
995
996
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
paugier's avatar
paugier committed
997
   "source": [
paugier's avatar
paugier committed
998
    "## Level 2: commands `clone`, `push`, `pull`  "
paugier's avatar
paugier committed
999
1000
1001
1002
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1003
   "execution_count": 43,
paugier's avatar
paugier committed
1004
1005
1006
1007
1008
1009
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1010
      "/tmp/myrepos\n"
paugier's avatar
paugier committed
1011
1012
1013
1014
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1015
1016
    "cd ..\n",
    "pwd"
paugier's avatar
paugier committed
1017
1018
1019
1020
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1021
   "execution_count": 44,
paugier's avatar
paugier committed
1022
1023
1024
1025
1026
1027
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1028
1029
      "updating to branch default\n",
      "2 files updated, 0 files merged, 0 files removed, 0 files unresolved\n"
paugier's avatar
paugier committed
1030
1031
1032
1033
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1034
    "hg clone myrepo0 myrepo_web"
paugier's avatar
paugier committed
1035
1036
1037
1038
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "cd myrepo0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
paugier's avatar
paugier committed
1049
1050
1051
1052
1053
1054
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1055
      "file1.txt  file2.txt\n"
paugier's avatar
paugier committed
1056
1057
1058
1059
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1060
    "ls"
paugier's avatar
paugier committed
1061
1062
1063
1064
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1065
   "execution_count": 47,
paugier's avatar
paugier committed
1066
   "metadata": {},
paugier's avatar
paugier committed
1067
1068
1069
1070
1071
1072
1073
1074
1075
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0;34;1mM \u001b[0m\u001b[0;34;1mfile2.txt\u001b[0m\n"
     ]
    }
   ],
paugier's avatar
paugier committed
1076
   "source": [
paugier's avatar
paugier committed
1077
1078
    "echo \"Hello\" > file2.txt\n",
    "hg st"
paugier's avatar
paugier committed
1079
1080
1081
1082
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1083
   "execution_count": 48,
paugier's avatar
paugier committed
1084
1085
1086
   "metadata": {},
   "outputs": [],
   "source": [
paugier's avatar
paugier committed
1087
    "hg commit -m \"Improve file2\""
paugier's avatar
paugier committed
1088
1089
1090
1091
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1092
   "execution_count": 49,
paugier's avatar
paugier committed
1093
1094
1095
1096
1097
1098
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
      "@  \u001b[0;33mchangeset:   3:8839d935ce7e\u001b[0m\n",
      "|  tag:         tip\n",
      "|  user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "|  date:        Thu May 23 14:29:03 2019 +0200\n",
      "|  summary:     Improve file2\n",
      "|\n",
      "o  \u001b[0;33mchangeset:   2:c67605445601\u001b[0m\n",
      "|  user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "|  date:        Thu May 23 14:29:01 2019 +0200\n",
      "|  summary:     Add file 2\n",
      "|\n",
      "o  \u001b[0;33mchangeset:   1:4c7dfaebb15e\u001b[0m\n",
      "|  user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "|  date:        Thu May 23 14:28:56 2019 +0200\n",
      "|  summary:     Remove file0 and add file1\n",
      "|\n",
      "o  \u001b[0;33mchangeset:   0:8879044fa44a\u001b[0m\n",
      "   user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "   date:        Thu May 23 14:28:54 2019 +0200\n",
      "   summary:     First commit\n",
      "\n"
paugier's avatar
paugier committed
1120
1121
1122
1123
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1124
    "hg log -G"
paugier's avatar
paugier committed
1125
1126
1127
1128
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1129
   "execution_count": 50,
paugier's avatar
paugier committed
1130
1131
1132
1133
1134
1135
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1136
1137
1138
1139
1140
1141
      "pushing to /tmp/myrepos/myrepo_web\n",
      "searching for changes\n",
      "adding changesets\n",
      "adding manifests\n",
      "adding file changes\n",
      "added 1 changesets with 1 changes to 1 files\n"
paugier's avatar
paugier committed
1142
1143
1144
1145
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1146
1147
1148
1149
1150
1151
1152
1153
    "hg push /tmp/myrepos/myrepo_web"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "At this point, we have 2 repositories."
paugier's avatar
paugier committed
1154
1155
1156
1157
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1158
   "execution_count": 51,
paugier's avatar
paugier committed
1159
1160
1161
1162
1163
1164
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1165
1166
      "/tmp/myrepos\n",
      "\u001b[0m\u001b[01;34mmyrepo0\u001b[0m  \u001b[01;34mmyrepo_web\u001b[0m\n"
paugier's avatar
paugier committed
1167
1168
1169
1170
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1171
1172
1173
    "cd /tmp/myrepos\n",
    "pwd\n",
    "ls"
paugier's avatar
paugier committed
1174
1175
1176
1177
1178
1179
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
paugier's avatar
paugier committed
1180
    "Let's create a new repository from the repo on the web. (Usually, it is done in another computer.)"
paugier's avatar
paugier committed
1181
1182
1183
1184
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1185
   "execution_count": 52,
paugier's avatar
paugier committed
1186
1187
1188
1189
1190
1191
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1192
1193
      "updating to branch default\n",
      "2 files updated, 0 files merged, 0 files removed, 0 files unresolved\n"
paugier's avatar
paugier committed
1194
1195
1196
1197
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1198
    "hg clone myrepo_web myrepo_other_computer"
paugier's avatar
paugier committed
1199
1200
1201
1202
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1203
   "execution_count": 53,
paugier's avatar
paugier committed
1204
   "metadata": {},
paugier's avatar
paugier committed
1205
1206
1207
1208
1209
1210
1211
1212
1213
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file1.txt  file2.txt\n"
     ]
    }
   ],
paugier's avatar
paugier committed
1214
   "source": [
paugier's avatar
paugier committed
1215
1216
    "cd myrepo_other_computer\n",
    "ls"
paugier's avatar
paugier committed
1217
1218
1219
1220
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1221
   "execution_count": 54,
paugier's avatar
paugier committed
1222
1223
1224
1225
1226
1227
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1228
      "Hello\n"
paugier's avatar
paugier committed
1229
1230
1231
1232
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1233
    "cat file2.txt"
paugier's avatar
paugier committed
1234
1235
1236
1237
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1238
   "execution_count": 55,
paugier's avatar
paugier committed
1239
1240
1241
   "metadata": {},
   "outputs": [],
   "source": [
paugier's avatar
paugier committed
1242
    "echo \"Hello Word!\" > file2.txt"
paugier's avatar
paugier committed
1243
1244
1245
1246
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1247
   "execution_count": 56,
paugier's avatar
paugier committed
1248
1249
1250
1251
1252
1253
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1254
      "\u001b[0;34;1mM \u001b[0m\u001b[0;34;1mfile2.txt\u001b[0m\n"
paugier's avatar
paugier committed
1255
1256
1257
1258
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1259
    "hg st"
paugier's avatar
paugier committed
1260
1261
1262
1263
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "hg commit -m '\"Hello Word!\" is even nicer'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "hg st"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We push the new changeset towards the default repository (from which this repository has been created), which is the \"web\" repository."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
paugier's avatar
paugier committed
1290
1291
1292
1293
1294
1295
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1296
1297
1298
1299
1300
1301
      "pushing to /tmp/myrepos/myrepo_web\n",
      "searching for changes\n",
      "adding changesets\n",
      "adding manifests\n",
      "adding file changes\n",
      "added 1 changesets with 1 changes to 1 files\n"
paugier's avatar
paugier committed
1302
1303
1304
1305
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1306
    "hg push"
paugier's avatar
paugier committed
1307
1308
1309
1310
1311
1312
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
paugier's avatar
paugier committed
1313
    "Let's come back to the original repository in the first computer."
paugier's avatar
paugier committed
1314
1315
1316
1317
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "cd ../myrepo0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
paugier's avatar
paugier committed
1328
1329
1330
1331
1332
1333
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1334
      "Hello\n"
paugier's avatar
paugier committed
1335
1336
1337
1338
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1339
    "cat file2.txt"
paugier's avatar
paugier committed
1340
1341
1342
1343
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1344
   "execution_count": 62,
paugier's avatar
paugier committed
1345
1346
1347
1348
1349
1350
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1351
1352
1353
1354
1355
      "\u001b[0;33mparent: 3:8839d935ce7e \u001b[0mtip\n",
      " Improve file2\n",
      "branch: default\n",
      "commit: (clean)\n",
      "update: (current)\n"
paugier's avatar
paugier committed
1356
1357
1358
1359
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1360
    "hg sum"
paugier's avatar
paugier committed
1361
1362
1363
1364
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1365
   "execution_count": 63,
paugier's avatar
paugier committed
1366
1367
1368
1369
1370
1371
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1372
1373
1374
1375
1376
1377
1378
1379
      "pulling from /tmp/myrepos/myrepo_web\n",
      "searching for changes\n",
      "adding changesets\n",
      "adding manifests\n",
      "adding file changes\n",
      "added 1 changesets with 1 changes to 1 files\n",
      "new changesets 7731298d515d\n",
      "(run 'hg update' to get a working copy)\n"
paugier's avatar
paugier committed
1380
1381
1382
1383
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1384
    "hg pull /tmp/myrepos/myrepo_web"
paugier's avatar
paugier committed
1385
1386
1387
1388
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1389
   "execution_count": 64,
paugier's avatar
paugier committed
1390
1391
1392
1393
1394
1395
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1396
      "1 files updated, 0 files merged, 0 files removed, 0 files unresolved\n"
paugier's avatar
paugier committed
1397
1398
1399
1400
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1401
    "hg up"
paugier's avatar
paugier committed
1402
1403
1404
   ]
  },
  {
paugier's avatar
paugier committed
1405
   "cell_type": "markdown",
paugier's avatar
paugier committed
1406
1407
   "metadata": {},
   "source": [
paugier's avatar
paugier committed
1408
    "We could have just run `hg pull -u` to pull and update to the tip of the branch where we are, i.e. the last commit since the repository is now in a linear state."
paugier's avatar
paugier committed
1409
1410
1411
1412
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1413
   "execution_count": 65,
paugier's avatar
paugier committed
1414
1415
1416
1417
1418
1419
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1420
1421
1422
1423
1424
      "\u001b[0;33mparent: 4:7731298d515d \u001b[0mtip\n",
      " \"Hello Word!\" is even nicer\n",
      "branch: default\n",
      "commit: (clean)\n",
      "update: (current)\n"
paugier's avatar
paugier committed
1425
1426
1427
1428
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1429
    "hg sum"
paugier's avatar
paugier committed
1430
1431
1432
1433
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1434
   "execution_count": 66,
paugier's avatar
paugier committed
1435
1436
1437
1438
1439
1440
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1441
      "Hello Word!\n"
paugier's avatar
paugier committed
1442
1443
1444
1445
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1446
    "cat file2.txt"
paugier's avatar
paugier committed
1447
1448
1449
   ]
  },
  {
paugier's avatar
paugier committed
1450
1451
1452
1453
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
paugier's avatar
paugier committed
1454
    }
paugier's avatar
paugier committed
1455
   },
paugier's avatar
paugier committed
1456
   "source": [
paugier's avatar
paugier committed
1457
    "## Level 3: nonlinear history, unnamed branches and `merge` command  "
paugier's avatar
paugier committed
1458
1459
1460
1461
1462
1463
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
paugier's avatar
paugier committed
1464
    "We can now consider the case in which 2 persons (Alice and Bob) work at the same time on the same project. First they both clone the web repository."
paugier's avatar
paugier committed
1465
1466
1467
1468
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1469
   "execution_count": 67,
paugier's avatar
paugier committed
1470
1471
1472
1473
1474
1475
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1476
1477
      "updating to branch default\n",
      "2 files updated, 0 files merged, 0 files removed, 0 files unresolved\n"
paugier's avatar
paugier committed
1478
1479
1480
1481
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1482
1483
1484
    "# Alice\n",
    "cd /tmp/myrepos/\n",
    "hg clone myrepo_web myrepo_Alice"
paugier's avatar
paugier committed
1485
1486
1487
1488
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1489
   "execution_count": 68,
paugier's avatar
paugier committed
1490
1491
1492
1493
1494
1495
1496
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "updating to branch default\n",
paugier's avatar
paugier committed
1497
      "2 files updated, 0 files merged, 0 files removed, 0 files unresolved\n"
paugier's avatar
paugier committed
1498
1499
1500
1501
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1502
1503
1504
1505
1506
1507
1508
1509
1510
    "# Bob\n",
    "hg clone myrepo_web myrepo_Bob"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Just for this notebook, we can tell Mercurial who is the owner of Alice's and Bob's repositories. "
paugier's avatar
paugier committed
1511
1512
1513
1514
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1515
   "execution_count": 69,
paugier's avatar
paugier committed
1516
1517
1518
   "metadata": {},
   "outputs": [],
   "source": [
paugier's avatar
paugier committed
1519
1520
1521
    "# not useful in real life!\n",
    "echo \"username = Alice <alice@mail.wonderland>\" >> /tmp/myrepos/myrepo_Alice/.hg/hgrc\n",
    "echo \"username = Bob <bob@mail.wonderland>\" >> /tmp/myrepos/myrepo_Bob/.hg/hgrc"
paugier's avatar
paugier committed
1522
1523
1524
1525
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1526
   "execution_count": 70,
paugier's avatar
paugier committed
1527
1528
1529
1530
1531
1532
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1533
1534
1535
1536
1537
1538
1539
      "\u001b[0;32madding Alice_file.py\u001b[0m\n",
      "pushing to /tmp/myrepos/myrepo_web\n",
      "searching for changes\n",
      "adding changesets\n",
      "adding manifests\n",
      "adding file changes\n",
      "added 1 changesets with 1 changes to 1 files\n"
paugier's avatar
paugier committed
1540
1541
1542
1543
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1544
1545
1546
1547
1548
1549
    "# Alice works\n",
    "cd /tmp/myrepos/myrepo_Alice\n",
    "touch Alice_file.py\n",
    "hg add\n",
    "hg commit -m \"Alice adds a file\"\n",
    "hg push"
paugier's avatar
paugier committed
1550
1551
1552
1553
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1554
1555
1556
1557
1558
1559
   "execution_count": 71,
   "metadata": {
    "tags": [
     "raises-exception"
    ]
   },
paugier's avatar
paugier committed
1560
1561
1562
1563
1564
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1565
      "\u001b[0;32madding Bob_file.py\u001b[0m\n"
paugier's avatar
paugier committed
1566
1567
1568
1569
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1570
1571
1572
1573
1574
    "# Bob works\n",
    "cd /tmp/myrepos/myrepo_Bob\n",
    "touch Bob_file.py\n",
    "hg add\n",
    "hg commit -m \"Bob adds a file\""
paugier's avatar
paugier committed
1575
1576
1577
   ]
  },
  {
paugier's avatar
paugier committed
1578
   "cell_type": "markdown",
paugier's avatar
paugier committed
1579
1580
   "metadata": {},
   "source": [
paugier's avatar
paugier committed
1581
1582
1583
1584
1585
1586
1587
1588
1589
    "At this point, `hg push` would lead to the following error:\n",
    "\n",
    "```\n",
    "pushing to /tmp/myrepos/myrepo_web\n",
    "searching for changes\n",
    "remote has heads on branch 'default' that are not known locally: 69b3f39e70ab\n",
    "abort: push creates new remote head 938fc2084593!\n",
    "(pull and merge or see 'hg help push' for details about pushing new heads)\n",
    "```"
paugier's avatar
paugier committed
1590
1591
1592
   ]
  },
  {
paugier's avatar
paugier committed
1593
   "cell_type": "markdown",
paugier's avatar
paugier committed
1594
1595
   "metadata": {},
   "source": [
paugier's avatar
paugier committed
1596
    "Bob encounters a problem... The remote repository has a commit which is not know locally. Let's first pull this commit."
paugier's avatar
paugier committed
1597
1598
1599
1600
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1601
   "execution_count": 72,
paugier's avatar
paugier committed
1602
1603
1604
1605
1606
1607
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1608
      "pulling from /tmp/myrepos/myrepo_web\n",
paugier's avatar
paugier committed
1609
1610
1611
1612
      "searching for changes\n",
      "adding changesets\n",
      "adding manifests\n",
      "adding file changes\n",
paugier's avatar
paugier committed
1613
1614
1615
      "added 1 changesets with 1 changes to 1 files (+1 heads)\n",
      "new changesets babf3d5a206f\n",
      "(run 'hg heads' to see heads, 'hg merge' to merge)\n"
paugier's avatar
paugier committed
1616
1617
1618
1619
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1620
1621
1622
1623
1624
1625
1626
1627
    "hg pull"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we can examine the situation."
paugier's avatar
paugier committed
1628
1629
1630
1631
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1632
   "execution_count": 73,
paugier's avatar
paugier committed
1633
1634
1635
1636
1637
1638
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
      "\u001b[0;33mchangeset:   6:babf3d5a206f\u001b[0m\n",
      "tag:         tip\n",
      "parent:      4:7731298d515d\n",
      "user:        Alice <alice@mail.wonderland>\n",
      "date:        Thu May 23 14:29:09 2019 +0200\n",
      "summary:     Alice adds a file\n",
      "\n",
      "\u001b[0;33mchangeset:   5:77110f8956cb\u001b[0m\n",
      "user:        Bob <bob@mail.wonderland>\n",
      "date:        Thu May 23 14:29:10 2019 +0200\n",
      "summary:     Bob adds a file\n",
      "\n"
paugier's avatar
paugier committed
1651
1652
1653
1654
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1655
    "hg heads"
paugier's avatar
paugier committed
1656
1657
1658
1659
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1660
   "execution_count": 74,
paugier's avatar
paugier committed
1661
1662
1663
1664
1665
1666
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
      "o  \u001b[0;33mchangeset:   6:babf3d5a206f\u001b[0m\n",
      "|  tag:         tip\n",
      "|  parent:      4:7731298d515d\n",
      "|  user:        Alice <alice@mail.wonderland>\n",
      "|  date:        Thu May 23 14:29:09 2019 +0200\n",
      "|  summary:     Alice adds a file\n",
      "|\n",
      "| @  \u001b[0;33mchangeset:   5:77110f8956cb\u001b[0m\n",
      "|/   user:        Bob <bob@mail.wonderland>\n",
      "|    date:        Thu May 23 14:29:10 2019 +0200\n",
      "|    summary:     Bob adds a file\n",
      "|\n",
      "o  \u001b[0;33mchangeset:   4:7731298d515d\u001b[0m\n",
      "|  user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "|  date:        Thu May 23 14:29:05 2019 +0200\n",
      "|  summary:     \"Hello Word!\" is even nicer\n",
      "|\n",
      "o  \u001b[0;33mchangeset:   3:8839d935ce7e\u001b[0m\n",
      "|  user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "~  date:        Thu May 23 14:29:03 2019 +0200\n",
      "   summary:     Improve file2\n",
      "\n"
paugier's avatar
paugier committed
1689
1690
1691
1692
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
    "hg log -G -l 4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We have 2 \"unnamed branches\" (in the \"named branch\" default), i.e. 2 different commits with the same parent (changeset 4).\n",
    "\n",
    "A simple way to avoid this situation is to pull just before a commit and to make sure to commit from the last commit in the shared repository.\n",
    "\n",
    "There are different ways to solve this problem. The nicest would be to move changeset 5 above changeset 6 (actually change the parent of changeset 5 to changeset 6). It's very simple to do with the command `hg rebase -s 5 -d 6` (`-s` and `-d` mean source and destination, respectively). It is nice since it leads to a linear state but it is a little bit too complicated (history rewriting).\n",
    "\n",
    "In the error log, Mercurial tells us about the simple way to solve the situation: pull and merge. Let's try that."
paugier's avatar
paugier committed
1707
1708
1709
1710
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1711
   "execution_count": 75,
paugier's avatar
paugier committed
1712
1713
1714
1715
1716
1717
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1718
1719
      "1 files updated, 0 files merged, 0 files removed, 0 files unresolved\n",
      "(branch merge, don't forget to commit)\n"
paugier's avatar
paugier committed
1720
1721
1722
1723
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1724
    "hg merge"
paugier's avatar
paugier committed
1725
1726
1727
1728
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1729
   "execution_count": 76,
paugier's avatar
paugier committed
1730
1731
1732
1733
1734
1735
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1736
1737
1738
1739
1740
1741
1742
1743
      "\u001b[0;33mparent: 5:77110f8956cb \u001b[0m\n",
      " Bob adds a file\n",
      "\u001b[0;33mparent: 6:babf3d5a206f \u001b[0mtip\n",
      " Alice adds a file\n",
      "branch: default\n",
      "commit: \u001b[0;34;1m1 modified\u001b[0m (merge)\n",
      "update: (current)\n",
      "phases: 1 draft\n"
paugier's avatar
paugier committed
1744
1745
1746
1747
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1748
    "hg sum"
paugier's avatar
paugier committed
1749
1750
1751
1752
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1753
   "execution_count": 77,
paugier's avatar
paugier committed
1754
1755
1756
1757
1758
1759
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1760
1761
1762
1763
1764
1765
      "\u001b[0;34;1mM \u001b[0m\u001b[0;34;1mAlice_file.py\u001b[0m\n",
      "# The repository is in an unfinished *merge* state.\n",
      "\n",
      "# To continue:    hg commit\n",
      "# To abort:       hg merge --abort\n",
      "\n"
paugier's avatar
paugier committed
1766
1767
1768
1769
1770
1771
1772
1773
1774
     ]
    }
   ],
   "source": [
    "hg st"
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1775
   "execution_count": 78,
paugier's avatar
paugier committed
1776
   "metadata": {},
paugier's avatar
paugier committed
1777
1778
1779
1780
1781
1782
1783
1784
1785
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alice_file.py  Bob_file.py  file1.txt  file2.txt\n"
     ]
    }
   ],
paugier's avatar
paugier committed
1786
   "source": [
paugier's avatar
paugier committed
1787
    "ls"
paugier's avatar
paugier committed
1788
1789
1790
1791
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1792
   "execution_count": 79,
paugier's avatar
paugier committed
1793
1794
1795
   "metadata": {},
   "outputs": [],
   "source": [
paugier's avatar
paugier committed
1796
    "hg commit -m \"Merge Alice and Bob commits\""
paugier's avatar
paugier committed
1797
1798
1799
1800
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1801
   "execution_count": 80,
paugier's avatar
paugier committed
1802
1803
1804
1805
1806
1807
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
      "@    \u001b[0;33mchangeset:   7:08314eada178\u001b[0m\n",
      "|\\   tag:         tip\n",
      "| |  parent:      5:77110f8956cb\n",
      "| |  parent:      6:babf3d5a206f\n",
      "| |  user:        Bob <bob@mail.wonderland>\n",
      "| |  date:        Thu May 23 14:29:12 2019 +0200\n",
      "| |  summary:     Merge Alice and Bob commits\n",
      "| |\n",
      "| o  \u001b[0;33mchangeset:   6:babf3d5a206f\u001b[0m\n",
      "| |  parent:      4:7731298d515d\n",
      "| |  user:        Alice <alice@mail.wonderland>\n",
      "| |  date:        Thu May 23 14:29:09 2019 +0200\n",
      "| |  summary:     Alice adds a file\n",
      "| |\n",
      "o |  \u001b[0;33mchangeset:   5:77110f8956cb\u001b[0m\n",
      "|/   user:        Bob <bob@mail.wonderland>\n",
      "|    date:        Thu May 23 14:29:10 2019 +0200\n",
      "|    summary:     Bob adds a file\n",
      "|\n",
      "o  \u001b[0;33mchangeset:   4:7731298d515d\u001b[0m\n",
      "|  user:        paugier <pierre.augier@univ-grenoble-alpes.fr>\n",
      "~  date:        Thu May 23 14:29:05 2019 +0200\n",
      "   summary:     \"Hello Word!\" is even nicer\n",
      "\n"
paugier's avatar
paugier committed
1832
1833
1834
1835
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1836
    "hg log -G -l 4"
paugier's avatar
paugier committed
1837
1838
1839
   ]
  },
  {
paugier's avatar
paugier committed
1840
   "cell_type": "markdown",
paugier's avatar
paugier committed
1841
1842
   "metadata": {},
   "source": [
paugier's avatar
paugier committed
1843
    "Note that the history is no longer linear. However, the repository is now in a good state so we should be able to push in the remote repository."
paugier's avatar
paugier committed
1844
1845
1846
1847
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1848
   "execution_count": 81,
paugier's avatar
paugier committed
1849
1850
1851
1852
1853
1854
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1855
1856
1857
1858
1859
1860
      "pushing to /tmp/myrepos/myrepo_web\n",
      "searching for changes\n",
      "adding changesets\n",
      "adding manifests\n",
      "adding file changes\n",
      "added 2 changesets with 1 changes to 1 files\n"
paugier's avatar
paugier committed
1861
1862
1863
1864
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1865
1866
1867
1868
1869
1870
1871
1872
    "hg push"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And Alice can get Bob's file."
paugier's avatar
paugier committed
1873
1874
1875
1876
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1877
   "execution_count": 82,
paugier's avatar
paugier committed
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pulling from /tmp/myrepos/myrepo_web\n",
      "searching for changes\n",
      "adding changesets\n",
      "adding manifests\n",
      "adding file changes\n",
paugier's avatar
paugier committed
1889
1890
1891
      "added 2 changesets with 1 changes to 1 files\n",
      "new changesets 77110f8956cb:08314eada178\n",
      "1 files updated, 0 files merged, 0 files removed, 0 files unresolved\n"
paugier's avatar
paugier committed
1892
1893
1894
1895
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1896
1897
1898
    "# Alice works\n",
    "cd /tmp/myrepos/myrepo_Alice\n",
    "hg pull -u"
paugier's avatar
paugier committed
1899
1900
1901
1902
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1903
   "execution_count": 83,
paugier's avatar
paugier committed
1904
1905
1906
1907
1908
1909
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1910
1911
1912
1913
1914
      "\u001b[0;33mparent: 7:08314eada178 \u001b[0mtip\n",
      " Merge Alice and Bob commits\n",
      "branch: default\n",
      "commit: (clean)\n",
      "update: (current)\n"
paugier's avatar
paugier committed
1915
1916
1917
1918
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1919
    "hg sum"
paugier's avatar
paugier committed
1920
1921
1922
1923
   ]
  },
  {
   "cell_type": "code",
paugier's avatar
paugier committed
1924
   "execution_count": 84,
paugier's avatar
paugier committed
1925
1926
1927
1928
1929
1930
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
paugier's avatar
paugier committed
1931
      "Alice_file.py  Bob_file.py  file1.txt  file2.txt\n"
paugier's avatar
paugier committed
1932
1933
1934
1935
     ]
    }
   ],
   "source": [
paugier's avatar
paugier committed
1936
    "ls"
paugier's avatar
paugier committed
1937
   ]
paugier's avatar
paugier committed
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Gitlab\n",
    "\n",
    "https://gricad-gitlab.univ-grenoble-alpes.fr\n",
    "\n",
    "- Create a repository\n",
    "- Clone it with Mercurial locally\n",
    "\n",
    "  Note the difference between the https and ssh addresses. To use ssh, one first has to [setup a ssh key](https://gricad-gitlab.univ-grenoble-alpes.fr/profile/keys).\n",
    "  \n",
    "- Create a README.md and fill it with few lines of markdown code.\n",
    "\n",
    "- Commit and push:\n",
    "\n",
    "```\n",
    "hg st\n",
    "hg add\n",
    "hg commit -m \"Modify README.md\"\n",
    "hg push\n",
    "```\n",
    "\n",
    "Note the difference with `hg add` and `git add`!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Example of a Latex project\n",
    "\n",
    "It's very useful to use a Makefile. Everything can be compiled just with the command `make`. Complicated Makefile syntaxes are not mandatory!\n",
    "\n",
    "The commands `latexmk` and `latexdiff` can be really useful!\n",
    "\n",
    "Here is a simple example:\n",
    "\n",
    "```\n",
    "name := my_paper\n",
    "\n",
    "LATEX := pdflatex -shell-escape -synctex=1\n",
    "\n",
    ".PHONY: all clean cleanall\n",
    "\n",
    "all: $(name).pdf\n",
    "\n",
    "revision.tex:\n",
    "\thg cat -r 0.2.0 $(name).tex > $(name)_submitted.tex\n",
    "\tlatexdiff -c PICTUREENV=minted $(name)_submitted.tex $(name).tex > revision.tex\n",
    "\trm -f $(name)_submitted.tex\n",
    "\n",
    "revision.pdf: revision.tex\n",
    "\tlatexmk -pdf -pdflatex=\"$(LATEX)\" revision.tex\n",
    "\trm -f revision.tex\n",
    "\n",
    "revision: revision.tex revision.pdf clean\n",
    "\n",
    "rebuttal.pdf: rebuttal.md\n",
    "\tpandoc $< -o $@\n",
    "\n",
    "clean:\n",
    "\trm -f *.log *.aux *.out *.bbl *.blg *.tmp\n",
    "\trm -rf _minted-$(name)\n",
    "\n",
    "cleanall: clean\n",
    "\trm -f $(name).pdf\n",
    "\n",
    "$(name).pdf: $(name).tex\n",
    "\tlatexmk -pdf -pdflatex=\"$(LATEX)\" $(name).tex\n",
    "\n",
    "```\n",
    "\n"
   ]
paugier's avatar
paugier committed
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Bash",
   "language": "bash",
   "name": "bash"
  },
  "language_info": {
   "codemirror_mode": "shell",
   "file_extension": ".sh",
   "mimetype": "text/x-sh",
   "name": "bash"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}