If the same utility script is checked in to different SCM directories yet should be the same everywhere, how can I verify they are the same?

Rob Fagen

Acknowledged that it's not a good situation, but sometimes you discover that the same utility scripts (or things like Makefiles) have been checked in to different directories within the same or different repositories for the same or different projects. They may have even been checked into inconsistently named directories or project directories resident at different levels of the source tree.

How can I find the files with the same name and (maybe) the same purpose that are living in different directories and easily discover which are the same, which are different and what the differences are?

Rob Fagen

For the Makefile example, let's say that someone is working alone on a new and improved variant, projectX, and has updated the Makefile to automate a formerly manual task. You're responsible for making sure that the rest of the older projects catch up, but someone might have already done some of the updates.

You could use the script below to run diffTree.sh Makefile and get output like this:

bash$ diffTree.sh Makefile
diff ./newprojects/projectX/Makefile ./projectB/Makefile
1,2d0
< CONFIGPARAM = "foo"
17c5
<       echo "I did that thing for you"
---
>       echo "You should do that thing"
diff ./projectB/Makefile ./projectC/Makefile
diff ./projectC/Makefile ./projectD/Makefile
end of files
bash$ _

This tells you that projectB and C and D are all identical, but newprojects/projectX/Makefile is different from B, and therefore also equally different from C and D.

If all the files in different locations with the same name are the same, you'll get something like this:

bash$ diffTree.sh sameFile.h
diff ./newprojects/projectX/src/headers/sameFile.h ./projectB/src/headers/sameFile.h
diff ./projectB/src/headers/sameFile.h ./projectC/src/headers/sameFile.h
diff ./projectC/src/headers/sameFile.h ./projectD/src/headers/sameFile.h
end of files
bash$ _

If you specify a filename that doesn't exist at all in the tree, you'll get:

bash$ diffTree.sh foo
end of files
bash$ _

Here's the script:

#!/usr/bin/env bash
set `find . -name $1 -print ; echo no files`
while [[ $# -gt 1 ]]
  do 
    if [[ $2 = no && $3 = files ]]
      then 
        shift
      else 
        echo diff $1 $2
        diff $1 $2
      fi
    shift
  done
echo end of files

It appears to handle wildcards in the filename, but there's probably something to be done to make that safer. Likewise, allowing for diff options like 'ignore whitespace' and so on would be an improvement.

Obviously, it totally breaks if you happen to have a file called 'no' and a second file called 'files' come up in the middle of the 'find' command's output, but since all the filenames are prefixed by './' and 'no' comes after 'files' alphabetically, I think it's safe enough.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I run two programs at the same time, but when they are in different directories? (Tcsh shell)

From Dev

How do I shim executables with the same names in different directories?

From Dev

How do I call templates with same names at different directories in Django?

From Dev

How can I copy a file and create the target directories at the same time?

From Dev

How can I verify that a list elements are in same order of another list or not?

From Dev

How to copy same file from different directories to different directories

From Dev

How can I use PowerShell to copy the same file to many directories with the same name?

From Dev

VirtualHost Same ServerName Different Directories

From Dev

How do I force-download different .pdfs in same script?

From Dev

can apache and rails run on the same server in different directories?

From Dev

Dagger 2 how to access same component everywhere

From Dev

How can two wrapper objects be equal, yet not equal at the same time

From Dev

how can the same item be undefined in one instance yet defined in another

From Dev

How can I run SSH as a different user on the same Ubuntu installation?

From Dev

How can I store the same data in two different mySQL tables?

From Dev

How can I use same methods in different classes type ArrayList?

From Dev

How can I declare same object name for different class?

From Dev

How can I distinguish different exceptions occured in the same try statement

From Dev

How can I test with rspec different routes but to the same controller method?

From Dev

How can I render the same texture with different colors?

From Dev

How can I publish the same collection with different subsets of data?

From Dev

How can I have different background colors in the same animation?

From Dev

How can I pass two different ID in same tabAdapter?

From Dev

How can I use the same Activity for different content in Android?

From Dev

Same hash keys, different value: how can I compare them?

From Dev

How can I set different sensitivities for two mice at the same time?

From Dev

How can I have different events for the same CustomInfoWindow

From Dev

How can I tell if the elements in an Array List are same or different?

From Dev

Same hash keys, different value: how can I compare them?

Related Related

  1. 1

    How can I run two programs at the same time, but when they are in different directories? (Tcsh shell)

  2. 2

    How do I shim executables with the same names in different directories?

  3. 3

    How do I call templates with same names at different directories in Django?

  4. 4

    How can I copy a file and create the target directories at the same time?

  5. 5

    How can I verify that a list elements are in same order of another list or not?

  6. 6

    How to copy same file from different directories to different directories

  7. 7

    How can I use PowerShell to copy the same file to many directories with the same name?

  8. 8

    VirtualHost Same ServerName Different Directories

  9. 9

    How do I force-download different .pdfs in same script?

  10. 10

    can apache and rails run on the same server in different directories?

  11. 11

    Dagger 2 how to access same component everywhere

  12. 12

    How can two wrapper objects be equal, yet not equal at the same time

  13. 13

    how can the same item be undefined in one instance yet defined in another

  14. 14

    How can I run SSH as a different user on the same Ubuntu installation?

  15. 15

    How can I store the same data in two different mySQL tables?

  16. 16

    How can I use same methods in different classes type ArrayList?

  17. 17

    How can I declare same object name for different class?

  18. 18

    How can I distinguish different exceptions occured in the same try statement

  19. 19

    How can I test with rspec different routes but to the same controller method?

  20. 20

    How can I render the same texture with different colors?

  21. 21

    How can I publish the same collection with different subsets of data?

  22. 22

    How can I have different background colors in the same animation?

  23. 23

    How can I pass two different ID in same tabAdapter?

  24. 24

    How can I use the same Activity for different content in Android?

  25. 25

    Same hash keys, different value: how can I compare them?

  26. 26

    How can I set different sensitivities for two mice at the same time?

  27. 27

    How can I have different events for the same CustomInfoWindow

  28. 28

    How can I tell if the elements in an Array List are same or different?

  29. 29

    Same hash keys, different value: how can I compare them?

HotTag

Archive