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

Err: Reference not found after repo initialisation failed #17

Closed
julien040 opened this issue Feb 26, 2023 · 0 comments · Fixed by #19
Closed

Err: Reference not found after repo initialisation failed #17

julien040 opened this issue Feb 26, 2023 · 0 comments · Fixed by #19
Assignees
Labels
bug Something isn't working

Comments

@julien040
Copy link
Owner

When a repo is initialized, if the profile creation failed, gut won't work.

Sorry, I can't check if the HEAD is detached 😢
Error message: reference not found

Potential origin

func Init(cmd *cobra.Command, args []string) {
	wd, err := os.Getwd()
	if err != nil {
		exitOnError("Oups, something went wrong while getting the current working directory", err)
	}
	if executor.IsPathGitRepo(wd) {
		exitOnError("Oups, this directory is already a git repository. Delete the .git folder if you want to initialize a new repository", nil)
	}
	err = executor.Init(wd)
	if err != nil {
		exitOnError("Oups, something went wrong while initializing the repository", err)
	}
	profile := selectProfile("", true)
	associateProfileToPath(profile, wd)
	_, err = executor.Commit(wd, "🎉 Initial commit from Gut")
	if err != nil {
		exitOnError("Oups, something went wrong while creating the first commit", err)
	}
	print.Message("Yeah, your repository is ready to go!", print.Success)

}

This is the function for the command Init in gut.

If selectProfile failed (e.g. pass ins't installed), no initial commit is made ( executor.Commit() is never called).
However, the repo is initialised.
When gut checks if the repo is in detached head, it fails because there isn't any commit (so no HEAD)

@julien040 julien040 self-assigned this Feb 26, 2023
@julien040 julien040 added the bug Something isn't working label Feb 26, 2023
@julien040 julien040 linked a pull request Feb 26, 2023 that will close this issue
julien040 added a commit that referenced this issue Feb 26, 2023
If profile initialisation fails on a new repo, a repo would be initialised.
However, no commit would be made.
This lead to issue when gut tries to figured out the HEAD. It couldn't because there isn't any commits.

To solve this issue, initialisation of a git repo is now made after the profile selection. If selection fails, it exits.
Therefore, the repo won't be left in a state initialised but without any commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant