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

Fix "fatal: destination path … already exists" on checkout #861

Conversation

norio-nomura
Copy link
Contributor

git rev-parse --git-dir returns not only relative path but also absolute path. When absolute path was returned, it caused "fatal: destination path" error.

% git rev-parse --git-dir
.git
% cd Carthage/Checkouts/Argo
% git rev-parse --git-dir
/Users/norio/Documents/workspace/github/Carthage/.git/modules/Carthage/Checkouts/Argo
% 

`git rev-parse --git-dir` returns not only relative path but also
absolute path. When absolute path was returned, it caused
"fatal: destination path" error.
@norio-nomura norio-nomura changed the title Fix "fatal: destination path … already exists" Fix "fatal: destination path … already exists" on checkout Oct 23, 2015
@mdiep
Copy link
Member

mdiep commented Oct 24, 2015

Good catch!

Using a relative path makes me a little uneasy. Could we use NSString.absolutePath to test if it's absolute and make it absolute if it's not?

@norio-nomura
Copy link
Contributor Author

Oh, this PR still have a bug.
When relativeOrAbsoluteGitDirectory is relative, that is not based on current directory of defaultManager().
It needs to making absolute path based on directoryURL.

@norio-nomura
Copy link
Contributor Author

Thanks for reviewing.
I changed to making absolute path as your review.

if (relativeOrAbsoluteGitDirectory as NSString).absolutePath {
absoluteGitDirectory = relativeOrAbsoluteGitDirectory
} else {
absoluteGitDirectory = (directoryURL.path! as NSString).stringByAppendingPathComponent(relativeOrAbsoluteGitDirectory)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directoryURL.URLByAppendingPathComponent would be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be as follows?:

absoluteGitDirectory = directoryURL.URLByAppendingPathComponent(relativeOrAbsoluteGitDirectory).path!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better as follows:

var absoluteGitDirectory: String?
if (relativeOrAbsoluteGitDirectory as NSString).absolutePath {
    absoluteGitDirectory = relativeOrAbsoluteGitDirectory
} else {
    absoluteGitDirectory = directoryURL.URLByAppendingPathComponent(relativeOrAbsoluteGitDirectory).path
}
var isDirectory: ObjCBool = false
let directoryExists = absoluteGitDirectory.map { NSFileManager.defaultManager().fileExistsAtPath($0, isDirectory: &isDirectory) } ?? false

@mdiep
Copy link
Member

mdiep commented Oct 24, 2015

That looks great! Thanks!

mdiep added a commit that referenced this pull request Oct 24, 2015
…y-exists-on-checkout

Fix "fatal: destination path … already exists" on checkout
@mdiep mdiep merged commit 76afa42 into Carthage:master Oct 24, 2015
@norio-nomura norio-nomura deleted the fix-destination-path-already-exists-on-checkout branch October 24, 2015 14:14
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

Successfully merging this pull request may close these issues.

None yet

3 participants