Skip to content

commited file still in staging zone after checkout #1642

@vincentDcmps

Description

@vincentDcmps

hello,

I use your library to improve automatic update on my local infrastructure.
I check for some docker image release and commit image in a new dedicated branch.
so my workflow is following:

  • create a branch
  • modify targeting file
  • checkout with keep option enable
  • add and commit file
  • checkout on master without keep option

but in the case where I have another file modify in the worktree who are not commit by my worklow I have a weird behavior when I come back on my main branch file commited in the last commit are always in staging zone.

in a normal git behavor once i Checkout on main branch I need just to have the file modify but not staged and nothing else in the stage zone.

code is the following for information

func (g *GitFileUpdater) CommitImage(image *dockerImage.DockerImage) bool {
	slog.Debug(fmt.Sprintf("commit of image %s in file %s", g.File.Path, image.Name))
	w, err := g.GitUpdater.Repository.Worktree()
	if err != nil {
		slog.Error(err.Error())
		return false
	}
	err = w.Checkout(&git.CheckoutOptions{
		Branch: g.Branch.Name(), Keep: true,
	})
	if err != nil {
		slog.Error(err.Error(), "stage", "Checkout")
		return false
	}
	_, err = w.Add(g.File.Path)
	if err != nil {
		slog.Error(err.Error(), "stage", "add")
		return false
	}
	commitmsg := fmt.Sprintf("update (%s): %s to %s", g.File.GetFileName(), image.Name, image.NewTag)
	_, err = w.Commit(commitmsg, &git.CommitOptions{
		Author: &object.Signature{
			Name:  "nomad-image-updater",
			Email: "",
			When:  time.Now(),
		},
	})
	if err != nil {
		slog.Error(err.Error(), "stage", "commit")
		return false
	}
	w.Checkout(&git.CheckoutOptions{
		Branch: g.GitUpdater.ReferenceBranch,
		})

	return true
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions