Skip to content

Commit

Permalink
Allow to push branch to any remote
Browse files Browse the repository at this point in the history
  • Loading branch information
j4yk committed May 29, 2019
1 parent 19fc35d commit 4e9ac24
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 32 deletions.
34 changes: 10 additions & 24 deletions src/Squit.package/SquitBrowser.class/instance/actionBranchPush.st
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
actions on branches
actionBranchPush
| historian branchName workingCopy repository gitRepository |
self hasBranchSelection ifFalse: [^ self].
selectedHistorian isRemoteTrackingHistorian ifTrue:
[^ self inform: 'You should not push a remote-tracking branch. Push a local branch instead.'].
historian := selectedHistorian.
branchName := historian name.
workingCopy := self projectSelection.
repository := workingCopy repository.
gitRepository := repository gitRepository.
self checkTrackedBranchOrOfferChange: historian ifUnsupported: [^ self].
[self withRemoteErrorHandlingDo:
[self handlingCredentialsOf: historian
do: [workingCopy repository
exportToUpstream: historian
ifNone: [
self offerToSetUpstreamBranchOf: historian shortName
in: gitRepository
ifCanceled: [^ self].
^ self actionBranchPush "try again"]]
ifCanceled: [^ self]]]
on: GitNonFastForwardPushUpdatesDetected do: [:e |
(self confirm: 'Warning: the tip of your branch is behind its remote counterpart. Do you want to force the push anyway?')
ifTrue: [e proceedWithForcedPush]
ifFalse: [^ self]].
self pushSelectedHistorianByDoing:
[:gitRepository |
self checkTrackedBranchOrOfferChange: selectedHistorian ifUnsupported: [^ self].
selectedHistorian repository
exportToUpstream: selectedHistorian
ifNone: [
self offerToSetUpstreamBranchOf: selectedHistorian shortName
in: gitRepository
ifCanceled: [^ self].
^ self actionBranchPush "try again"]].
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
actions on branches
actionPushToRemote: aString
self pushSelectedHistorianByDoing:
[selectedHistorian repository
export: selectedHistorian
withName: (UIManager default
request: 'Branch name at remote:'
initialAnswer: selectedHistorian shortName)
toRemoteNamed: aString].
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
ui menu
menuBranchListHook: aMenu
<menuBranchListShifted: false>
| commands activeBranchName branchStatus onlyActive onlyInactive onlyLocal onlyRemote onlyWithUpstream |
| activeBranchName branchStatus onlyActive onlyInactive onlyLocal onlyRemote onlyWithUpstream hasRemotes |
self hasBranchSelection ifFalse: [^ aMenu].
activeBranchName := self projectSelection loadedHistorian shortName.
onlyLocal := selectedHistorian isRemoteTrackingHistorian not.
onlyRemote := selectedHistorian isRemoteTrackingHistorian.
onlyActive := selectedHistorian = self projectSelection loadedHistorian.
onlyInactive := selectedHistorian ~= self projectSelection loadedHistorian.
onlyWithUpstream := selectedHistorian hasUpstreamHistorian.
hasRemotes := self projectSelection repository hasRemotes.
branchStatus := true caseOf:
{[onlyRemote] -> ['(remote-tracking branch)'].
[onlyActive] -> ['(currently checked out)']}
otherwise: ''.
aMenu addTitle: 'Branch ', selectedHistorian shortName,
(branchStatus ifNotEmpty: [String cr, branchStatus]).
commands :=
self buildMenu: aMenu from:
{{'Switch to this branch'. #actionBranchSwitch. 'Stash uncommitted changes on the active branch, then checkout the selected branch.'. onlyLocal & onlyInactive}.
{'Switch, but keep uncommitted changes'. #actionBranchSwitchMoveOver. 'Checkout the selected branch and try to move over uncommitted changes to it.'. onlyLocal & onlyInactive}.
{'Create a new branch and switch to it'. #actionBranchCreateAndSwitch. 'Create a new branch at the same commit as this branch and switch to the new branch'. onlyRemote}.
{'Discard uncommitted changes'. #actionBranchResetToTip. nil. onlyActive}.
{'Merge into ', activeBranchName. #actionBranchMerge. 'Merge this branch into your active branch ', activeBranchName. onlyInactive}.
'-'.
{'Push'. #actionBranchPush. nil. onlyLocal}.
{'Set upstream branch'. #actionSetUpstreamBranch. nil. onlyLocal}.
{'Push'. #actionBranchPush. nil. onlyLocal}}.
(onlyLocal and: [hasRemotes]) ifTrue:
[aMenu add: 'Push to' subMenu: self remotesPushSubMenu].
self buildMenu: aMenu from:
{{'Set upstream branch'. #actionSetUpstreamBranch. nil. onlyLocal}.
{'Remove upstream branch at the remote'. #actionBranchRemoveUpstream. 'Push the deletion of the remote branch'. onlyWithUpstream}.
'-'.
{'Rename'. #actionBranchRename. nil. onlyLocal}.
{'Remove'. #actionBranchRemove}.
'-'.
{'Compare with working copy'. #actionBranchDiffWithWorkingCopy}}.

self buildMenu: aMenu from: commands.

^ aMenu
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
private
pushSelectedHistorianByDoing: aBlock
| historian branchName workingCopy repository gitRepository |
self hasBranchSelection ifFalse: [^ self].
selectedHistorian isRemoteTrackingHistorian ifTrue:
[^ self inform: 'You should not push a remote-tracking branch. Push a local branch instead.'].
historian := selectedHistorian.
branchName := historian name.
workingCopy := self projectSelection.
repository := workingCopy repository.
gitRepository := repository gitRepository.
[self withRemoteErrorHandlingDo:
[self handlingCredentialsOf: historian
do: [aBlock cull: gitRepository]
ifCanceled: [^ self]]]
on: GitNonFastForwardPushUpdatesDetected do: [:e |
(self confirm: 'Warning: the tip of your branch is behind its remote counterpart. Do you want to force the push anyway?')
ifTrue: [e proceedWithForcedPush]
ifFalse: [^ self]].
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ui menu
remotesMenuWithItems: aBlock
| remotesMenuSpec |
remotesMenuSpec := ToolBuilder default pluggableMenuSpec new.
(self chooseableRemoteNamesFrom: self projectSelection repository gitRepository) sorted do:
[:each | aBlock value: remotesMenuSpec value: each].
^ ToolBuilder default buildPluggableMenu: remotesMenuSpec

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ui menu
remotesPushSubMenu
^ self remotesMenuWithItems:
[:menu :remote |
menu
add: remote
action: (MessageSend
receiver: self
selector: #actionPushToRemote:
argument: remote)]
8 changes: 6 additions & 2 deletions src/Squit.package/SquitBrowser.class/methodProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"actionBranchCreateAndSwitch" : "jr 3/14/2019 23:02",
"actionBranchDiffWithWorkingCopy" : "jr 1/14/2018 15:26",
"actionBranchMerge" : "jr 11/21/2018 21:50",
"actionBranchPush" : "jr 12/1/2018 23:47",
"actionBranchPush" : "jr 5/30/2019 01:25",
"actionBranchRemove" : "jr 4/6/2018 23:47",
"actionBranchRemoveUpstream" : "jr 12/1/2018 23:47",
"actionBranchRename" : "pre 6/15/2018 16:01",
Expand Down Expand Up @@ -64,6 +64,7 @@
"actionProjectRename" : "jr 4/7/2018 00:14",
"actionPull" : "jr 12/1/2018 23:48",
"actionPush" : "jr 4/14/2017 00:05",
"actionPushToRemote:" : "jr 5/30/2019 01:33",
"actionRemoteAdd" : "jr 10/14/2018 22:15",
"actionRemoteAddContinue:" : "jr 10/14/2018 22:22",
"actionSelfUpdate" : "fn 4/15/2017 10:53",
Expand Down Expand Up @@ -128,7 +129,7 @@
"loadBranchList" : "jr 4/29/2018 19:36",
"loadCommitList" : "jr 6/5/2017 00:35",
"loadedSelectedObject" : "jr 5/13/2017 19:40",
"menuBranchListHook:" : "jr 10/17/2018 13:04",
"menuBranchListHook:" : "jr 5/30/2019 01:20",
"menuCommitListHook:" : "jr 10/17/2018 13:33",
"menuObjectListHook:" : "jr 10/17/2018 11:25",
"menuProjectListHook:" : "jr 10/17/2018 13:31",
Expand Down Expand Up @@ -156,9 +157,12 @@
"projectList" : "fn 4/11/2017 11:48",
"projectListMenu:" : "fn 4/11/2017 15:38",
"projectSelection" : "fn 4/11/2017 17:12",
"pushSelectedHistorianByDoing:" : "jr 5/30/2019 01:27",
"rebuildCommitList" : "jr 6/5/2017 00:49",
"refresh" : "jr 6/5/2017 00:24",
"remoteUrlOf:" : "jr 5/22/2017 00:04",
"remotesMenuWithItems:" : "jr 5/30/2019 01:12",
"remotesPushSubMenu" : "jr 5/30/2019 01:14",
"requestAndSetUpstreamBranchOf:in:ifCanceled:" : "jr 11/20/2018 22:12",
"requestAndStoreCredentialsFor:remoteUrl:ifCanceled:" : "jr 4/26/2017 14:17",
"searchTerm" : "fn 4/11/2017 18:33",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
synchronizing
export: aHistorian withName: branchString toRemoteNamed: remoteString
self withCredentialsDo:
[gitRepository push: {aHistorian name -> branchString} toRemote: remoteString]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testing
hasRemotes
^ gitRepository remoteNames notEmpty
2 changes: 2 additions & 0 deletions src/Squit.package/SquitRepository.class/methodProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
"delete:" : "jr 4/14/2017 00:21",
"exists" : "jr 4/27/2017 15:47",
"expandShortRefName:" : "jr 2/8/2017 14:25",
"export:withName:toRemoteNamed:" : "jr 5/30/2019 01:30",
"exportToUpstream:ifNone:" : "jr 4/12/2017 14:47",
"exportVersionAt:to:" : "jr 1/26/2017 14:03",
"extension:ifPresent:ifAbsent:" : "jr 3/6/2017 19:41",
"filesystemExtension" : "jr 3/6/2017 19:42",
"flushCaches" : "jr 7/22/2017 22:28",
"gitRepository" : "jr 1/11/2017 18:14",
"hasRemotes" : "jr 5/30/2019 01:20",
"hash" : "jr 4/14/2017 00:55",
"historianForTemporaryVersions" : "jr 6/29/2017 17:13",
"historianForTemporaryVersionsOn:" : "jr 6/29/2017 17:45",
Expand Down

0 comments on commit 4e9ac24

Please sign in to comment.