Skip to content

Commit

Permalink
Revert "Fix fetching a local repository with relative path"
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo authored Nov 14, 2017
1 parent f3d43f3 commit 31f0d72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
27 changes: 13 additions & 14 deletions Source/CarthageKit/Git.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public struct FetchCache {
/// Amount of time before a git repository is fetched again. Defaults to 1 minute
public static var fetchCacheInterval: TimeInterval = 60.0

private static var lastFetchTimes: [URL : TimeInterval] = [:]
private static var lastFetchTimes: [GitURL : TimeInterval] = [:]

internal static func clearFetchTimes() {
lastFetchTimes.removeAll()
}

internal static func needsFetch(forURL url: URL) -> Bool {
internal static func needsFetch(forURL url: GitURL) -> Bool {
guard let lastFetch = lastFetchTimes[url] else {
return true
}
Expand All @@ -32,8 +32,10 @@ public struct FetchCache {
return !(0...fetchCacheInterval).contains(difference)
}

fileprivate static func updateLastFetchTime(forURL url: URL) {
lastFetchTimes[url] = Date().timeIntervalSince1970
fileprivate static func updateLastFetchTime(forURL url: GitURL?) {
if let url = url {
lastFetchTimes[url] = Date().timeIntervalSince1970
}
}
}

Expand Down Expand Up @@ -88,21 +90,18 @@ public func cloneRepository(_ cloneURL: GitURL, _ destinationURL: URL, isBare: B

return launchGitTask(arguments + [ "--quiet", cloneURL.urlString, destinationURL.path ])
.on(completed: {
FetchCache.updateLastFetchTime(forURL: destinationURL)
FetchCache.updateLastFetchTime(forURL: cloneURL)
})
}

/// Returns a signal that completes when the fetch completes successfully.
public func fetchRepository(_ repositoryFileURL: URL, refspec: String? = nil) -> SignalProducer<String, CarthageError> {
public func fetchRepository(_ repositoryFileURL: URL, remoteURL: GitURL? = nil, refspec: String? = nil) -> SignalProducer<String, CarthageError> {
precondition(repositoryFileURL.isFileURL)

var arguments = [ "fetch", "--prune", "--quiet" ]

// Use the `origin` remote which should have been set up.
//
// See https://github.com/Carthage/Carthage/issues/968
// and https://github.com/Carthage/Carthage/pull/2125.
arguments.append("origin")
if let remoteURL = remoteURL {
arguments.append(remoteURL.urlString)
}

// Specify an explict refspec that fetches tags for pruning.
// See https://github.com/Carthage/Carthage/issues/1027 and `man git-fetch`.
Expand All @@ -114,7 +113,7 @@ public func fetchRepository(_ repositoryFileURL: URL, refspec: String? = nil) ->

return launchGitTask(arguments, repositoryFileURL: repositoryFileURL)
.on(completed: {
FetchCache.updateLastFetchTime(forURL: repositoryFileURL)
FetchCache.updateLastFetchTime(forURL: remoteURL)
})
}

Expand Down Expand Up @@ -488,7 +487,7 @@ public func addSubmoduleToRepository(_ repositoryFileURL: URL, _ submodule: Subm
.flatMap(.merge) { submoduleExists -> SignalProducer<(), CarthageError> in
if submoduleExists {
// Just check out and stage the correct revision.
return fetchRepository(submoduleDirectoryURL, refspec: "+refs/heads/*:refs/remotes/origin/*")
return fetchRepository(submoduleDirectoryURL, remoteURL: fetchURL, refspec: "+refs/heads/*:refs/remotes/origin/*")
.then(
launchGitTask(
["config", "--file", ".gitmodules", "submodule.\(submodule.name).url", submodule.url.urlString],
Expand Down
4 changes: 2 additions & 2 deletions Source/CarthageKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1225,13 +1225,13 @@ public func cloneOrFetch(
.flatMap(.merge) { isRepository -> SignalProducer<(ProjectEvent?, URL), CarthageError> in
if isRepository {
let fetchProducer: () -> SignalProducer<(ProjectEvent?, URL), CarthageError> = {
guard FetchCache.needsFetch(forURL: repositoryURL) else {
guard FetchCache.needsFetch(forURL: remoteURL) else {
return SignalProducer(value: (nil, repositoryURL))
}

return SignalProducer(value: (.fetching(dependency), repositoryURL))
.concat(
fetchRepository(repositoryURL, refspec: "+refs/heads/*:refs/heads/*")
fetchRepository(repositoryURL, remoteURL: remoteURL, refspec: "+refs/heads/*:refs/heads/*")
.then(SignalProducer<(ProjectEvent?, URL), CarthageError>.empty)
)
}
Expand Down

0 comments on commit 31f0d72

Please sign in to comment.