Skip to content

Commit

Permalink
Git Init Container checkout #69
Browse files Browse the repository at this point in the history
* add ability to checkout branches/commits/tags
  • Loading branch information
jfaltermeier committed Nov 23, 2023
1 parent f84e9de commit a873805
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 6 additions & 5 deletions python/git-init/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ ssh-keygen -t ed25519 -C "Test TC Git Init SSH Keypair"
export HTTP_PASSWORD=pat
export SSH_PASSWORD=sshpw
export SSH_REPO="[email protected]:username/my.repository.git"
export BRANCH=maintenance_1_1_x

# HTTPS Public
docker run --rm theiacloud/theia-cloud-git-init:local "$HTTP_PUBLIC" "/tmp/my-repo"
docker run --rm theiacloud/theia-cloud-git-init:local "$HTTP_PUBLIC" "/tmp/my-repo" "$BRANCH"

# HTTPS Private
docker run --env GIT_PROMPT1=$HTTP_USERNAME --env GIT_PROMPT2=$HTTP_PASSWORD --rm theiacloud/theia-cloud-git-init:local "$HTTP_PRIVATE" "/tmp/my-repo"
docker run --env GIT_PROMPT1=$HTTP_USERNAME --env GIT_PROMPT2=$HTTP_PASSWORD --rm theiacloud/theia-cloud-git-init:local "$HTTP_PRIVATE" "/tmp/my-repo" "$BRANCH"

# HTTPS Private with Username
docker run --env GIT_PROMPT1=$HTTP_PASSWORD --rm theiacloud/theia-cloud-git-init:local "$HTTP_PRIVATE_WITH_USERNAME" "/tmp/my-repo"
docker run --env GIT_PROMPT1=$HTTP_PASSWORD --rm theiacloud/theia-cloud-git-init:local "$HTTP_PRIVATE_WITH_USERNAME" "/tmp/my-repo" "$BRANCH"

# HTTPS Private with Username and Password
docker run --rm theiacloud/theia-cloud-git-init:local "$HTTP_PRIVATE_WITH_USERNAME_AND_PASSWORD" "/tmp/my-repo"
docker run --rm theiacloud/theia-cloud-git-init:local "$HTTP_PRIVATE_WITH_USERNAME_AND_PASSWORD" "/tmp/my-repo" "$BRANCH"

# SSH
docker run --env GIT_PROMPT1=$SSH_PASSWORD -v ~/tmp/ssh/:/etc/theia-cloud-ssh --rm theiacloud/theia-cloud-git-init:local "$SSH_REPO" "/tmp/my-repo"
docker run --env GIT_PROMPT1=$SSH_PASSWORD -v ~/tmp/ssh/:/etc/theia-cloud-ssh --rm theiacloud/theia-cloud-git-init:local "$SSH_REPO" "/tmp/my-repo" "$BRANCH"
```
9 changes: 9 additions & 0 deletions python/git-init/git-init.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def getHostname(repository):
parser = argparse.ArgumentParser()
parser.add_argument("repository", help="The repository URL", type=str)
parser.add_argument("directory", help="The directory to clone into", type=str)
parser.add_argument("checkout", help="The branch/commit id/tag to checkout", type=str)
args = parser.parse_args()

# Set up git credential helper
Expand All @@ -83,3 +84,11 @@ def getHostname(repository):

if debugLogging:
runProcess(["ls", "-al", args.directory])

# Checkout
code = runProcess(["git", "-C", args.directory, "checkout", args.checkout])
if code != 0:
exit(code)

if debugLogging:
runProcess(["git", "-C", args.directory, "status"])

0 comments on commit a873805

Please sign in to comment.