Skip to content

Commit

Permalink
Fixed problems with adding/cloning the same URL and commit twice
Browse files Browse the repository at this point in the history
If the repo is already cloned, git clone would fail.

Signed-off-by: Ole Herman Schumacher Elgesem <[email protected]>
  • Loading branch information
olehermanse committed Feb 2, 2022
1 parent 4a3752c commit 34fba82
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cfbs/internal_file_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ def _get_git_repo_commit_sha(repo_path):
return f.read().strip()


def _clone_and_checkout(url, path, commit):
# NOTE: If any of these shell (git) commands fail, we will exit
if not os.path.exists(path + "/.git"):
sh("git clone --no-checkout %s %s" % (url, path))
sh("git checkout " + commit, directory=path)


def clone_url_repo(repo_url):
assert repo_url.startswith(("https://", "ssh://", "git://"))

Expand All @@ -157,8 +164,7 @@ def clone_url_repo(repo_url):

if commit is not None:
commit_path = os.path.join(repo_dir, commit)
sh("git clone --no-checkout %s %s" % (repo_url, commit_path))
sh("cd %s; git checkout %s" % (commit_path, commit))
_clone_and_checkout(repo_url, commit_path, commit)
else:
master_path = os.path.join(repo_dir, "master")
sh("git clone %s %s" % (repo_url, master_path))
Expand Down

0 comments on commit 34fba82

Please sign in to comment.