Add --force option to fetch_sources.py
authorThomas Spurden <thomas.spurden@broadcom.com>
Wed, 16 Dec 2020 12:26:52 +0000 (12:26 +0000)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 28 Jan 2021 18:06:15 +0000 (18:06 +0000)
This passes --force to git fetch and checkout.

Change-Id: I56a7ccafefb2eaac69d2253516308daa8e8808cf
(cherry picked from commit 2feac9e222d15c94adf3d39e61878e489a0f0aea)

external/fetch_sources.py

index dec4e6d..8a977fe 100644 (file)
@@ -70,7 +70,7 @@ class SourcePackage (Source):
                Source.clean(self)
                self.removeArchives()
 
-       def update (self, cmdProtocol = None):
+       def update (self, cmdProtocol = None, force = False):
                if not self.isArchiveUpToDate():
                        self.fetchAndVerifyArchive()
 
@@ -182,7 +182,7 @@ class SourceFile (Source):
                self.filename           = filename
                self.checksum           = checksum
 
-       def update (self, cmdProtocol = None):
+       def update (self, cmdProtocol = None, force = False):
                if not self.isFileUpToDate():
                        Source.clean(self)
                        self.fetchAndVerifyFile()
@@ -273,7 +273,7 @@ class GitRepo (Source):
                assert url != None
                return url
 
-       def update (self, cmdProtocol = None):
+       def update (self, cmdProtocol = None, force = False):
                fullDstPath = os.path.join(EXTERNAL_DIR, self.baseDir, self.extractDir)
 
                url = self.selectUrl(cmdProtocol)
@@ -287,8 +287,9 @@ class GitRepo (Source):
                                (stdout, stderr) = proc.communicate()
                                if proc.returncode == 0:
                                        execute(["git", "tag", "-d",tag])
-                       execute(["git", "fetch", "--tags", url, "+refs/heads/*:refs/remotes/origin/*"])
-                       execute(["git", "checkout", self.revision])
+                       force_arg = ['--force'] if force else []
+                       execute(["git", "fetch"] + force_arg + ["--tags", url, "+refs/heads/*:refs/remotes/origin/*"])
+                       execute(["git", "checkout"] + force_arg + [self.revision])
                finally:
                        popWorkingDir()
 
@@ -348,6 +349,8 @@ def parseArgs ():
                                                " Minimum python version required " + versionsForInsecureStr)
        parser.add_argument('--protocol', dest='protocol', default=None, choices=['ssh', 'https'],
                                                help="Select protocol to checkout git repositories.")
+       parser.add_argument('--force', dest='force', action='store_true', default=False,
+                                               help="Pass --force to git fetch and checkout commands")
 
        args = parser.parse_args()
 
@@ -368,4 +371,4 @@ if __name__ == "__main__":
                if args.clean:
                        pkg.clean()
                else:
-                       pkg.update(args.protocol)
+                       pkg.update(args.protocol, args.force)