@@ -2477,7 +2477,7 @@ def get_source_tarball_from_git(filename, targetdir, git_config):
24772477 clone_cmd .extend (['--depth' , '1' ])
24782478
24792479 if tag :
2480- clone_cmd .extend (['--branch' , 'refs/tags/' + tag ])
2480+ clone_cmd .extend (['--branch' , tag ])
24812481 if recursive :
24822482 clone_cmd .append ('--recursive' )
24832483 else :
@@ -2487,22 +2487,41 @@ def get_source_tarball_from_git(filename, targetdir, git_config):
24872487
24882488 tmpdir = tempfile .mkdtemp ()
24892489 cwd = change_dir (tmpdir )
2490- run .run_cmd (' ' .join (clone_cmd ), log_all = True , log_ok = False , simple = False , regexp = False )
2490+ run .run_cmd (' ' .join (clone_cmd ), log_all = True , simple = True , regexp = False )
24912491
24922492 # if a specific commit is asked for, check it out
24932493 if commit :
24942494 checkout_cmd = ['git' , 'checkout' , commit ]
24952495 if recursive :
24962496 checkout_cmd .extend (['&&' , 'git' , 'submodule' , 'update' , '--init' , '--recursive' ])
24972497
2498- run .run_cmd (' ' .join (checkout_cmd ), log_all = True , log_ok = False , simple = False , regexp = False , path = repo_name )
2498+ run .run_cmd (' ' .join (checkout_cmd ), log_all = True , simple = True , regexp = False , path = repo_name )
2499+ elif not build_option ('extended_dry_run' ):
2500+ # If we wanted to get a tag make sure we actually got a tag and not a branch with the same name
2501+ # This doesn't make sense in dry-run mode as we don't have anything to check
2502+ cmd = 'git describe --exact-match --tags HEAD'
2503+ # Note: Disable logging to also disable the error handling in run_cmd
2504+ (out , ec ) = run .run_cmd (cmd , log_ok = False , log_all = False , regexp = False , path = repo_name )
2505+ if ec != 0 or tag not in out .splitlines ():
2506+ cmds = []
2507+ if not keep_git_dir :
2508+ # Make the repo unshallow, same as git fetch --unshallow in git 1.8.3+
2509+ # The first fetch seemingly does nothing, no idea why.
2510+ cmds .append ('git fetch --depth=2147483647 && git fetch --depth=2147483647' )
2511+ cmds .append ('git checkout refs/tags/' + tag )
2512+ # Clean all untracked files, e.g. from left-over submodules
2513+ cmds .append ('git clean --force -d -x' )
2514+ if recursive :
2515+ cmds .append ('git submodule update --init --recursive' )
2516+ for cmd in cmds :
2517+ run .run_cmd (cmd , log_all = True , simple = True , regexp = False , path = repo_name )
24992518
25002519 # create an archive and delete the git repo directory
25012520 if keep_git_dir :
25022521 tar_cmd = ['tar' , 'cfvz' , targetpath , repo_name ]
25032522 else :
25042523 tar_cmd = ['tar' , 'cfvz' , targetpath , '--exclude' , '.git' , repo_name ]
2505- run .run_cmd (' ' .join (tar_cmd ), log_all = True , log_ok = False , simple = False , regexp = False )
2524+ run .run_cmd (' ' .join (tar_cmd ), log_all = True , simple = True , regexp = False )
25062525
25072526 # cleanup (repo_name dir does not exist in dry run mode)
25082527 change_dir (cwd )
0 commit comments