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 34
 be helpful, when building brew packages (for example). (**-nb**)
35 35
 
36 36
 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.
37
+life. 2.3 will focus on making operations faster in the Windows bash shell.
38 38
 
39 39
 ### Commands
40 40
 
... ...
@@ -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 180
       fi
181 181
    fi
182 182
 
183
-
184 183
    exekutor svn checkout ${flags} ${SVNFLAGS} "${src}" "${dst}" || fail "svn clone of \"${src}\" into \"${dst}\" failed"
185 184
 }
186 185
 
... ...
@@ -218,26 +216,24 @@ svn_update()
218 218
 
219 219
 run_git()
220 220
 {
221
-   local clonesdir
222
-
223
-   clonesdir="$1"
224
-   [ $# -eq 0 ] || shift
225
-
226 221
    local i
222
+   local name
227 223
 
228
-   for i in "${clonesdir}"/*
224
+   IFS="
225
+"
226
+   for i in `all_repository_directories_from_repos`
229 227
    do
230
-      if [ -d "$i" ]
228
+      IFS="${DEFAULT_IFS}"
229
+
230
+      if [ -d "${i}/.git" -o -d "${i}/refs" ]
231 231
       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
232
+         log_info "### $i:"
233
+         (cd "$i" ; exekutor git ${GITFLAGS} "$@" ) || fail "git failed"
234
+         log_info
238 235
       fi
239 236
    done
240 237
 
238
+   IFS="${DEFAULT_IFS}"
241 239
 }
242 240
 
243 241
 
... ...
@@ -267,7 +263,7 @@ git_main()
267 267
       return 0
268 268
    fi
269 269
 
270
-   run_git "${CLONES_SUBDIR}" "$@"
270
+   run_git "$@"
271 271
 }
272 272
 
273 273
 
... ...
@@ -275,6 +271,7 @@ scm_initialize()
275 275
 {
276 276
    log_fluff ":scm_initialize:"
277 277
    [ -z "${MULLE_BOOTSTRAP_FUNCTIONS_SH}" ] && . mulle-bootstrap-functions.sh
278
+   [ -z "${MULLE_BOOTSTRAP_REPOSITORIES_SH}" ] && . mulle-bootstrap-repositories.sh
278 279
 }
279 280
 
280 281
 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 101
 
102 102
 ensure_repos_clean()
103 103
 {
104
-   local clonesdir
105
-
106
-   clonesdir="$1"
107
-
108 104
    #
109 105
    # Make sure that tagging is OK
110 106
    # all git repos must be clean
111 107
    #
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
108
+   local i
109
+
110
+   IFS="
111
+"
112
+   for i in `all_repository_directories_from_repos`
113
+   do
114
+      IFS="${DEFAULT_IFS}"
115
+
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
+   IFS="${DEFAULT_IFS}"
123 123
 }
124 124
 
125 125
 
126 126
 ensure_tags_unknown()
127 127
 {
128 128
    local tag
129
-   local clonesdir
130 129
 
131
-   clonesdir="$1"
132
-   tag="$2"
130
+   tag="$1"
133 131
 
134 132
    #
135 133
    # Make sure that tagging is OK
136 134
    # all git repos must be clean
137 135
    #
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
136
+   local i
137
+
138
+   IFS="
139
+"
140
+   for i in `all_repository_directories_from_repos`
141
+   do
142
+      IFS="${DEFAULT_IFS}"
143
+
144
+      # only tag what looks like a git repo
145
+      # make it scm_tag sometimes
146
+      if [ -d "${i}/.git" -o -d "${i}/refs" ]
147
+      then
148
+         (cd "${i}" ; git_tag_unknown "${i}" "${tag}" ) || exit 1
149
+      fi
150
+   done
151
+
152
+   IFS="${DEFAULT_IFS}"
149 153
 }
150 154
 
151 155
 
152 156
 tag()
153 157
 {
154
-   local clonesdir
155 158
    local tag
156 159
 
157
-   clonesdir="$1"
158
-   [ $# -eq 0 ] || shift
159 160
    tag="$1"
160 161
    [ $# -eq 0 ] || shift
161 162
 
162 163
    local i
164
+   local name
163 165
 
164
-   if dir_has_files "${clonesdir}"
165
-   then
166
-      for i in "${clonesdir}"/*
167
-      do
168
-         if [ -d "$i" ]
166
+   IFS="
167
+"
168
+   for i in `all_repository_directories_from_repos`
169
+   do
170
+      IFS="${DEFAULT_IFS}"
171
+
172
+      if [ -d "${i}/.git" -o -d "${i}/refs" ]
173
+      then
174
+         name="`basename -- "${i}"`"
175
+         if [ -z "${tag}" ]
169 176
          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
177
+            log_info "### ${name}:"
178
+            (cd "$i" ; exekutor git tag $GITFLAGS "$@" ) || fail "tag failed"
179
+         else
180
+            log_info "Tagging \"${name}\" with \"${tag}\""
181
+            (cd "$i" ; exekutor git tag $GITFLAGS "$@" "${tag}" ) || fail "tag failed"
175 182
          fi
176
-      done
177
-   fi
183
+      fi
184
+   done
185
+
186
+   IFS="${DEFAULT_IFS}"
178 187
 }
179 188
 
180 189
 
... ...
@@ -184,50 +194,75 @@ tag_main()
184 184
 
185 185
    [ -z "${MULLE_BOOTSTRAP_LOCAL_ENVIRONMENT_SH}" ] && . mulle-bootstrap-local-environment.sh
186 186
    [ -z "${MULLE_BOOTSTRAP_SCRIPTS_SH}" ] && . mulle-bootstrap-scripts.sh
187
+   [ -z "${MULLE_BOOTSTRAP_REPOSITORIES_SH}" ] && . mulle-bootstrap-repositories.sh
187 188
 
188 189
    GITFLAGS=
189 190
    TAG_OPERATION="tag"
190 191
 
191
-   while :
192
+   while [ $# -ne 0 ]
192 193
    do
193
-      if [ "$1" = "-h" -o "$1" = "--help" ]
194
+      case "$1" in
195
+         -h|--help)
196
+            tag_usage
197
+         ;;
198
+
199
+         -f|--force)
200
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
201
+            TAG_OPERATION="force tag"
202
+         ;;
203
+
204
+         -l|--list|-v|--verify)
205
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
206
+            TAG_OPERATION="list/verify tags"
207
+            UNCLEAN_OK=YES
208
+         ;;
209
+
210
+         -d|--delete)
211
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
212
+            TAG_OPERATION="delete the tag of"
213
+         ;;
214
+
215
+         # no argument gitflags
216
+         -n|-a|--annotate|-s|--sign|-create-reflog|--column)
217
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
218
+         ;;
219
+         # argument gitflags
220
+         -*)
221
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
222
+            shift
223
+            GITFLAGS="`concat "${GITFLAGS}" "$1"`"
224
+         ;;
225
+
226
+         *)
227
+            break
228
+         ;;
229
+      esac
230
+
231
+      shift
232
+   done
233
+
234
+
235
+   if [ -z "${UNCLEAN_OK}" ]
236
+   then
237
+      TAG=$1
238
+      [ $# -eq 0 ] || shift
239
+
240
+      if [ -z "${TAG}" ]
194 241
       then
195 242
          tag_usage
196 243
       fi
197 244
 
198
-      if [ "$1" = "-f" ]
245
+      if [ -z "${GITFLAGS}" ]
199 246
       then
200
-         GITFLAGS="${GITFLAGS} $1"
201
-         TAG_OPERATION="force tag"
202
-         [ $# -eq 0 ] || shift
203
-         continue
247
+         ensure_tags_unknown "${TAG}"
204 248
       fi
205 249
 
206
-      if [ "$1" = "-d" ]
250
+      # clumsy compare
251
+      if [ "${TAG_OPERATION}" != "delete the tag of" ]
207 252
       then
208
-         GITFLAGS="${GITFLAGS} $1"
209
-         TAG_OPERATION="delete the tag of"
210
-         [ $# -eq 0 ] || shift
211
-         continue
253
+         ensure_repos_clean
212 254
       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 255
    fi
230
-   ensure_repos_clean "${CLONES_SUBDIR}"
231 256
 
232 257
    if dir_has_files "${CLONES_SUBDIR}"
233 258
    then
... ...
@@ -239,7 +274,7 @@ tag_main()
239 239
 
240 240
    fetch__run_fetch_settings_script "pre-tag"
241 241
 
242
-   tag "${CLONES_SUBDIR}" "${TAG}" "$@"
242
+   tag "${TAG}" "$@"
243 243
 
244 244
    fetch__run_fetch_settings_script "pre-tag"
245 245
 }