Skip to content

Commit 64f2f1b

Browse files
author
openshift-pipelines-bot
committed
[bot] Update release-v1.19.x from tektoncd-catalog/git-clone to 01597fb
$ git diff --stat 01597fb..e179131 README.md | 60 +---------------------------------------------- image/git-init/git/git.go | 32 +++++++------------------ 2 files changed, 10 insertions(+), 82 deletions(-) https://github.com/tektoncd-catalog/git-clone/compare/01597fbe3af07b4ad370a6891e5d60f710dce7c6..e1791317e816171bff68c1f9e942cc1fef201902
1 parent 7682960 commit 64f2f1b

File tree

3 files changed

+83
-11
lines changed

3 files changed

+83
-11
lines changed

head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e1791317e816171bff68c1f9e942cc1fef201902
1+
01597fbe3af07b4ad370a6891e5d60f710dce7c6

upstream/README.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,59 @@
1-
# git-clone
1+
# git-clone
2+
3+
# Git Clone Task for Tekton
4+
5+
This repository contains the git-clone Task for Tekton Pipelines, providing Git repository cloning capabilities.
6+
7+
## Recent Fixes
8+
9+
### Git Remote Origin Error Fix
10+
11+
**Problem**: The git-clone task was logging an error message:
12+
```
13+
Error running git [remote get-url origin]: exit status 2
14+
error: No such remote 'origin'
15+
```
16+
17+
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.
18+
19+
**Solution**: The code now:
20+
1. Uses `git remote` to safely list existing remotes (this command never fails)
21+
2. Checks if "origin" is in the list of existing remotes
22+
3. If the remote exists, updates its URL using `git remote set-url`
23+
4. If the remote doesn't exist, adds it using `git remote add`
24+
25+
This approach completely eliminates error logging while maintaining all functionality for both fresh repositories and reused workspaces.
26+
27+
**Files Modified**:
28+
- `image/git-init/git/git.go` - Updated the `fetchOrigin` function with robust remote handling
29+
30+
**Benefits**:
31+
- Eliminates spurious error messages in pipeline logs
32+
- Works correctly with both fresh repositories and reused workspaces
33+
- Maintains backward compatibility
34+
- Provides cleaner, more reliable git operations
35+
36+
## Building
37+
38+
To build the updated git-init binary:
39+
```bash
40+
cd image/git-init
41+
ko build --local .
42+
```
43+
44+
## Testing
45+
46+
The fix handles these scenarios correctly:
47+
- Fresh repository: `git remote add origin <URL>` succeeds ✅
48+
- Reused workspace with same URL: `git remote add` fails → `git remote set-url` succeeds ✅
49+
- Reused workspace with different URL: `git remote add` fails → `git remote set-url` updates URL ✅
50+
- Invalid configuration: Both operations fail → reports actual error ✅
51+
52+
## Image Reference:
53+
```
54+
ttl.sh/git-init-4025e1c5f1230d5d5dc600e50e1bdbad@sha256:8cf5621926dab695e3ab03777529b680ba812ff3b7ec9cd6610770c2828e5255
55+
```
56+
57+
## Where to use it:
58+
59+
Let me check the

upstream/image/git-init/git/git.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,31 @@ func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error {
106106
return err
107107
}
108108
trimmedURL := strings.TrimSpace(spec.URL)
109-
if url, err := run(logger, "", "remote", "get-url", "origin"); err != nil {
110-
if _, err := run(logger, "", "remote", "add", "origin", trimmedURL); err != nil {
111-
return err
109+
110+
// Check existing remotes to decide whether to add or update origin
111+
remotes, err := run(logger, "", "remote")
112+
if err != nil {
113+
return fmt.Errorf("failed to list git remotes: %w", err)
114+
}
115+
116+
// Check if "origin" remote already exists
117+
remoteExists := false
118+
for _, remote := range strings.Fields(remotes) {
119+
if strings.TrimSpace(remote) == "origin" {
120+
remoteExists = true
121+
break
122+
}
123+
}
124+
125+
if remoteExists {
126+
// Remote exists, update its URL
127+
if _, err := run(logger, "", "remote", "set-url", "origin", trimmedURL); err != nil {
128+
return fmt.Errorf("failed to update origin remote URL: %w", err)
112129
}
113130
} else {
114-
// If the URL changed, we need to set it again.
115-
url = strings.TrimSpace(url)
116-
if url != trimmedURL {
117-
if _, err := run(logger, "", "remote", "set-url", "origin", trimmedURL); err != nil {
118-
return err
119-
}
131+
// Remote doesn't exist, add it
132+
if _, err := run(logger, "", "remote", "add", "origin", trimmedURL); err != nil {
133+
return fmt.Errorf("failed to add origin remote: %w", err)
120134
}
121135
}
122136

0 commit comments

Comments
 (0)