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 35
 * use unexpanded URLs for dependency matches and store those into .bootstrap.auto
36 36
 * mulle-bootstrap now picks up URL changes and corrects them in fetched
37 37
 repositiories, but that does not per se force an update.
38
+* try to detect changes in .bootstrap better
39
+
38 40
 
39 41
 2.2.1
40 42
 ===
... ...
@@ -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 383
    # some commands should refresh before execution
384 384
    # try to avoid pulling in the header if not needed
385 385
    #
386
-   if [ "${MULLE_BOOTSTRAP_NEEDS_REFRESH}" = "YES" ] || refresh_needed
386
+   if refresh_needed
387 387
    then
388 388
       case "${command}" in
389 389
          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 662
 
663 663
    if [ -e "${dstdir}" ]
664 664
    then
665
-      ensure_clone_url_is_correct "${dstdir}" "${url}"
666
-      ensure_clone_branch_is_correct "${dstdir}" "${branch}"
667
-
665
+      if ensure_clone_url_is_correct "${dstdir}" "${url}"
666
+      then
667
+         ensure_clone_branch_is_correct "${dstdir}" "${branch}"
668
+      fi
668 669
       log_fluff "Repository \"${dstdir}\" already exists"
669 670
    else
670 671
       if [ "${MULLE_BOOTSTRAP_IGNORE_GRAVEYARD}" != "YES" -a -d "${CLONESFETCH_SUBDIR}/.graveyard/${name}" ]
... ...
@@ -960,8 +967,11 @@ update_repository()
960 960
       fi
961 961
    fi
962 962
 
963
-   ensure_clone_url_is_correct "${dstdir}" "${url}"
964
-   ensure_clone_branch_is_correct "${dstdir}" "${branch}"
963
+   if ensure_clone_url_is_correct "${dstdir}" "${url}"
964
+   then
965
+      ensure_clone_branch_is_correct "${dstdir}" "${branch}"
966
+   fi
967
+
965 968
    [ $rval -eq 0 -o $rval -eq 2 ]
966 969
    return $?
967 970
 }
... ...
@@ -1267,9 +1277,10 @@ clone_embedded_repository()
1267 1267
       fi
1268 1268
 
1269 1269
    else
1270
-      ensure_clone_url_is_correct "${dstdir}" "${url}"
1271
-      ensure_clone_branch_is_correct "${dstdir}" "${branch}"
1272
-
1270
+      if ensure_clone_url_is_correct "${dstdir}" "${url}"
1271
+      then
1272
+         ensure_clone_branch_is_correct "${dstdir}" "${branch}"
1273
+      fi
1273 1274
       log_fluff "Repository \"${dstdir}\" already exists"
1274 1275
    fi
1275 1276
 
... ...
@@ -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 123
 {
124 124
    if [ ! -d "${BOOTSTRAP_SUBDIR}.auto" ]
125 125
    then
126
-     log_fluff "Need refresh because ${BOOTSTRAP_SUBDIR}.auto does not exist."
126
+     log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}.auto\" does not exist."
127 127
      return 0
128 128
    fi
129 129
 
130 130
    if [ ! -f "${CLONESFETCH_SUBDIR}/.refresh_done" ]
131 131
    then
132
-      log_fluff "Need refresh because ${CLONESFETCH_SUBDIR}/.refresh_done does not exist."
132
+      log_fluff "Need refresh because \"${CLONESFETCH_SUBDIR}/.refresh_done\" does not exist."
133 133
       return 0
134 134
    fi
135 135
 
136
-   if [ "${CLONESFETCH_SUBDIR}/.refresh_done" -ot "${BOOTSTRAP_SUBDIR}/embedded_repositories" ]
136
+   if [ ! -z "`find "${BOOTSTRAP_SUBDIR}" -newer "${CLONESFETCH_SUBDIR}/.refresh_done" 2> /dev/null`" ]
137 137
    then
138
-      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}/embedded_repositories\" is modified"
138
+      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}\" is modified"
139 139
       return 0
140 140
    fi
141 141
 
142
-   if [ "${CLONESFETCH_SUBDIR}/.refresh_done" -ot "${BOOTSTRAP_SUBDIR}/repositories" ]
142
+   if [ ! -z "`find "${BOOTSTRAP_SUBDIR}.local" -newer "${CLONESFETCH_SUBDIR}/.refresh_done" 2> /dev/null`" ]
143 143
    then
144
-      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}/repositories\" is modified"
144
+      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}.local\" is modified"
145 145
       return 0
146 146
    fi
147 147
 
148
-   if [ "${CLONESFETCH_SUBDIR}/.refresh_done" -ot "${BOOTSTRAP_SUBDIR}.local/embedded_repositories" ]
148
+   if [ ! -z "`find "${CLONESFETCH_SUBDIR}"/*/"${BOOTSTRAP_SUBDIR}" -newer "${CLONESFETCH_SUBDIR}/.refresh_done" 2> /dev/null`" ]
149 149
    then
150
-      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}.local/embedded_repositories\" is modified"
150
+      log_fluff "Need refresh because \"${BOOTSTRAP_SUBDIR}.local\" is modified"
151 151
       return 0
152 152
    fi
153 153
 
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
154
+   log_fluff "No refresh needed."
159 155
 
160 156
    return 1
161 157
 }
... ...
@@ -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 140
 
141 141
    if [ "${branch}" != "${tag}" ]
142 142
    then
143
-      log_info "Checking out version ${C_WHITE}${C_BOLD}${tag}${C_INFO} of ${C_MAGENTA}${C_BOLD}${dst}${C_INFO} ..."
143
+      log_info "Checking out version ${C_RESET_BOLD}${tag}${C_INFO} of ${C_MAGENTA}${C_BOLD}${dst}${C_INFO} ..."
144 144
       ( exekutor cd "${dst}" ; exekutor git ${GITFLAGS} checkout ${options} "${tag}" )
145 145
 
146 146
       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 69
 
70 70
 (
71 71
    cd c ;
72
-   mulle-bootstrap fetch
72
+   mulle-bootstrap ${BOOTSTRAP_FLAGS} fetch
73 73
 
74 74
    [ -d src/b_1 ] || fail "b as src/b_1 failed to be embedded"
75 75
    [ -d src/b_1/src/a_1 ] && fail "a was wrongly embedded"
... ...
@@ -82,15 +84,15 @@ echo "=== test 1 done ==="
82 82
 echo ""
83 83
 echo ""
84 84
 
85
-
86 85
 (
87 86
    cd c ;
87
+   sleep 1 ;
88 88
    echo "../b;src/b_2" > .bootstrap/embedded_repositories ;
89
-   mulle-bootstrap fetch
89
+   mulle-bootstrap ${BOOTSTRAP_FLAGS} fetch
90 90
    [ -d src/b_1 ] && fail "b as src/b_1 failed to be removed"
91 91
    [ -d src/b_2 ] || fail "b as src/b_2 failed to be added"
92 92
    :
93
-) || exit 1 
93
+) || exit 1
94 94
 
95 95
 echo ""
96 96
 echo ""
... ...
@@ -101,10 +103,10 @@ echo ""
101 101
 
102 102
 (
103 103
    cd d ;
104
-   mulle-bootstrap -a fetch
104
+   mulle-bootstrap -a ${BOOTSTRAP_FLAGS} fetch
105 105
    [ -d .repos/c/src/b_1 ] || fail "b as .repos/c/src/b_1 failed to be fetched"
106 106
    :
107
-) || exit 1 
107
+) || exit 1
108 108
 
109 109
 echo ""
110 110
 echo ""
... ...
@@ -115,8 +117,9 @@ echo ""
115 115
 
116 116
 (
117 117
    cd d ;
118
+   sleep 1 ;
118 119
    echo "../b;src/b_2" > .repos/c/.bootstrap/embedded_repositories ;
119
-   mulle-bootstrap -vvv fetch
120
+   mulle-bootstrap ${BOOTSTRAP_FLAGS} fetch
120 121
    [ -d .repos/c/src/b_1 ] && fail "b as .repos/c/src/b_1 failed to be removed"
121 122
    [ -d .repos/c/src/b_2 ] || fail "b as .repos/c/src/b_2 failed to be added"
122 123
    :
123 124
old mode 100644
124 125
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 "$@"