@@ -426,9 +426,13 @@ def pull(self, names):
426426 repo_config = config ["repos" ][name ]
427427 revision = repo_config ["revision" ]
428428
429+ # Boolean value wether repo is newly cloned.
430+ cloned = False
431+
429432 if not repo_path .exists ():
430433 clone_rev = revision ["tag" ] if "tag" in revision else revision ["branch" ]
431434 clone_url = repo_config .get ("url" , None )
435+ cloned = True
432436
433437 if not clone_url :
434438 raise SubGitConfigException (f"Missing required key 'url' on repo '{ name } '" )
@@ -453,7 +457,7 @@ def pull(self, names):
453457 g = Git (p )
454458
455459 # Fetch all changes from upstream git repo
456- repo .remotes .origin .pull ()
460+ repo .remotes .origin .fetch ()
457461
458462 # How to handle the repo when a branch is specified
459463 if "branch" in revision :
@@ -462,6 +466,16 @@ def pull(self, names):
462466 # Extract the sub tag data
463467 branch_revision = revision ["branch" ]
464468
469+ if not cloned :
470+ try :
471+ latest_remote_sha = str (repo .rev_parse (f"origin/{ branch_revision } " ))
472+ latest_local_sha = str (repo .head .commit .hexsha )
473+
474+ if latest_remote_sha != latest_local_sha :
475+ repo .remotes .origin .pull ()
476+ except git .exc .BadName as er :
477+ log .error (er )
478+
465479 # Ensure the local version of the branch exists and points to the origin ref for that branch
466480 repo .create_head (f"{ branch_revision } " , f"origin/{ branch_revision } " )
467481
0 commit comments