-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
54 additions
and
28 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/FileSystem-Git.package/FileSystemGitRepository.class/instance/cloneExternalFrom..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
git porcelain | ||
cloneExternalFrom: aStringOrUrl | ||
| directory children | | ||
directory := repository workingDir. | ||
children := directory children. | ||
(children isEmpty or: [children size = 1 and: [children first basename = '.git']]) | ||
ifFalse: [^ self error: 'Target directory is not empty']. | ||
directory deleteAll. | ||
self externalCommand: ('git clone "{1}" "{2}"' format: {aStringOrUrl. directory pathName}). |
24 changes: 9 additions & 15 deletions
24
src/FileSystem-Git.package/FileSystemGitRepository.class/instance/cloneFrom..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
git porcelain | ||
cloneFrom: aStringOrUrl | ||
| url remoteRefs head | | ||
url := aStringOrUrl asUrl. | ||
self addRemote: 'origin' url: aStringOrUrl. | ||
remoteRefs := self fetchFrom: 'origin'. | ||
head := self remoteHead: remoteRefs. | ||
head ifNotNil: [self unitOfWork updateHeadToRef: head message: 'clone: from ', url]. | ||
self unitOfWork allReferencesPrefixedWith: 'refs/remotes/origin/' | ||
do: [:each | | branchName | | ||
branchName := each allButFirst: 'refs/remotes/origin/' size. | ||
self unitOfWork | ||
updateRef: 'refs/heads/', branchName | ||
to: (self unitOfWork resolveRef: each); | ||
setUpstreamRemoteOfBranchNamed: branchName to: 'origin'; | ||
setUpstreamRefOfBranchNamed: branchName | ||
to: (self expandRemoteRef: branchName)]. | ||
GitFeatureFlags externalFetchAndPush | ||
ifTrue: [self cloneExternalFrom: aStringOrUrl] | ||
ifFalse: [[self cloneInternalFrom: aStringOrUrl] | ||
on: ConnectionClosed | ||
do: [:exception | | ||
self | ||
handleConnectionClosed: exception | ||
whileTryingTo: 'clone' | ||
ifRetry: [self cloneFrom: aStringOrUrl]]]. |
17 changes: 17 additions & 0 deletions
17
src/FileSystem-Git.package/FileSystemGitRepository.class/instance/cloneInternalFrom..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
git porcelain | ||
cloneInternalFrom: aStringOrUrl | ||
| url remoteRefs head | | ||
url := aStringOrUrl asUrl. | ||
self addRemote: 'origin' url: aStringOrUrl. | ||
remoteRefs := self fetchInternalFrom: 'origin'. | ||
head := self remoteHead: remoteRefs. | ||
head ifNotNil: [self unitOfWork updateHeadToRef: head message: 'clone: from ', url]. | ||
self unitOfWork allReferencesPrefixedWith: 'refs/remotes/origin/' | ||
do: [:each | | branchName | | ||
branchName := each allButFirst: 'refs/remotes/origin/' size. | ||
self unitOfWork | ||
updateRef: 'refs/heads/', branchName | ||
to: (self unitOfWork resolveRef: each); | ||
setUpstreamRemoteOfBranchNamed: branchName to: 'origin'; | ||
setUpstreamRefOfBranchNamed: branchName | ||
to: (self expandRemoteRef: branchName)]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
src/Squot.package/SqueakWorkingCopy.class/instance/cloneFrom..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
git-operations | ||
cloneFrom: aStringOrUrl | ||
self handleCredentialsDuring: [ | remote refs head | | ||
remote := self fsgitRepository addRemote: 'origin' url: aStringOrUrl asUrl. | ||
refs := self fsgitRepository fetchFrom: remote name. | ||
head := self fsgitRepository remoteHead: refs. | ||
head ifNotNil: [ | branchName trackingRef branch commit | | ||
branchName := head allButFirst: 'refs/heads/' size. | ||
trackingRef := remote trackingRefOf: head. | ||
commit := self unitOfWork objectReferenced: trackingRef. | ||
branch := (self createBranchNamed: branchName at: commit) ifNil: [^ self]. | ||
self setUpstreamRemoteName: remote name andRef: branchName for: branch. | ||
self updateSymbolicHeadToRef: branch]]. | ||
| gitHead target | | ||
self handleCredentialsDuring: [self fsgitRepository cloneFrom: aStringOrUrl]. | ||
gitHead := self unitOfWork ref: self headRefBasename. | ||
gitHead ifNil: [^ self error: 'No HEAD found after clone.']. | ||
target := self unitOfWork objectReferenced: self headRefBasename. | ||
(gitHead isSymbolic and: [self isGitBranchRef: gitHead targetRef]) ifTrue: [ | branchName branch | | ||
branchName := gitHead targetRef allButFirst: self gitBranchesBaseName size. | ||
branch := self createBranchNamed: branchName at: target. | ||
self setUpstreamRemoteName: self unitOfWork remoteNames first andRef: branchName for: branch. | ||
target := branch]. | ||
self updateSymbolicHeadTo: target. |
3 changes: 3 additions & 0 deletions
3
src/Squot.package/SqueakWorkingCopy.class/instance/isGitBranchRef..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
refs | ||
isGitBranchRef: aString | ||
^ aString beginsWith: self gitBranchesBaseName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters