Skip to content

Commit

Permalink
Add force push button
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusDoe committed May 18, 2024
1 parent 0f2f84d commit 88123af
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
git porcelain - external
externalPush: aCollectionOfBranchNamesAndAssociations toRemote: remoteName
externalPush: aCollectionOfBranchNamesAndAssociations toRemote: remoteName force: forceBoolean
aCollectionOfBranchNamesAndAssociations do: [:branch |
self externalGitDo: ('push {1} {2}:{3}' format: {remoteName. branch key. branch value})].
self externalGitDo: ('push {1}{2} {3}:{4}' format: {
forceBoolean ifTrue: ['-f '] ifFalse: [''].
remoteName. branch key. branch value})].
self repository changed: #allReferences.
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
git porcelain
push: aCollectionOfBranchNamesAndAssociations toRemote: remoteName
"self push: { 'master' } toRemote: 'origin'.
self push: { 'branch' -> 'remoteBranchName' } toRemote: 'origin'"
GitFeatureFlags externalFetchAndPush
ifTrue: [self externalPush: aCollectionOfBranchNamesAndAssociations toRemote: remoteName]
ifFalse: [
[self
pushToRemote: remoteName
update: aCollectionOfBranchNamesAndAssociations
deleteRemoteBranches: Array empty]
on: ConnectionClosed
do: [:exception |
self
handleConnectionClosed: exception
whileTryingTo: 'push'
ifRetry: [self push: aCollectionOfBranchNamesAndAssociations toRemote: remoteName]]]
self push: aCollectionOfBranchNamesAndAssociations toRemote: remoteName force: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
git porcelain
push: aCollectionOfBranchNamesAndAssociations toRemote: remoteName force: forceBoolean
"self push: { 'master' } toRemote: 'origin'.
self push: { 'branch' -> 'remoteBranchName' } toRemote: 'origin'"
GitFeatureFlags externalFetchAndPush
ifTrue: [self
externalPush: aCollectionOfBranchNamesAndAssociations
toRemote: remoteName
force: forceBoolean]
ifFalse: [
[self
pushToRemote: remoteName
update: aCollectionOfBranchNamesAndAssociations
deleteRemoteBranches: Array empty
force: forceBoolean]
on: ConnectionClosed
do: [:exception |
self
handleConnectionClosed: exception
whileTryingTo: 'push'
ifRetry: [self
push: aCollectionOfBranchNamesAndAssociations
toRemote: remoteName
force: forceBoolean]]]
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
git porcelain
pushToRemote: remoteName update: aCollectionOfBranchNamesAndAssociations deleteRemoteBranches: aCollectionOfRemoteBranchNames
| remote url protocol updateRefs deleteRefs report |
remote := self unitOfWork remoteNamed: remoteName.
url := remote url.
updateRefs := aCollectionOfBranchNamesAndAssociations collect: [:each |
each value == each
ifTrue: [(self unitOfWork expandRef: each) -> (self unitOfWork objectReferenced: each)]
ifFalse: [(self expandRemoteRef: each value) "remote name" -> (self unitOfWork objectReferenced: each key "local name")]].
(updateRefs detect: [:each | each value isNil] ifNone: []) ifNotNil:
[:badUpdate | GitRefDoesNotExistYet new
repository: repository;
missingRef: badUpdate key;
signal: 'Nothing to push for ', badUpdate key asString].
deleteRefs := aCollectionOfRemoteBranchNames collect: [:each | self expandRemoteRef: each].
protocol := GitAbstractProtocol url: url.
protocol remote: remote.
report := protocol pushReferences: updateRefs of: repository deleting: deleteRefs.
updateRefs do: [:refAndCommit |
(report successes includes: refAndCommit key) ifTrue:
[self unitOfWork
updateRef: refAndCommit key
ofRemote: remoteName
to: refAndCommit value hexHash
message: 'update by push']].
deleteRefs do: [:each |
(report successes includes: each) ifTrue:
[self unitOfWork deleteRef:
(self unitOfWork refName: each forRemote: remoteName)]].
^ self
pushToRemote: remoteName
update: aCollectionOfBranchNamesAndAssociations
deleteRemoteBranches: aCollectionOfRemoteBranchNames
force: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
git porcelain
pushToRemote: remoteName update: aCollectionOfBranchNamesAndAssociations deleteRemoteBranches: aCollectionOfRemoteBranchNames force: forceBoolean
| remote url protocol updateRefs deleteRefs pushBlock report |
remote := self unitOfWork remoteNamed: remoteName.
url := remote url.
updateRefs := aCollectionOfBranchNamesAndAssociations collect: [:each |
each value == each
ifTrue: [(self unitOfWork expandRef: each) -> (self unitOfWork objectReferenced: each)]
ifFalse: [(self expandRemoteRef: each value) "remote name" -> (self unitOfWork objectReferenced: each key "local name")]].
(updateRefs detect: [:each | each value isNil] ifNone: []) ifNotNil:
[:badUpdate | GitRefDoesNotExistYet new
repository: repository;
missingRef: badUpdate key;
signal: 'Nothing to push for ', badUpdate key asString].
deleteRefs := aCollectionOfRemoteBranchNames collect: [:each | self expandRemoteRef: each].
protocol := GitAbstractProtocol url: url.
protocol remote: remote.
pushBlock := [protocol pushReferences: updateRefs of: repository deleting: deleteRefs].
report := forceBoolean
ifTrue: [pushBlock
on: GitNonFastForwardPushUpdatesDetected
do: [:notification | notification proceedWithForcedPush]]
ifFalse: [pushBlock value].
updateRefs do: [:refAndCommit |
(report successes includes: refAndCommit key) ifTrue:
[self unitOfWork
updateRef: refAndCommit key
ofRemote: remoteName
to: refAndCommit value hexHash
message: 'update by push']].
deleteRefs do: [:each |
(report successes includes: each) ifTrue:
[self unitOfWork deleteRef:
(self unitOfWork refName: each forRemote: remoteName)]].
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"expandRemoteRef:" : "pre 6/15/2018 16:04",
"externalCommand:" : "mad 5/18/2024 11:18",
"externalGitDo:" : "mad 12/20/2023 19:11",
"externalPush:toRemote:" : "mad 5/15/2024 20:53",
"externalPush:toRemote:force:" : "mad 5/18/2024 12:25",
"fetchAllExternalFrom:" : "mad 5/15/2024 20:56",
"fetchFrom:" : "mad 4/22/2024 17:34",
"fetchFromAll:" : "mad 4/22/2024 17:25",
Expand All @@ -31,9 +31,11 @@
"orphanedHead" : "jr 1/29/2017 22:52",
"performTerminalCommandTemplateReplacement:in:" : "mad 4/3/2024 16:18",
"pruneRefs:keep:" : "mad 4/7/2024 14:44",
"push:toRemote:" : "mad 4/22/2024 17:21",
"push:toRemote:" : "mad 5/18/2024 11:30",
"push:toRemote:force:" : "mad 5/18/2024 11:30",
"pushToRemote:deleteRemoteBranches:" : "jr 1/2/2017 10:18",
"pushToRemote:update:deleteRemoteBranches:" : "jr 7/23/2020 00:43",
"pushToRemote:update:deleteRemoteBranches:" : "mad 5/18/2024 11:28",
"pushToRemote:update:deleteRemoteBranches:force:" : "mad 5/18/2024 11:27",
"pushToUpstreamBranchOf:ifNone:" : "jr 3/4/2020 00:49",
"recursivelyCollectCommits:into:limit:" : "jr 3/2/2017 10:39",
"remoteHead:" : "mad 10/1/2023 16:52",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
git-operations
pushRef: aString
pushRef: aString force: forceBoolean
| remoteAndRef |
remoteAndRef := self upstreamRemoteNameAndRefFor: aString.
remoteAndRef ifNil: [^ self].
self handleCredentialsDuring: [
self fsgitRepository push: {aString -> remoteAndRef value} toRemote: remoteAndRef key]
self fsgitRepository push: {aString -> remoteAndRef value} toRemote: remoteAndRef key force: forceBoolean]
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"moveToNewRepositoryLocation:" : "mad 12/22/2023 17:50",
"name" : "mad 9/19/2023 11:52",
"name:" : "mad 12/8/2023 17:31",
"pushRef:" : "mad 9/18/2023 20:07",
"pushRef:force:" : "mad 5/18/2024 11:31",
"refChanged:" : "mad 5/15/2024 21:20",
"refName:" : "mad 6/3/2023 14:17",
"refsBaseName" : "mad 11/28/2023 15:33",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actions
actionForcePush: refString
(self confirm: 'Do you really want to force push? This might discard commits made by other members of your team.')
ifFalse: [^ self].
^ self actionPush: refString force: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
actions
actionForcePush
self activeWorkingCopyIfNilInformAnd: [^ self].
self actionForcePush: (self currentBranchIfNilInformAnd: [^ self]).
8 changes: 1 addition & 7 deletions src/Squot.package/SquotBrowser.class/instance/actionPush..st
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
actions
actionPush: refString
self activeWorkingCopyIfNilInformAnd: [^ self].
(self activeWorkingCopy isSqueakBranchRef: refString) ifFalse: [
(UIManager default confirm:
('The active ref ''{1}'' is not a branch. Push anyway?'
format: {refString}))
ifFalse: [^ self]].
self activeWorkingCopy pushRef: refString.
^ self actionPush: refString force: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
actions
actionPush: refString force: aBoolean
self activeWorkingCopyIfNilInformAnd: [^ self].
(self activeWorkingCopy isSqueakBranchRef: refString) ifFalse: [
(UIManager default confirm:
('The active ref ''{1}'' is not a branch. Push anyway?'
format: {refString}))
ifFalse: [^ self]].
self activeWorkingCopy pushRef: refString force: aBoolean.
5 changes: 5 additions & 0 deletions src/Squot.package/SquotBrowser.class/instance/otherMenu..st
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ otherMenu: aMenuSpec
add: 'Self-update'
target: self
selector: #actionSelfUpdate
argumentList: {};

add: 'Force push'
target: self
selector: #actionForcePush
argumentList: {}.
7 changes: 5 additions & 2 deletions src/Squot.package/SquotBrowser.class/methodProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"actionExportActiveProjectToSar" : "mad 1/9/2024 20:22",
"actionFetchAll" : "mad 9/19/2023 12:29",
"actionFixup:keepCurrentMessage:editMessage:" : "mad 4/5/2024 15:12",
"actionForcePush" : "mad 5/18/2024 11:33",
"actionForcePush:" : "mad 5/18/2024 11:32",
"actionMaterializeActiveCommit" : "mad 4/5/2024 19:31",
"actionMaterializeCherryPick:" : "mad 4/10/2024 17:07",
"actionMaterializeCommit:" : "mad 4/5/2024 19:30",
Expand All @@ -47,7 +49,8 @@
"actionPick:message:windowTitlePrefix:revert:amend:alwaysOpenDialog:" : "mad 4/5/2024 14:43",
"actionPull" : "mad 12/13/2023 18:03",
"actionPush" : "mad 9/26/2023 16:58",
"actionPush:" : "mad 9/26/2023 16:57",
"actionPush:" : "mad 5/18/2024 11:31",
"actionPush:force:" : "mad 5/18/2024 11:31",
"actionRebaseOntoActiveCommit" : "mad 4/5/2024 19:33",
"actionRebaseOntoCommit:" : "mad 4/7/2024 18:22",
"actionRefreshRefList" : "mad 10/24/2023 19:54",
Expand Down Expand Up @@ -138,7 +141,7 @@
"openDialogToShowChangeSets:windowTitle:" : "mad 10/22/2023 00:36",
"openDialogToShowChangeSetsFromCommit:to:" : "mad 10/22/2023 00:56",
"openDialogToShowChangeSetsFromImageTo:" : "mad 11/29/2023 16:48",
"otherMenu:" : "mad 10/24/2023 17:14",
"otherMenu:" : "mad 5/18/2024 11:37",
"parentForPick:" : "mad 4/5/2024 14:44",
"projectListMenu:" : "mad 4/3/2024 16:48",
"refChanged:" : "mad 5/15/2024 20:47",
Expand Down

0 comments on commit 88123af

Please sign in to comment.