Skip to content

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

Closed as not planned

Description

@vedavidhbudimuri
No description provided.

Activity

  1. thacoon commented on Apr 14, 2022

    @thacoon

    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
    }
  2. thacoon commented on Apr 25, 2022

    @thacoon

    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.

  3. github-actions commented on Feb 23, 2024

    @github-actions

    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!

  4. added
    stale
    on Feb 23, 2024
  5. added
    bug
    good first issue
    help wanted
    and removed
    stale
    on Mar 11, 2024
  6. github-actions commented on Jun 28, 2024

    @github-actions

    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!

  7. added
    stale
    on Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issuehelp wantedstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions