Skip to content
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

cmd/git-init: check for errors or at least log them #677

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
cmd/git-init: check for errors or at least log them
- if something fail (even if not fatal), we can at least see it
  happened
- it makes my linter happier 😅

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester committed Mar 26, 2019
commit 12a5e8b8e6ea5f42cc64c30f7d554c493f127fc4
11 changes: 6 additions & 5 deletions cmd/git-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ func main() {
logger.Fatalf("Failed to change directory with path %s; err %v", path, err)
}
} else {
run(logger, "git", "init")
runOrFail(logger, "git", "init")
}

run(logger, "git", "remote", "add", "origin", *url)
err = run(logger, "git", "fetch", "--depth=1", "--recurse-submodules=yes", "origin", *revision)
if err != nil {
runOrFail(logger, "git", "remote", "add", "origin", *url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason we don't use runOrFail here is that it uses logger.Fatalf which will log and call Exit(1)
We needed to try the git pull case when this fails

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pivotal-nader-ziada not sure to follow, the rest of the git commands are all referencing the origin remote. If we failed to add it, nothing else will work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, my bad! I thought it was the fetch

if err := run(logger, "git", "fetch", "--depth=1", "--recurse-submodules=yes", "origin", *revision); err != nil {
// Fetch can fail if an old commitid was used so try git pull, performing regardless of error
// as no guarantee that the same error is returned by all git servers gitlab, github etc...
run(logger, "git", "pull", "--recurse-submodules=yes", "origin")
if err := run(logger, "git", "pull", "--recurse-submodules=yes", "origin"); err != nil {
logger.Warnf("Failed to pull origin : %s", err)
}
runOrFail(logger, "git", "checkout", *revision)
} else {
runOrFail(logger, "git", "reset", "--hard", "FETCH_HEAD")
Expand Down