4.8 Ejercicio 8 - usando el script

Del repo de ejercicios, hagan checkout de la rama exercise8/branchA y hagan merge de exercise8/branchB. Deberíamos ver un conflicto de archivo completo en primes.py.

Traten de hacer el merge corrigiendo la historia de la rama usando el script dado en esta receta.

Usemos unix2dos como hicimos antes para verificar:

Listing 4.42:Ejercicio 8 - formatos de EOL
$ git show HEAD:primes.py | unix2dos -idum 
       0      21       0 
$ git show MERGE_HEAD:primes.py | unix2dos -idum 
      27       0       0 
$ git show $( git merge-base HEAD MERGE_HEAD ):primes.py | unix2dos -idum 
       0      21       0

Y podemos ver como el formato cambió en MERGE_HEAD, también conocida como la otra rama, así que hagamos checkout de esa rama y veamos donde se rompió:

Listing 4.43:Ejercicio 8 - averiguando donde se rompió
$ git checkout -f exercise8/branchB 
Switched to branch ’exercise8/branchB’ 
$ git log --stat --pretty=%h primes.py 
491c86b 
 
 primes.py | 3 +++ 
 1 file changed, 3 insertions(+) 
ea81ba7 
 
 primes.py | 45 ++++++++++++++++++++++++--------------------- 
 1 file changed, 24 insertions(+), 21 deletions(-) 
55be073 
 
 primes.py | 21 +++++++++++++++++++++ 
 1 file changed, 21 insertions(+)

Y podemos ver que el archivo tuvo una modificacióngigante en la revisión ea81ba7. Asegurémonos:

Listing 4.44:Ejercicio 8 - asegurándonos
$ git show ea81ba7~:primes.py | unix2dos -idum 
       0      21       0 
$ git show ea81ba7:primes.py | unix2dos -idum 
      24       0       0

Y ahó lo podemos ver expuesto. En el ancestro de ea81ba7, eran saltos de linea NIX y en ea81ba7 se habían cambiado a DOS.

Utilicemos el script de la receta para coregir la rama. Primero, voy a colocar el script en el arbol de trabajo y luego voy a ejecutarlo:

Listing 4.45:Ejercicio 8 - corriendo el script
$ ./correct_eol.sh ea81ba7~ exercise8/branchB primes.py 
correct_eol.sh 
copyright 2020 Edmundo Carmona Antoranz 
Released under the terms of GPLv2 
file: primes.py EOL format: unix 
Checking out starting revision (55be073 Prime number calculation) 
Bringing over revision ea81ba7 (Check only already-known primes as divisors) 
 
Bringing over revision 491c86b (No need to check all divisors) 
 
Finished 
Check the results in the working tree and also the branch history with git log or gitk 
If you like the results, feel free to move the branch over here (for example, with ’git branch -f some-branch’)

Verifiquemos la historia de las ramas:

Listing 4.46:Ejercicio 8 - mirando la historia
$ git log --graph --oneline HEAD exercise8/branchA exercise8/branchB 
* fa1aca4 (HEAD) No need to check all divisors 
* 434aec2 Check only already-known primes as divisors 
| * 2be7601 (exercise8/branchA) Let’s go up to 10000 
|/ 
| * 491c86b (exercise8/branchB) No need to check all divisors 
| * ea81ba7 Check only already-known primes as divisors 
|/ 
* 55be073 Prime number calculation

Y podemos ver como HEAD y exercise8/branchB tienen historias análogas. Comparemos para verificar que el contenido es el mismo:

Listing 4.47:Ejercicio 8 - Comparando resultados
$ git diff -w HEAD exercise8/branchB 
$

Exactamente lo que queríamos. Ahora deberíamos mover la rama e intentar hacer el merge de nuevo. Voy a saltarme el paso de mover la rama y voy a proceder a hacer la mezcla sobre HEAD:

Listing 4.48:Ejercicio 8 - mezclando sobre HEAD
$ git merge exercise8/branchA 
Auto-merging primes.py 
Merge made by the ’recursive’ strategy. 
 primes.py | 2 +- 
 1 file changed, 1 insertion(+), 1 deletion(-)

Y podemos ver cómo en este caso la mezcla salió bien porque no había discrepancias de formato de EOL. Copyright 2020 Edmundo Carmona Antoranz