@@ -301,18 +301,17 @@ def getG2Branch():
301301
302302def getG2VersionInfo ():
303303 '''Get the git version information. This can be a bit slow, so reading
304- .../GSASII/saved_version.py may be faster (in main but not master branch)
304+ .../GSASII/saved_version.py may be faster
305305 '''
306306 gv = getSavedVersionInfo ()
307307 if HowIsG2Installed ().startswith ('git' ):
308308 g2repo = openGitRepo (path2GSAS2 )
309309 commit = g2repo .head .commit
310- ctim = commit .committed_datetime .strftime ('%d-%b-%Y %H:%M' )
310+ ctim = commit .committed_datetime .strftime ('%d-%b-%y %H:%M' )
311311 now = dt .datetime .now ().replace (
312312 tzinfo = commit .committed_datetime .tzinfo )
313313 delta = now - commit .committed_datetime
314314 age = delta .total_seconds ()/ (60 * 60 * 24. )
315- gversion = f"Tag: #{ GetVersionNumber ()} , { GetVersionTag ()} "
316315 msg = ''
317316 if g2repo .head .is_detached :
318317 msg = ("\n " +
@@ -326,14 +325,19 @@ def getG2VersionInfo():
326325 if rc is None :
327326 msg += f"\n \t No history found. On development branch? ({ g2repo .active_branch } )"
328327 elif str (g2repo .active_branch ) != 'main' :
329- msg += f'\n \t Using development branch " { g2repo .active_branch } " '
328+ msg += f'\n \t Using development branch: { g2repo .active_branch } '
330329 elif age > 60 and len (rc ) > 0 :
331- msg += f"\n \t **** This version is really old. Please update. >= { len (rc )} updates have been posted ****"
332- elif age > 5 and len (rc ) > 0 :
333- msg += f"\n \t **** Please consider updating. >= { len (rc )} updates have been posted"
334- elif len (rc ) > 0 :
335- msg += f"\n \t This GSAS-II version is ~{ len (rc )} updates behind current."
336- return f" GSAS-II: { commit .hexsha [:8 ]} , { ctim } ({ age :.1f} days old). { gversion } { msg } "
330+ msg += f"\n \t **** This version is really old ({ age :.1f} days). Please update.\n \t **** At least { len (rc )} updates have been posted ****"
331+ elif (age > 5 and len (rc ) > 0 ) or len (rc ) > 5 :
332+ msg += f"\n \t **** Please consider updating. This version is { age :.1f} days old\n \t **** and { len (rc )} or more updates behind."
333+ # elif len(rc) > 0:
334+ # msg += f"\n\tThis GSAS-II version is ~{len(rc)} updates behind current."
335+ # could consider getting version & tag from gv if not None (see below)
336+ gversion = f"{ GetVersionNumber ()} /{ GetVersionTag ()} "
337+ if len (rc ) > 0 :
338+ return f" GSAS-II: { gversion } posted { ctim } (\u2265 { len (rc )} new updates) [{ commit .hexsha [:8 ]} ]{ msg } "
339+ else :
340+ return f" GSAS-II: { gversion } posted { ctim } (no new updates) [{ commit .hexsha [:8 ]} ]{ msg } "
337341 elif gv is not None :
338342 vt = ''
339343 cvt = ''
@@ -542,8 +546,10 @@ def gitCheckForUpdates(fetch=True,g2repo=None):
542546 provide useful information in the case of a detached Head (see
543547 :func:`countDetachedCommits` for that.)
544548
545- :param bool fetch: if True (default), updates are copied over from
549+ :param bool fetch: if True (default), updates are downloaded from
546550 the remote repository (git fetch), before checking for changes.
551+ At present, this feature is not used anywhere in GSAS-II (fetch=False
552+ in all calls).
547553 :param str g2repo: git.Rwpo connecton to GSAS-II installation. If
548554 None (default) it will be opened.
549555 :returns: a list containing (remotecommits, localcommits, fetched) where
@@ -567,8 +573,12 @@ def gitCheckForUpdates(fetch=True,g2repo=None):
567573 g2repo = openGitRepo (path2GSAS2 )
568574 if g2repo .head .is_detached :
569575 return (None ,None ,None )
576+ prevremotecommits = None
570577 if fetch :
571578 try :
579+ head = g2repo .head .ref
580+ tracking = head .tracking_branch ()
581+ prevremotecommits = [i .hexsha for i in head .commit .iter_items (g2repo , f'{ head .path } ..{ tracking .path } ' )]
572582 g2repo .remote ().fetch ()
573583 fetched = True
574584 except git .GitCommandError as msg :
@@ -578,6 +588,11 @@ def gitCheckForUpdates(fetch=True,g2repo=None):
578588 tracking = head .tracking_branch ()
579589 localcommits = [i .hexsha for i in head .commit .iter_items (g2repo , f'{ tracking .path } ..{ head .path } ' )]
580590 remotecommits = [i .hexsha for i in head .commit .iter_items (g2repo , f'{ head .path } ..{ tracking .path } ' )]
591+ if prevremotecommits is None : prevremotecommits = remotecommits
592+ if fetch and len (prevremotecommits ) != len (remotecommits ):
593+ print (f"Fetch of new GSAS-II versions uploaded { len (remotecommits )- len (prevremotecommits )} new updates." )
594+ elif fetch and GetConfigValue ('debug' ):
595+ print ('Updates fetched; nothing new' )
581596 return remotecommits ,localcommits ,fetched
582597 except :
583598 return (None ,None ,None )
@@ -2164,7 +2179,8 @@ def openInNewTerm(project=None,g2script=None,pythonapp=sys.executable):
21642179
21652180 if updateType == 'fetch' :
21662181 # download the latest updates from GitHub to the local repository
2167- # in background while GSAS-II runs no updates are applied
2182+ # in background while GSAS-II runs no updates are applied.
2183+ # invoked by gitGetUpdate(mode='Background')
21682184 logfile = os .path .join (os .path .expanduser ('~' ),'GSASII_bkgUpdate.log' )
21692185 mode = 'a'
21702186 # don't let log file get too large (20K bytes)
@@ -2176,36 +2192,53 @@ def openInNewTerm(project=None,g2script=None,pythonapp=sys.executable):
21762192 except :
21772193 print ('background git update was unable to open log file' )
21782194 sys .exit ()
2179- fp .write ('Starting background git update' )
2180- fp .write (dt .datetime .strftime (dt .datetime .now (),
2181- " at %Y-%m-%dT%H:%M\n " ))
21822195 try :
21832196 import git
21842197 except :
2185- fp .write ('git import failed' )
2198+ fp .write ('Git background import failed' )
2199+ fp .write (dt .datetime .strftime (dt .datetime .now (),
2200+ " at %Y-%m-%dT%H:%M\n " ))
21862201 fp .close ()
21872202 sys .exit ()
21882203 try :
21892204 g2repo = openGitRepo (path2GSAS2 )
2205+ prevremotecommits = None
2206+ if not g2repo .head .is_detached :
2207+ head = g2repo .head .ref
2208+ tracking = head .tracking_branch ()
2209+ prevremotecommits = [i .hexsha for i in head .commit .iter_items (g2repo , f'{ head .path } ..{ tracking .path } ' )]
21902210 g2repo .remote ().fetch ()
2191- fp .write ('Updates fetched\n ' )
2211+ if not g2repo .head .is_detached :
2212+ head = g2repo .head .ref
2213+ tracking = head .tracking_branch ()
2214+ remotecommits = [i .hexsha for i in head .commit .iter_items (g2repo , f'{ head .path } ..{ tracking .path } ' )]
2215+ new = len (remotecommits )- len (prevremotecommits )
2216+ msg = f'{ new } new update(s) found and downloaded, so { len (remotecommits )} total are available to install'
2217+ #fp.write(f'{msg}\n')
2218+ if new > 0 : print (msg )
21922219 except Exception as msg :
2220+ fp .write ('Background git update message' )
2221+ fp .write (dt .datetime .strftime (dt .datetime .now (),
2222+ " at %Y-%m-%dT%H:%M\n " ))
21932223 fp .write (f'Update failed with message { msg } \n ' )
21942224
21952225 if g2repo .head .is_detached :
2226+ fp .write ('Background git update message' )
2227+ fp .write (dt .datetime .strftime (dt .datetime .now (),
2228+ " at %Y-%m-%dT%H:%M\n " ))
21962229 fp .write ('Status: reverted to an old install\n ' )
2197- else :
2198- try :
2199- rc ,lc ,_ = gitCheckForUpdates (False ,g2repo )
2200- if len (rc ) == 0 :
2201- fp .write ('Status: no unapplied commits\n ' )
2202- else :
2203- fp .write (f'Status: unapplied commits now { len (rc )} \n ' )
2204- except Exception as msg :
2205- fp .write (f'\n gitCheckForUpdates failed with message { msg } \n ' )
2206- fp .write ('update done at' )
2207- fp .write (dt .datetime .strftime (dt .datetime .now (),
2208- " at %Y-%m-%dT%H:%M\n \n " ))
2230+ # else:
2231+ # try:
2232+ # rc,lc,_ = gitCheckForUpdates(False,g2repo)
2233+ # if len(rc) == 0:
2234+ # fp.write('Status: no unapplied commits\n')
2235+ # else:
2236+ # fp.write(f'Status: unapplied commits now {len(rc)}\n')
2237+ # except Exception as msg:
2238+ # fp.write(f'\ngitCheckForUpdates failed with message {msg}\n')
2239+ # fp.write('update done at')
2240+ # fp.write(dt.datetime.strftime(dt.datetime.now(),
2241+ # " at %Y-%m-%dT%H:%M\n\n"))
22092242 fp .close ()
22102243 sys .exit ()
22112244
0 commit comments