summaryrefslogtreecommitdiffstats
path: root/kpilot/Documentation/merge-into-svn.sh
blob: c012deed57a0dfcb60caf3db09f8b01838dd4a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
COPYTO=$1

if [ "x$COPYTO" = "x" ] || [ ! -d "$COPYTO" ]
then
  echo "$(basename $0) <directory to merge to>"
  exit 1
fi

STARTDIR=$(pwd)

COPYFILES=""
DELFILES=""
NEWFILES=""

function isversioned {
  F=$1
  svn info $F 2>&1 | grep Checksum > /dev/null
  rc=$?
  if [ $rc -eq 0 ]
  then
    echo 1
  else
    echo 0
  fi
}

function checkCopy {

echo "[-] Checking for files that need to be copied to: [$COPYTO]..."
echo "-----------------------------------------------------"

# first pass is to copy all files we care about from current to destination
for f in $(find . | egrep -vi \
"aap|build-|\.svn|\.libs|Makefile$|Makefile.in|~$|\.la$")
do
if [ -f $f ]; then
  F=$(printf "%-60s\n" $f)
  C=$(sum -r $f)
  O=$(sum -r $COPYTO/$f 2>/dev/null)
  if [ "$C" = "$O" ] ; then
    S="SAME"
  elif [ ! -f $COPYTO/$f ]; then
    S="NEW"
  else
    S="DIFF"
  fi

  if [ "$S" != "SAME" ]; then
    echo "file: [$F], status: [$S]"
    if [ "$S" = "DIFF" ]; then
      COPY="y"
    elif [ "$S" = "NEW" ] ; then
      V=$(isversioned $f)
      if [ "$V" -eq 0 ]; then
        echo " - new file, but not versioned, so ignoring."
	COPY="n"
      elif [ "$V" -eq 1 ]; then
        echo -n " - new file.  versioned. copy this one? (Y/N) -> "
        read ANS
        ANS=$(echo $ANS | tr '[A-Z]' '[a-z]')
        if [ "$ANS" = "y" ]; then
          COPY="y"
	  NEWFILES="$NEWFILES $f"
        else
          COPY="n"
        fi
      fi
    fi
    if [ "$COPY" = "y" ]; then
      echo "  - copying this file..."
      COPYFILES="$COPYFILES $f"
    else 
      echo "  - not copying it..."
    fi
  fi
fi
done
}

function checkDelete {

echo "[-] Checking for files that should be deleted from: [$COPYTO] ..."
echo "-----------------------------------------------------"

# now see if there's anything that was in dest, but is not in new and
# remove it
cd $COPYTO
for f in $(find . | egrep -vi \
"aap|build|.svn|.libs|Makefile|~$|lib/pilot-link|.la$|.deps|.moc$|.lo$|\.o$")
do
if [ -f $f ]; then
  F=$(printf "%-60s\n" $f)
  if [ ! -f $STARTDIR/$f ] ; then
    V=$(isversioned $f)
    if [ "$V" -eq 1 ]; then
      echo -n " - file: [$F] looks like it's been deleted. should I remove it?  (Y/N) -> "
      read ANS
      ANS=$(echo $ANS | tr '[A-Z]' '[a-z]')
      if [ "$ANS" = "y" ]; then
        echo "  - okay, I'll remove this one..."
        DELFILES="$DELFILES $f"
      fi
    fi
  fi
fi
done
}

checkCopy
checkDelete

cd "$STARTDIR"

echo "okay, here are the files that I'll copy:"
for f in $(echo $COPYFILES)
do
  echo " - $f"
done

echo "and here are the files that I'll do an svn remove on:"
for f in $(echo $DELFILES)
do
  echo " - $f"
done

echo "and here are the files that I'll do an svn add on:"
for f in $(echo $NEWFILES)
do
  echo " - $f"
done

echo -n "Okay to proceed? (y/n) -> "
read ANS
ANS=$(echo $ANS | tr '[A-Z]' '[a-z]')
if [ "$ANS" != "y" ]; then
  echo "  - okay, stopping."
  exit
fi

cd "$STARTDIR"

echo "okay, copying..."
for f in $(echo $COPYFILES)
do
  cp --parents -v "$f" "$COPYTO"
done

cd "$COPYTO"

echo "doing svn remove..."
for f in $(echo $DELFILES)
do
  echo " - $f"
  svn remove "$f"
done

cd "$COPYTO"

echo "doing svn add..."
for f in $(echo $NEWFILES)
do
  echo " - $f"
  svn add "$f"
done