@@ -206,6 +206,36 @@ class InstInfo:
206206 return (f'InstInfo({ self .name } , { self .source_loc } , { self .git_url } , '
207207 f'{ self .entry } , { self .deps } , { self .subdir } )' )
208208
209+ def get_repo_commit (self ) -> Union [str , None ]:
210+ """The latest commit from a remote repo or the HEAD of a local repo."""
211+ if self .srctype in [Source .LOCAL_REPO , Source .GIT_LOCAL_CLONE ]:
212+ git = run (['git' , 'rev-parse' , 'HEAD' ], cwd = str (self .source_loc ),
213+ stdout = PIPE , stderr = PIPE , text = True , check = False , timeout = 10 )
214+ if git .returncode != 0 :
215+ return None
216+ return git .stdout .splitlines ()[0 ]
217+
218+ if self .srctype == Source .GITHUB_REPO :
219+ parsed_url = urlparse (self .source_loc )
220+ if 'github.com' not in parsed_url .netloc :
221+ return None
222+ if len (parsed_url .path .split ('/' )) < 2 :
223+ return None
224+ start = 1
225+ # Maybe we were passed an api.github.com/repo/<user> url
226+ if 'api' in parsed_url .netloc :
227+ start += 1
228+ repo_user = parsed_url .path .split ('/' )[start ]
229+ repo_name = parsed_url .path .split ('/' )[start + 1 ]
230+ api_url = f'{ API_GITHUB_COM } /repos/{ repo_user } /{ repo_name } /commits?ref=HEAD'
231+ r = urlopen (api_url , timeout = 5 )
232+ if r .status != 200 :
233+ return None
234+ try :
235+ return json .loads (r .read ().decode ())['0' ]['sha' ]
236+ except :
237+ return None
238+
209239 def get_inst_details (self ) -> bool :
210240 """Search the source_loc for plugin install details.
211241 This may be necessary if a contents api is unavailable.
@@ -1694,6 +1724,15 @@ def update_plugin(plugin_name: str) -> Union[str, None]:
16941724
16951725 src = InstInfo (plugin_name ,
16961726 metadata ['original source' ], None )
1727+ if not src .get_inst_details ():
1728+ log .error (f'cannot locate { plugin_name } in original source { metadata ["original_source" ]} ' )
1729+ return None
1730+ repo_commit = src .get_repo_commit ()
1731+ if not repo_commit :
1732+ log .debug ('source commit not available' )
1733+ if repo_commit and repo_commit == metadata ['installed commit' ]:
1734+ log .debug (f'Installed { plugin_name } is already latest - { repo_commit } ' )
1735+ return None
16971736 uninstall (plugin_name )
16981737 try :
16991738 installed = _install_plugin (src )
0 commit comments