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

Cloned repository is dirty #1773

Open
vshulgin opened this issue Mar 10, 2020 · 5 comments
Open

Cloned repository is dirty #1773

vshulgin opened this issue Mar 10, 2020 · 5 comments

Comments

@vshulgin
Copy link

vshulgin commented Mar 10, 2020

Reproduction steps

Clone remote repository to local folder

var options = new CloneOptions
  {
    CredentialsProvider = (url, user, cred) => new UsernamePasswordCredentials { Username = userName, Password = passWord }
    };
Repository.Clone(_remoteUrl, _localPath, options);

Expected behavior

git status must return nothing to commit, working tree clean

Actual behavior

git status returns

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    Managers/ashish.reddy-automation-eng.productsem-20191015.yaml
        deleted:    Managers/ashish.reddy-coaching-eng.productsem-20191003.yaml
        deleted:    Managers/ashish.reddy-coaching-eng.productsem-20191015.yaml
        deleted:    Managers/gowtham.ramachandra-coaching-Eng.Manager-20191008.yaml
        deleted:    Managers/gowtham.ramachandra-coaching-Eng.Manager-20191009.yaml
        deleted:    Managers/gowtham.ramachandra-process-improvement-Eng.Manager-20191008.yaml
        deleted:    Managers/radhesh.radhakrishnan-process-improvement-eng.manager-20191011.yaml

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   DataStructures/automation-schema.json
        modified:   DataStructures/coaching-schema.json
        modified:   DataStructures/process-improvement-schema.json

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        _git2_a18992

Version of LibGit2Sharp (release number or SHA1)

0.26.2

Operating system(s) tested; .NET runtime tested

Windows 10 Version 2004 10.0.19041
.Net Core 3.1

@ethomson
Copy link
Member

How are you configuring your line endings? Do your line endings (as checked in to the repository) match the promises that you've made with your configuration?

A mismatch between your .gitattributes configuration (and yes, please do use .gitattributes, not core.autocrlf) and the contents in the repository are almost always to blame for this behavior.

@DaveSenn
Copy link

I've the same problem (also with version 0.26.2 on Windows 10). Cloning a new repo results in the clone repo conaining a symlinkd with name "_git2_a05268".

I tested without a .gitattributes files and `then again with the following file:

###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################

* text=auto

*.bmp binary
*.dll binary
*.gif binary
*.jpg binary
*.png binary
*.ico binary
*.snk binary
*.exe binary
*.dll binary
*.pdb binary
*.xlsm binary
*.xlsx binary
*.xls binary
*.dox binary
*.doc binary
*.docx binary
*.pdf binary
*.obj binary
*.exp binary
*.iobj binary
*.ipdb binary
*.lib binary
*.jar binary
*.zip binary
*.pch binary
*.res binary
*.tlog binary
*.db binary
*.cache binary

*.ascx text eol=crlf
*.cd text eol=crlf
*.cmd text eol=crlf
*.coffee text eol=crlf
*.config text eol=crlf
*.cs text eol=crlf diff=csharp 
*.csproj text eol=crlf merge=union 
*.cshtml text eol=crlf
*.css text eol=crlf
*.dtd text eol=crlf
*.edmx text eol=crlf
*.htm text eol=crlf
*.html text eol=crlf
*.js text eol=crlf
*.json text eol=crlf
*.msbuild text eol=crlf
*.nuspec text eol=crlf
*.resx text eol=crlf
*.ruleset text eol=crlf
*.StyleCop text eol=crlf
*.targets text=auto
*.tt text=auto
*.txt text eol=crlf
*.vb text eol=crlf
*.vbhtml text eol=crlf
*.vbproj text eol=crlf merge=union 
*.vbs text eol=crlf
*.wsf text eol=crlf
*.xml text eol=crlf
*.xunit text eol=crlf
*.sln text eol=crlf merge=union
*.cpp text eol=crlf
*.c text eol=crlf
*.h text eol=crlf
*.mc text eol=crlf
*.def text eol=crlf
*.rc text eol=crlf
*.rc2 text eol=crlf
*.vcxproj text eol=crlf
*.manifest text eol=crlf
*.shfbproj text eol=crlf
*.rdl text eol=crlf
*.rds text eol=crlf
*.rptproj text eol=crlf

> dir
Capture

My code (.NET Core 3.1):

public static void Clone( String repoPath, String httpUrl )
{
	var credentials = GetGitCredentials();

	var cloneOptions = new CloneOptions
	{
		CredentialsProvider =
			( url, user, cred ) => new UsernamePasswordCredentials { Username = credentials.Username, Password = credentials.Password }
	};
	Repository.Clone( httpUrl, repoPath, cloneOptions );
}

@vshulgin
Copy link
Author

There is .gitattributes file in repository

* text=auto
*.yaml text eol=lf

Files in this repository re-normalized with git add --renormalize .
Cloning with git clone results to clean repository, cloning with libgit2sharp results to dirty repository with following status:

On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    Managers/ashish.reddy-automation-eng.productsem-20191015.yaml
        deleted:    Managers/ashish.reddy-coaching-eng.productsem-20191003.yaml
        deleted:    Managers/ashish.reddy-coaching-eng.productsem-20191015.yaml
        deleted:    Managers/gowtham.ramachandra-coaching-Eng.Manager-20191008.yaml
        deleted:    Managers/gowtham.ramachandra-coaching-Eng.Manager-20191009.yaml
        deleted:    Managers/gowtham.ramachandra-process-improvement-Eng.Manager-20191008.yaml
        deleted:    Managers/radhesh.radhakrishnan-process-improvement-eng.manager-20191011.yaml

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   DataStructures/automation-schema.json
        modified:   DataStructures/coaching-schema.json
        modified:   DataStructures/process-improvement-schema.json

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        _git2_a11820

As you may see, some files are deleted. Is it because of line-endings? I don't think so.
Also, untracked file _git2_a11820 - what is this? It is windows shortcut, pointing to un-existing directory, the name of target directory is the same as name of parent directory where the repository is cloned, i.e. repository is cloned to C:\temp\testing\eng.hub and mentioned shortcut point to C:\temp\testing\eng.hub\testing.

Any ideas?

@ethomson
Copy link
Member

@TalyGin Ah, sorry, I see that there are deleted files now. Somebody has added files without respecting case sensitivity. Do you have a Linux user? If not, somebody has turned off core.ignorecase. They should not have. More information is available here: https://serverfault.com/a/951979/98611

@ethomson
Copy link
Member

Regarding the _git2_a11820 junction, that was a bug during core.symlink detection. Here's the libgit2 issue: libgit2/libgit2#5147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants