ignoring mac's .DS_Store items now.
[feisty_meow.git] / scripts / rev_control / svn_rm_dupes.sh
1 #!/bin/bash
2
3 # whacks the files in the current directory which are duplicates of the
4 # files in the directory passed as a parameter.
5 # if there is a second parameter, then it is used as the "current directory".
6
7 exemplar_dir="$1"; shift
8 whack_dir="$1"; shift
9
10 #hmmm: much code here is shared with whack_dupes.  get into a library.
11
12 # make sure they gave us a good directory to start with.
13 if [ -z "$exemplar_dir" ]; then
14   echo "whack_dupes"
15   echo "-----------"
16   echo ""
17   echo "This program needs at least one directory parameter.  The files in the"
18   echo "current directory will be removed if a file in the specified directory"
19   echo "already exists.  So... the current directory is the less important one"
20   echo "and is presumed to have duplicates AND the directory given as parameter"
21   echo "is considered important and has the best versions of the files."
22   echo "If there is an optional second parameter, then that is used as the"
23   echo "\"current\" directory where we start from; it will be the less important"
24   echo "directory and will have its entries cleaned if they're duplicates."
25   exit 42;
26 fi
27
28 # check to make sure they gave us a good directory.
29 if [ ! -z "$whack_dir" -a ! -d "$whack_dir" ]; then
30   echo "the directory $whack_dir does not exist."
31   exit 3
32 fi
33
34 # test the tasty remote location with the better contents.
35 pushd "$exemplar_dir" &>/dev/null
36 if [ $? -ne 0 ]; then
37   # an error getting to this directory means its no good for us.
38   echo "the directory $exemplar_dir is inaccessible."
39   exit 2
40 fi
41 the_good_place="$(pwd)"
42 popd &>/dev/null
43
44 if [ ! -z "$whack_dir" ]; then
45   # use the directory as our "current" location.
46   pushd "$whack_dir" &>/dev/null
47 fi
48
49 # now that we're in the directory to clean, make sure we're good there.
50 if [ ! -d ".svn" ]; then
51 #  echo "Could not find a subversion directory; operation would be pointless."
52   exit 0
53 fi
54
55 current_dir="$(pwd)"
56
57 #echo "currdir=$current_dir gooddir=$the_good_place"
58
59 if [ "$current_dir" == "$the_good_place" ]; then
60   # this is not good; they're the same location.
61   echo "the request would whack all the files in the current directory; ignoring."
62   exit 4
63 fi
64
65 # do the real work now...
66 for i in *; do
67   if [ -f "$exemplar_dir/$i" ]; then
68     echo "whacking $i"
69     svn rm "$i"
70   fi
71 done
72
73 if [ ! -z "$whack_dir" ]; then
74   popd &>/dev/null
75 fi
76