-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite git-clone as shell script #188
Conversation
git/git-clone.yaml
Outdated
if [[ ${DEPTH} > 0 ]];then | ||
fetchArgs="${fetchArgs} --depth=${DEPTH}" | ||
fi | ||
if git ${fetchArgs};then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing [[
]]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually maybe I misunderstand what this is doing. What does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will check if the command exit properly and if it doesn't it will fallback, I have simply converted the GO code, and I assume that fallback was written to cover a user case... i.e:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this out locally in a pipeline and it performed the same as the existing git-init binary (as far as I can tell...)
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sbwsg The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
git/git-clone.yaml
Outdated
fetchArgs="${fetchArgs} --depth=${DEPTH}" | ||
fi | ||
if git ${fetchArgs};then | ||
git pull origin master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's possible that there is no "master" branch on the remote.
What is the purpose of this pull? We fetch in the previous line and then we checkout the specific revision on the next line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i wondered it too (to be honest I merely converted the GO code without too much tweaking), i think we can just git reset --hard anyway...
Adding @sthaha for advice since he is the git guru 😀 |
3729608
to
f87e20e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me; may want to consider addressing some of the comments.
git/git-clone.yaml
Outdated
|
||
ensureHomeEnv | ||
fetch | ||
echo -n "$(git rev-parse HEAD | tr -d '\n')" > "$(results.commit.path)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo isn't needed - right? i.e. git rev-parse HEAD | tr -d '\n' > "$( ...)
should work - right?
git/git-clone.yaml
Outdated
# https://git.io/JvBCr | ||
fetch() { | ||
[[ ${REVISION} == "" ]] && REVISION=master | ||
if [[ ${CHECKOUT_DIR} != "" ]];then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this can reduced to
test -z "$CHECKOUT_DIR" || cd "$CHECKOUT_DIR"
git init .
else | ||
git init . | ||
fi | ||
trimmedURL=$(echo ${URL}|sed -e 's/^[ ]*//' -e 's/[ ]*$//') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also just curious ... wouldn't trimmedURL=$(echo $URL)
work :D ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chmouel are you using sh? or zsh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chmouel you don't have to change the implementation, I was only curious ...
/hold will do this rewrite when i get a bit of time.. |
IMHO, we can merge this while you work on the improved version. |
I'm gonna contradict tektoncd/pipeline#1961:
I'm not sure that a script is the most maintainable way forward here? As soon as we get beyond a few lines in a script, whether we're talking about python or git, and when we're talking about a piece of infra that is so core to so many Pipelines (i.e. pulling from git), I feel like we want to start having testing, linting, all that good stuff. Moving this logic into a script feels like a couple steps backward for me? It definitely has the advantage of being able to see exactly what the script is doing, but I'd rather that we start adding tests and debug info to the git-init logic we already have - even move it into its own repo (or into this one). /hold |
@bobcatfish that's some fair points here is some of the advantages I see using a only shell git clone task :
And to add this, I am adding tests for this and we can have a job doing bash unit tests. |
I am not entirely sure how "so core" it is to Pipelines. It can be considered as core if it is in I do agree (and adding 👍) with @chmouel on his points, the |
We are rewritting git-clone as a 'pure' bourne shell script with no dependence on the git-init image. I have rewritten almost word by word the go code from here https://git.io/JvBCr Error handling are handled by shell's set -e so if any command fails it will just exit 1, There is some bugs in go code submodules which is done always so i have handled this differently to properly be conditional to the parameter. Signed-off-by: Chmouel Boudjnah <[email protected]>
I have added some tests and resynced with master... |
@chmouel: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
…o-release-v0.11 New merge from upstream v1beta to release v0.11
@bobcatfish @chmouel @vdemeester can we find a venue to discuss this further and get closure for this PR? Perhaps the Pipelines WG? I think there are sound arguments on both sides of this debate and we should probably resolve them so that we can set the policy for other catalog entries going forward. |
Sounds good to me, let's have this discussion on next week agenda. |
/close let's try in another way maybe complicated shell scripts is a bit too cryptic, will send a new PR trying it in Python+Tests. |
@chmouel: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
We are rewritting git-clone as a 'pure' bourne shell script with no dependence
on the git-init image.
I have rewritten almost word by word the go code from here https://git.io/JvBCr
Error handling are handled by shell's set -e so if any command fails it will
just exit 1,
There is some bugs in go code submodules which is done always so i have handled
this differently to properly be conditional to the parameter.
Changes
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide
for more details.