Browse code

Improved refresh needed checker.

Nat! authored on 22-10-2016 19:57:02
Showing 8 changed files
... ...
@@ -27,6 +27,8 @@ Changes:
27 27
 
28 28
 * clarified the use of options vs. flags some more. e.g. git GITFLAGS command GITOPTIONS.
29 29
 * update will now also refresh
30
+* improved refresh check, should not properly detect edited config files if the
31
+edit is at least a second after the last refresh run. Death of the hidden -fr flag
30 32
 * start version checking bootstrap contents
31 33
 * -f flag will now also try to checkout branches, that are checked out
32 34
 incorrectly
... ...
@@ -35,6 +37,8 @@ incorrectly
35 37
 * use unexpanded URLs for dependency matches and store those into .bootstrap.auto
36 38
 * mulle-bootstrap now picks up URL changes and corrects them in fetched
37 39
 repositiories, but that does not per se force an update.
40
+* try to detect changes in .bootstrap better
41
+
38 42
 
39 43
 2.2.1
40 44
 ===
... ...
@@ -211,10 +211,6 @@ bootstrap_main()
211 211
             MULLE_BOOTSTRAP_DIRTY_HARRY="NO"
212 212
          ;;
213 213
 
214
-         -fr|--force-refresh)
215
-            MULLE_BOOTSTRAP_NEEDS_REFRESH="YES"
216
-         ;;
217
-
218 214
          -n|--dry-run)
219 215
             MULLE_EXECUTOR_DRY_RUN="YES"
220 216
          ;;
... ...
@@ -383,7 +379,7 @@ bootstrap_main()
383 379
    # some commands should refresh before execution
384 380
    # try to avoid pulling in the header if not needed
385 381
    #
386
-   if [ "${MULLE_BOOTSTRAP_NEEDS_REFRESH}" = "YES" ] || refresh_needed
382
+   if refresh_needed
387 383
    then
388 384
       case "${command}" in
389 385
          bootstrap|nomagic|fetch|update)
... ...
@@ -566,18 +566,24 @@ ensure_clone_url_is_correct()
566 566
    local remote
567 567
    local actual
568 568
 
569
-   remote="`git_get_default_remote "${dstdir}"`"
570
-   if [ -z "${remote}" ]
569
+   if git_is_repository "${dstdir}"
571 570
    then
572
-      fail "Could not figure out a remote for \"${dstdir}\""
573
-   fi
571
+      remote="`git_get_default_remote "${dstdir}"`"
572
+      if [ -z "${remote}" ]
573
+      then
574
+         fail "Could not figure out a remote for \"$PWD/${dstdir}\""
575
+      fi
574 576
 
575
-   actual="`git_get_url "${dstdir}" "${remote}"`"
576
-   if [ "${actual}" != "${url}" ]
577
-   then
578
-      log_verbose "URL change for $remote in \"${dstdir}\" from $actual to $url"
579
-      git_set_url "${dstdir}" "${remote}" "${url}"
577
+      actual="`git_get_url "${dstdir}" "${remote}"`"
578
+      if [ "${actual}" != "${url}" ]
579
+      then
580
+         log_verbose "URL change for $remote in \"$PWD/${dstdir}\" from $actual to $url"
581
+         git_set_url "${dstdir}" "${remote}" "${url}"
582
+      fi
583
+      return 0
580 584
    fi
585
+
586
+   return 1
581 587
 }
582 588
 
583 589
 
... ...
@@ -662,9 +668,10 @@ checkout_repository()
662 668
 
663 669
    if [ -e "${dstdir}" ]
664 670
    then
665
-      ensure_clone_url_is_correct "${dstdir}" "${url}"
666
-      ensure_clone_branch_is_correct "${dstdir}" "${branch}"
667
-
671
+      if ensure_clone_url_is_correct "${dstdir}" "${url}"
672
+      then
673
+         ensure_clone_branch_is_correct "${dstdir}" "${branch}"
674
+      fi
668 675
       log_fluff "Repository \"${dstdir}\" already exists"
669 676
    else
670 677
       if [ "${MULLE_BOOTSTRAP_IGNORE_GRAVEYARD}" != "YES" -a -d "${CLONESFETCH_SUBDIR}/.graveyard/${name}" ]
... ...
@@ -960,8 +967,11 @@ update_repository()
960 967
       fi
961 968
    fi
962 969
 
963
-   ensure_clone_url_is_correct "${dstdir}" "${url}"
964
-   ensure_clone_branch_is_correct "${dstdir}" "${branch}"
970
+   if ensure_clone_url_is_correct "${dstdir}" "${url}"
971
+   then
972
+      ensure_clone_branch_is_correct "${dstdir}" "${branch}"
973
+   fi
974
+
965 975
    [ $rval -eq 0 -o $rval -eq 2 ]
966 976
    return $?
967 977
 }
... ...
@@ -1267,9 +1277,10 @@ clone_embedded_repository()
1267 1277
       fi
1268 1278
 
1269 1279
    else
1270
-      ensure_clone_url_is_correct "${dstdir}" "${url}"
1271
-      ensure_clone_branch_is_correct "${dstdir}" "${branch}"
1272
-
1280
+      if ensure_clone_url_is_correct "${dstdir}" "${url}"
1281
+      then
1282
+         ensure_clone_branch_is_correct "${dstdir}" "${branch}"
1283
+      fi
1273 1284
       log_fluff "Repository \"${dstdir}\" already exists"
1274 1285
    fi
1275 1286
 
... ...
@@ -115,6 +115,12 @@ fetch_needed()
115 115
       return 0
116 116
    fi
117 117
 
118
+   if [ "${CLONESFETCH_SUBDIR}/.fetch_done" -ot "${BOOTSTRAP_SUBDIR}" ]
119
+   then
120
+      log_fluff "Need fetch because \"${BOOTSTRAP_SUBDIR}\" is modified"
121
+      return 0
122
+   fi
123
+
118 124
    return 1
119 125
 }
120 126
 
... ...
@@ -123,39 +129,35 @@ refresh_needed()
123 129
 {
124 130
    if [ ! -d "${BOOTSTRAP_SUBDIR}.auto" ]
125 131
    then
126
-     log_fluff "Need refresh because ${BOOTSTRAP_SUBDIR}.auto does not exist."
132
+     log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}.auto\" does not exist."
127 133
      return 0
128 134
    fi
129 135
 
130 136
    if [ ! -f "${CLONESFETCH_SUBDIR}/.refresh_done" ]
131 137
    then
132
-      log_fluff "Need refresh because ${CLONESFETCH_SUBDIR}/.refresh_done does not exist."
138
+      log_fluff "Need refresh because \"${CLONESFETCH_SUBDIR}/.refresh_done\" does not exist."
133 139
       return 0
134 140
    fi
135 141
 
136
-   if [ "${CLONESFETCH_SUBDIR}/.refresh_done" -ot "${BOOTSTRAP_SUBDIR}/embedded_repositories" ]
142
+   if [ ! -z "`find "${BOOTSTRAP_SUBDIR}" -newer "${CLONESFETCH_SUBDIR}/.refresh_done" 2> /dev/null`" ]
137 143
    then
138
-      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}/embedded_repositories\" is modified"
144
+      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}\" is modified"
139 145
       return 0
140 146
    fi
141 147
 
142
-   if [ "${CLONESFETCH_SUBDIR}/.refresh_done" -ot "${BOOTSTRAP_SUBDIR}/repositories" ]
148
+   if [ ! -z "`find "${BOOTSTRAP_SUBDIR}.local" -newer "${CLONESFETCH_SUBDIR}/.refresh_done" 2> /dev/null`" ]
143 149
    then
144
-      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}/repositories\" is modified"
150
+      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}.local\" is modified"
145 151
       return 0
146 152
    fi
147 153
 
148
-   if [ "${CLONESFETCH_SUBDIR}/.refresh_done" -ot "${BOOTSTRAP_SUBDIR}.local/embedded_repositories" ]
154
+   if [ ! -z "`find "${CLONESFETCH_SUBDIR}"/*/"${BOOTSTRAP_SUBDIR}" -newer "${CLONESFETCH_SUBDIR}/.refresh_done" 2> /dev/null`" ]
149 155
    then
150
-      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}.local/embedded_repositories\" is modified"
156
+      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}.local\" is modified"
151 157
       return 0
152 158
    fi
153 159
 
154
-   if [ "${CLONESFETCH_SUBDIR}/.refresh_done" -ot "${BOOTSTRAP_SUBDIR}.local/repositories" ]
155
-   then
156
-      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}.local/repositories\" is modified"
157
-      return 0
158
-   fi
160
+   log_fluff "No refresh needed."
159 161
 
160 162
    return 1
161 163
 }
... ...
@@ -495,14 +495,14 @@ _refresh_embedded_repositories()
495 495
       local dstdir
496 496
       local olddir
497 497
 
498
+      ensure_clones_directory
499
+
498 500
       IFS="
499 501
 "
500 502
       for clone in ${clones}
501 503
       do
502 504
          IFS="${DEFAULT_IFS}"
503 505
 
504
-         ensure_clones_directory
505
-
506 506
          __parse_embedded_clone "${clone}"
507 507
 
508 508
          olddir="`find_embedded_repository_subdir_in_repos "${url}"`"
... ...
@@ -30,14 +30,19 @@
30 30
 #
31 31
 MULLE_BOOTSTRAP_SCM_SH="included"
32 32
 
33
+git_is_repository()
34
+{
35
+   [ -d "${dstdir}.git" ] || [ -d  "${dstdir}/refs" -a  -f "${dstdir}/HEAD" ]
36
+}
37
+
33 38
 
34 39
 git_is_bare_repository()
35 40
 {
36 41
    local is_bare
37 42
 
38
-       # if bare repo, we can only clone anyway
39
-    is_bare=`( cd "$1"; git rev-parse --is-bare-repository 2> /dev/null )`
40
-    [ "${is_bare}" = "true" ]
43
+   # if bare repo, we can only clone anyway
44
+   is_bare=`( cd "$1"; git rev-parse --is-bare-repository 2> /dev/null )`
45
+   [ "${is_bare}" = "true" ]
41 46
 }
42 47
 
43 48
 
... ...
@@ -140,7 +145,7 @@ git_checkout_tag()
140 145
 
141 146
    if [ "${branch}" != "${tag}" ]
142 147
    then
143
-      log_info "Checking out version ${C_WHITE}${C_BOLD}${tag}${C_INFO} of ${C_MAGENTA}${C_BOLD}${dst}${C_INFO} ..."
148
+      log_info "Checking out version ${C_RESET_BOLD}${tag}${C_INFO} of ${C_MAGENTA}${C_BOLD}${dst}${C_INFO} ..."
144 149
       ( exekutor cd "${dst}" ; exekutor git ${GITFLAGS} checkout ${options} "${tag}" )
145 150
 
146 151
       if [ $? -ne 0 ]
... ...
@@ -59,6 +59,8 @@ fail()
59 59
 }
60 60
 
61 61
 
62
+BOOTSTRAP_FLAGS="$@"
63
+
62 64
 setup
63 65
 
64 66
 echo ""
... ...
@@ -69,7 +71,7 @@ echo ""
69 71
 
70 72
 (
71 73
    cd c ;
72
-   mulle-bootstrap fetch
74
+   mulle-bootstrap ${BOOTSTRAP_FLAGS} fetch
73 75
 
74 76
    [ -d src/b_1 ] || fail "b as src/b_1 failed to be embedded"
75 77
    [ -d src/b_1/src/a_1 ] && fail "a was wrongly embedded"
... ...
@@ -82,15 +84,15 @@ echo "=== test 1 done ==="
82 84
 echo ""
83 85
 echo ""
84 86
 
85
-
86 87
 (
87 88
    cd c ;
89
+   sleep 1 ;
88 90
    echo "../b;src/b_2" > .bootstrap/embedded_repositories ;
89
-   mulle-bootstrap fetch
91
+   mulle-bootstrap ${BOOTSTRAP_FLAGS} fetch
90 92
    [ -d src/b_1 ] && fail "b as src/b_1 failed to be removed"
91 93
    [ -d src/b_2 ] || fail "b as src/b_2 failed to be added"
92 94
    :
93
-) || exit 1 
95
+) || exit 1
94 96
 
95 97
 echo ""
96 98
 echo ""
... ...
@@ -101,10 +103,10 @@ echo ""
101 103
 
102 104
 (
103 105
    cd d ;
104
-   mulle-bootstrap -a fetch
106
+   mulle-bootstrap -a ${BOOTSTRAP_FLAGS} fetch
105 107
    [ -d .repos/c/src/b_1 ] || fail "b as .repos/c/src/b_1 failed to be fetched"
106 108
    :
107
-) || exit 1 
109
+) || exit 1
108 110
 
109 111
 echo ""
110 112
 echo ""
... ...
@@ -115,8 +117,9 @@ echo ""
115 117
 
116 118
 (
117 119
    cd d ;
120
+   sleep 1 ;
118 121
    echo "../b;src/b_2" > .repos/c/.bootstrap/embedded_repositories ;
119
-   mulle-bootstrap -vvv fetch
122
+   mulle-bootstrap ${BOOTSTRAP_FLAGS} fetch
120 123
    [ -d .repos/c/src/b_1 ] && fail "b as .repos/c/src/b_1 failed to be removed"
121 124
    [ -d .repos/c/src/b_2 ] || fail "b as .repos/c/src/b_2 failed to be added"
122 125
    :
123 126
old mode 100644
124 127
new mode 100755
... ...
@@ -1,6 +1,16 @@
1 1
 #! /bin/sh
2 2
 
3
-( cd "dependency" ; ./run-test.sh )
4
-( cd "refresh" ; ./run-test.sh )
5
-( cd "refresh-embedded" ; ./run-test.sh )
3
+main()
4
+{
5
+   local i
6 6
 
7
+   for i in *
8
+   do
9
+      if [ -x "$i/run-test.sh" ]
10
+      then
11
+         "./$i/run-test.sh" "$@" || exit 1
12
+      fi
13
+   done
14
+}
15
+
16
+main "$@"