Browse code

Improve tag and git

Nat! authored on 14-10-2016 13:54:22
Showing 6 changed files
... ...
@@ -1,3 +1,16 @@
1
+2.2
2
+===
3
+
4
+* `mulle-bootstrap tag` will now also tag embedded repositories
5
+* `mulle-bootstrap git` will now also grace embedded repositories, so `mulle-bootstrap git status -s` is now better
6
+* reworked tag to be more aware of git flags, so `mulle-bootstrap tag -l` now
7
+works
8
+
9
+2.1.4
10
+===
11
+
12
+* use a safer but uglier method to append to .gitignore
13
+
1 14
 2.1.3
2 15
 ===
3 16
 
... ...
@@ -34,7 +47,7 @@ installed in `/usr/local` already, need not be fetched again. This can
34 47
 be helpful, when building brew packages (for example). (**-nb**)
35 48
 
36 49
 Support for `mulle-build` which has an in general more optimistic approach to
37
-life. 2.2 will focus on making operations faster in the Windows bash shell.
50
+life. 2.3 will focus on making operations faster in the Windows bash shell.
38 51
 
39 52
 ### Commands
40 53
 
... ...
@@ -29,7 +29,7 @@
29 29
 #   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 30
 #   POSSIBILITY OF SUCH DAMAGE.
31 31
 
32
-MULLE_BOOTSTRAP_VERSION="2.1.3"
32
+MULLE_BOOTSTRAP_VERSION="2.2"
33 33
 
34 34
 #
35 35
 # This is the main user interface to mulle-bootstrap
... ...
@@ -1094,9 +1094,13 @@ append_dir_to_gitignore_if_needed()
1094 1094
 
1095 1095
    fgrep -s -x -e "${directory}" -e "${pattern1}" -e "${pattern2}" -e "${pattern3}" .gitignore > /dev/null 2>&1
1096 1096
 
1097
+   #
1098
+   # prepend \n because it is safer, in case .gitignore has no trailing
1099
+   # LF which it often seems to not have
1100
+   #
1097 1101
    if [ $? -ne 0 ]
1098 1102
    then
1099
-      redirect_append_exekutor .gitignore echo "${directory}" || fail "Couldn\'t append to .gitignore"
1103
+      redirect_append_exekutor .gitignore echo "\n${directory}" || fail "Couldn\'t append to .gitignore"
1100 1104
       log_info "Added \"${directory}\" to \".gitignore\""
1101 1105
    fi
1102 1106
 }
... ...
@@ -269,6 +269,18 @@ repository_directories_from_repos()
269 269
 }
270 270
 
271 271
 
272
+# dstprefix
273
+all_repository_directories_from_repos()
274
+{
275
+   local dstprefix
276
+
277
+   dstprefix="$1"
278
+
279
+   repository_directories_from_repos
280
+   embedded_repository_directories_from_repos "${dstprefix}"
281
+}
282
+
283
+
272 284
 # this sets valuse to variables that should be declared
273 285
 # in the caller!
274 286
 #
... ...
@@ -165,7 +165,6 @@ svn_checkout()
165 165
    [ ! -z "$src" ] || internal_fail "src is empty"
166 166
    [ ! -z "$dst" ] || internal_fail "dst is empty"
167 167
 
168
-
169 168
    if [ ! -z "${branch}" ]
170 169
    then
171 170
       log_info "SVN checkout ${C_RESET_BOLD}${branch}${C_INFO} of ${C_MAGENTA}${C_BOLD}${src}${C_INFO} ..."
... ...
@@ -180,7 +179,6 @@ svn_checkout()
180 179
       fi
181 180
    fi
182 181
 
183
-
184 182
    exekutor svn checkout ${flags} ${SVNFLAGS} "${src}" "${dst}" || fail "svn clone of \"${src}\" into \"${dst}\" failed"
185 183
 }
186 184
 
... ...
@@ -218,26 +216,24 @@ svn_update()
218 216
 
219 217
 run_git()
220 218
 {
221
-   local clonesdir
222
-
223
-   clonesdir="$1"
224
-   [ $# -eq 0 ] || shift
225
-
226 219
    local i
220
+   local name
227 221
 
228
-   for i in "${clonesdir}"/*
222
+   IFS="
223
+"
224
+   for i in `all_repository_directories_from_repos`
229 225
    do
230
-      if [ -d "$i" ]
226
+      IFS="${DEFAULT_IFS}"
227
+
228
+      if [ -d "${i}/.git" -o -d "${i}/refs" ]
231 229
       then
232
-         if [ -d "${i}/.git" -o -d "${i}/refs" ]
233
-         then
234
-            log_info "### $i:"
235
-            (cd "$i" ; exekutor git ${GITFLAGS} "$@" ) || fail "git failed"
236
-            log_info
237
-         fi
230
+         log_info "### $i:"
231
+         (cd "$i" ; exekutor git ${GITFLAGS} "$@" ) || fail "git failed"
232
+         log_info
238 233
       fi
239 234
    done
240 235
 
236
+   IFS="${DEFAULT_IFS}"
241 237
 }
242 238
 
243 239
 
... ...
@@ -267,7 +263,7 @@ git_main()
267 263
       return 0
268 264
    fi
269 265
 
270
-   run_git "${CLONES_SUBDIR}" "$@"
266
+   run_git "$@"
271 267
 }
272 268
 
273 269
 
... ...
@@ -275,6 +271,7 @@ scm_initialize()
275 271
 {
276 272
    log_fluff ":scm_initialize:"
277 273
    [ -z "${MULLE_BOOTSTRAP_FUNCTIONS_SH}" ] && . mulle-bootstrap-functions.sh
274
+   [ -z "${MULLE_BOOTSTRAP_REPOSITORIES_SH}" ] && . mulle-bootstrap-repositories.sh
278 275
 }
279 276
 
280 277
 scm_initialize
... ...
@@ -40,12 +40,13 @@ tag_usage()
40 40
 {
41 41
    cat <<EOF >&2
42 42
 usage:
43
-   mulle-bootstrap tag [-f] <tag>
43
+   mulle-bootstrap tag [options] <tag>
44 44
 
45
-   -d           : delete tag
46
-   -f           : force tag
45
+   Options:
46
+      -d   : delete tag
47
+      -f   : force tag
47 48
 
48
-   tag          : the tag for your fetched repositories
49
+      tag  : the tag for your fetched repositories
49 50
 EOF
50 51
    exit 1
51 52
 }
... ...
@@ -101,80 +102,89 @@ git_must_be_clean()
101 102
 
102 103
 ensure_repos_clean()
103 104
 {
104
-   local clonesdir
105
-
106
-   clonesdir="$1"
107
-
108 105
    #
109 106
    # Make sure that tagging is OK
110 107
    # all git repos must be clean
111 108
    #
112
-   if dir_has_files "${clonesdir}"
113
-   then
114
-      for i in "${clonesdir}"/*
115
-      do
116
-         # only tag what looks like a git repo
117
-         if [ -d "${i}/.git" -o -d "${i}/refs" ]
118
-         then
119
-            (cd "${i}" ; git_must_be_clean "${i}" ) || exit 1
120
-         fi
121
-      done
122
-   fi
109
+   local i
110
+
111
+   IFS="
112
+"
113
+   for i in `all_repository_directories_from_repos`
114
+   do
115
+      IFS="${DEFAULT_IFS}"
116
+
117
+      # only tag what looks like a git repo
118
+      if [ -d "${i}/.git" -o -d "${i}/refs" ]
119
+      then
120
+         (cd "${i}" ; git_must_be_clean "${i}" ) || exit 1
121
+      fi
122
+   done
123
+   IFS="${DEFAULT_IFS}"
123 124
 }
124 125
 
125 126
 
126 127
 ensure_tags_unknown()
127 128
 {
128 129
    local tag
129
-   local clonesdir
130 130
 
131
-   clonesdir="$1"
132
-   tag="$2"
131
+   tag="$1"
133 132
 
134 133
    #
135 134
    # Make sure that tagging is OK
136 135
    # all git repos must be clean
137 136
    #
138
-   if dir_has_files "${clonesdir}"
139
-   then
140
-      for i in "${clonesdir}"/*
141
-      do
142
-         # only tag what looks like a git repo
143
-         if [ -d "${i}/.git" -o -d "${i}/refs" ]
144
-         then
145
-            (cd "${i}" ; git_tag_unknown "${i}" "${tag}" ) || exit 1
146
-         fi
147
-      done
148
-   fi
137
+   local i
138
+
139
+   IFS="
140
+"
141
+   for i in `all_repository_directories_from_repos`
142
+   do
143
+      IFS="${DEFAULT_IFS}"
144
+
145
+      # only tag what looks like a git repo
146
+      # make it scm_tag sometimes
147
+      if [ -d "${i}/.git" -o -d "${i}/refs" ]
148
+      then
149
+         (cd "${i}" ; git_tag_unknown "${i}" "${tag}" ) || exit 1
150
+      fi
151
+   done
152
+
153
+   IFS="${DEFAULT_IFS}"
149 154
 }
150 155
 
151 156
 
152 157
 tag()
153 158
 {
154
-   local clonesdir
155 159
    local tag
156 160
 
157
-   clonesdir="$1"
158
-   [ $# -eq 0 ] || shift
159 161
    tag="$1"
160 162
    [ $# -eq 0 ] || shift
161 163
 
162 164
    local i
165
+   local name
163 166
 
164
-   if dir_has_files "${clonesdir}"
165
-   then
166
-      for i in "${clonesdir}"/*
167
-      do
168
-         if [ -d "$i" ]
167
+   IFS="
168
+"
169
+   for i in `all_repository_directories_from_repos`
170
+   do
171
+      IFS="${DEFAULT_IFS}"
172
+
173
+      if [ -d "${i}/.git" -o -d "${i}/refs" ]
174
+      then
175
+         name="`basename -- "${i}"`"
176
+         if [ -z "${tag}" ]
169 177
          then
170
-            if [ -d "${i}/.git" -o -d "${i}/refs" ]
171
-            then
172
-               log_info "Tagging \"`basename -- "${i}"`\" with \"${tag}\""
173
-               (cd "$i" ; exekutor git tag $GITFLAGS "$@" "${tag}" ) || fail "tag failed"
174
-            fi
178
+            log_info "### ${name}:"
179
+            (cd "$i" ; exekutor git tag $GITFLAGS "$@" ) || fail "tag failed"
180
+         else
181
+            log_info "Tagging \"${name}\" with \"${tag}\""
182
+            (cd "$i" ; exekutor git tag $GITFLAGS "$@" "${tag}" ) || fail "tag failed"
175 183
          fi
176
-      done
177
-   fi
184
+      fi
185
+   done
186
+
187
+   IFS="${DEFAULT_IFS}"
178 188
 }
179 189
 
180 190
 
... ...
@@ -184,50 +194,75 @@ tag_main()
184 194
 
185 195
    [ -z "${MULLE_BOOTSTRAP_LOCAL_ENVIRONMENT_SH}" ] && . mulle-bootstrap-local-environment.sh
186 196
    [ -z "${MULLE_BOOTSTRAP_SCRIPTS_SH}" ] && . mulle-bootstrap-scripts.sh
197
+   [ -z "${MULLE_BOOTSTRAP_REPOSITORIES_SH}" ] && . mulle-bootstrap-repositories.sh
187 198
 
188 199
    GITFLAGS=
189 200
    TAG_OPERATION="tag"
190 201
 
191
-   while :
202
+   while [ $# -ne 0 ]
192 203
    do
193
-      if [ "$1" = "-h" -o "$1" = "--help" ]
204
+      case "$1" in
205
+         -h|--help)
206
+            tag_usage
207
+         ;;
208
+
209
+         -f|--force)
210
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
211
+            TAG_OPERATION="force tag"
212
+         ;;
213
+
214
+         -l|--list|-v|--verify)
215
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
216
+            TAG_OPERATION="list/verify tags"
217
+            UNCLEAN_OK=YES
218
+         ;;
219
+
220
+         -d|--delete)
221
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
222
+            TAG_OPERATION="delete the tag of"
223
+         ;;
224
+
225
+         # no argument gitflags
226
+         -n|-a|--annotate|-s|--sign|-create-reflog|--column)
227
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
228
+         ;;
229
+         # argument gitflags
230
+         -*)
231
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
232
+            shift
233
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
234
+         ;;
235
+
236
+         *)
237
+            break
238
+         ;;
239
+      esac
240
+
241
+      shift
242
+   done
243
+
244
+
245
+   if [ -z "${UNCLEAN_OK}" ]
246
+   then
247
+      TAG=$1
248
+      [ $# -eq 0 ] || shift
249
+
250
+      if [ -z "${TAG}" ]
194 251
       then
195 252
          tag_usage
196 253
       fi
197 254
 
198
-      if [ "$1" = "-f" ]
255
+      if [ -z "${GITFLAGS}" ]
199 256
       then
200
-         GITFLAGS="${GITFLAGS} $1"
201
-         TAG_OPERATION="force tag"
202
-         [ $# -eq 0 ] || shift
203
-         continue
257
+         ensure_tags_unknown "${TAG}"
204 258
       fi
205 259
 
206
-      if [ "$1" = "-d" ]
260
+      # clumsy compare
261
+      if [ "${TAG_OPERATION}" != "delete the tag of" ]
207 262
       then
208
-         GITFLAGS="${GITFLAGS} $1"
209
-         TAG_OPERATION="delete the tag of"
210
-         [ $# -eq 0 ] || shift
211
-         continue
263
+         ensure_repos_clean
212 264
       fi
213
-
214
-      break
215
-   done
216
-
217
-
218
-   TAG=$1
219
-   [ $# -eq 0 ] || shift
220
-
221
-   if [ -z "${TAG}" ]
222
-   then
223
-      tag_usage
224
-   fi
225
-
226
-   if [ -z "${GITFLAGS}" ]
227
-   then
228
-      ensure_tags_unknown "${CLONES_SUBDIR}" "${TAG}"
229 265
    fi
230
-   ensure_repos_clean "${CLONES_SUBDIR}"
231 266
 
232 267
    if dir_has_files "${CLONES_SUBDIR}"
233 268
    then
... ...
@@ -239,7 +274,7 @@ tag_main()
239 274
 
240 275
    fetch__run_fetch_settings_script "pre-tag"
241 276
 
242
-   tag "${CLONES_SUBDIR}" "${TAG}" "$@"
277
+   tag "${TAG}" "$@"
243 278
 
244 279
    fetch__run_fetch_settings_script "pre-tag"
245 280
 }