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

IsClean method returns false even if the working directory has no unstaged/uncommitted changes #332

Open
vedavidhbudimuri opened this issue Jun 5, 2021 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@vedavidhbudimuri
Copy link

No description provided.

@thacoon
Copy link

thacoon commented Apr 14, 2022

I experience the same issue. I tried the solution from #390 but IsClean returns true in some cases even if there are 0 changed files with 0 additions and 0 deletions.

func pushChanges(repo *git.Repository, worktree *git.Worktree) error {
	status, err := worktree.Status()
	if err != nil {
		return err
	} else if status.IsClean() {
		log.Println("Nothing to commit")
		return nil
	}

	author := &object.Signature{Name: CommitterName, Email: CommitterEmail, When: time.Now()}
	_, err = worktree.Commit(CommitMessage, &git.CommitOptions{Author: author})
	if err != nil {
		return err
	}

	return repo.Push(&git.PushOptions{RemoteName: "origin", Auth: transfer.auth})
}

I think this happens if a file is deleted but a new file is created with the exact same data. So status.Staging is unmodified but status.Worktree will be set to Deleted and thus IsClean returns true but on GitHub it will show as an empty commit as nothing has changed.

func (s Status) IsClean() bool {
	for _, status := range s {
		if status.Worktree != Unmodified || status.Staging != Unmodified {
			return false
		}
	}

	return true
}

@thacoon
Copy link

thacoon commented Apr 25, 2022

I now think that IsClean() is working correctly but the issue was that deleted files were not staged correctly, related Issue is #223

My current workaround is to run

status, err := worktree.Status()
if err != nil {
	return err
}

for file, s := range status {
	if s.Worktree == git.Deleted {
		_, err = worktree.Add(file)
		if err != nil {
			return err
		}
	}
}

to also add deleted files as worktree.AddWithOptions(&git.AddOptions{Path: transfer.ChartLocation, All: true}) did not seem to do it. Then I also have no empty commits.

Copy link

To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.

This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.

We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.

Thanks for your understanding and cooperation!

@github-actions github-actions bot added the stale Issues/PRs that are marked for closure due to inactivity label Feb 23, 2024
@pjbgf pjbgf added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed and removed stale Issues/PRs that are marked for closure due to inactivity labels Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants