This repository contains the git-clone Task for Tekton Pipelines, providing Git repository cloning capabilities.
Problem: The git-clone task was logging an error message:
Error running git [remote get-url origin]: exit status 2
error: No such remote 'origin'
This occurred because the original code tried to check if the "origin" remote existed using git remote get-url origin
, which fails on fresh repositories where no remotes exist yet.
Solution: The code now:
- Uses
git remote
to safely list existing remotes (this command never fails) - Checks if "origin" is in the list of existing remotes
- If the remote exists, updates its URL using
git remote set-url
- If the remote doesn't exist, adds it using
git remote add
This approach completely eliminates error logging while maintaining all functionality for both fresh repositories and reused workspaces.
Files Modified:
image/git-init/git/git.go
- Updated thefetchOrigin
function with robust remote handling
Benefits:
- Eliminates spurious error messages in pipeline logs
- Works correctly with both fresh repositories and reused workspaces
- Maintains backward compatibility
- Provides cleaner, more reliable git operations
To build the updated git-init binary:
cd image/git-init
ko build --local .
The fix handles these scenarios correctly:
- Fresh repository:
git remote add origin <URL>
succeeds ✅ - Reused workspace with same URL:
git remote add
fails →git remote set-url
succeeds ✅ - Reused workspace with different URL:
git remote add
fails →git remote set-url
updates URL ✅ - Invalid configuration: Both operations fail → reports actual error ✅
ttl.sh/git-init-4025e1c5f1230d5d5dc600e50e1bdbad@sha256:8cf5621926dab695e3ab03777529b680ba812ff3b7ec9cd6610770c2828e5255
Let me check the