Skip to content

Commit 49b63a8

Browse files
committed
fix: Update "checkout branch" to first fetch branch list before attempting checkout (#823)
1 parent ff32ffe commit 49b63a8

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111
- Expanded Baseline Export to include XSL Transforms (#815)
12+
- Enhanced "Check out branch" to first refresh list of remote branches to eliminate failure due to stale information (#823)
1213

1314
### Fixed
1415
- Fix Import All not importing items that do not already exist when compileOnImport is not set (#798)
@@ -17,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1718
- Fixed another instance of deletes showing as owned by undefined user (#812)
1819
- Fix Revert not syncing files with IRIS (#789)
1920

21+
2022
## [2.12.2] - 2025-07-08
2123

2224
### Fixed

cls/SourceControl/Git/Utils.cls

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,14 @@ ClassMethod NewBranch(newBranchName As %String) As %Status
443443

444444
ClassMethod SwitchBranch(targetBranchName As %String) As %Status
445445
{
446-
// Make sure that branch exists first (-a lists both local and remote)
447-
do ..RunGitWithArgs(.errStream,.outStream,"branch", "-a")
446+
// First, make sure that branch exists
447+
do ..RunGitCommand("fetch", .errStream, .outStream, "--prune") // refresh list of remote branches
448+
do ..RunGitWithArgs(.errStream, .outStream, "branch", "-a") // -a lists both local and remote
448449
set branches = outStream.Read()
449-
if ('$find(branches,targetBranchName)) {
450+
if ('$FIND(branches, targetBranchName)) {
450451
quit $$$ERROR($$$GeneralError, "Selected branch does not exist"_$C(10))
451452
}
452-
k outStream, errStream
453+
kill outStream, errStream
453454
do ..RunGitWithArgs(.errStream, .outStream, "checkout", targetBranchName)
454455
do ..PrintStreams(errStream, outStream)
455456
// Checkout can fail due to unstaged changes
@@ -1567,7 +1568,7 @@ ClassMethod ImportRoutines(force As %Boolean = 0, pullEventClass As %String) As
15671568

15681569
#dim ec as %Status = ..ListItemsInFiles(.itemList, .err)
15691570
quit:'ec ec
1570-
1571+
15711572
// If there is a config file it must be imported before everything else.
15721573
if $Data(itemList(##class(SourceControl.Git.Settings.Document).#INTERNALNAME)) {
15731574
set sc = ##class(SourceControl.Git.Utils).ImportItem(##class(SourceControl.Git.Settings.Document).#INTERNALNAME, force)
@@ -1591,10 +1592,10 @@ ClassMethod ImportRoutines(force As %Boolean = 0, pullEventClass As %String) As
15911592
for {
15921593
set internalName = $order(itemList(internalName))
15931594
quit:internalName=""
1594-
1595+
15951596
// Don't import the config file a second time
15961597
continue:internalName=##class(SourceControl.Git.Settings.Document).#INTERNALNAME
1597-
1598+
15981599
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(internalName)
15991600
continue:context.Package'=refPackage
16001601
set doImport = ..IsRoutineOutdated(internalName) || force
@@ -2814,7 +2815,7 @@ ClassMethod GetSourceControlInclude(prefix As %String = {%request.URLPrefix}) As
28142815

28152816
XData ProductionConfigScript [ MimeType = text/javascript ]
28162817
{
2817-
function checkProductionConfigLoad() {
2818+
function checkProductionConfigLoad() {
28182819
timerState(false);
28192820
}
28202821

docs/menu-items.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ This option pushes the commits in the branch to the remote repository. This exhi
2929
This option forcibly pushes the commits in the branch to the remote repository. This is potentially destructive and may overwrite the commit history of the remote branch. This exhibits the same behavior as the [git push --force](https://git-scm.com/docs/git-push) command.
3030

3131
## Fetch from remote
32-
Much like the [git fetch](https://git-scm.com/docs/git-fetch) command, this option fetches the most recent versions of the branch without merging that version into the local copy of the branch.
32+
This option first [fetches](https://git-scm.com/docs/git-fetch) the most recent version of the branch without merging that version into the local copy of the branch. It will then list all files modified between the current version and the remote version.
33+
34+
This also has the effect of refreshing the list of all remote branches and pruning any references that no longer exist in the remote. (see: [git fetch --prune](https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---prune))
35+
3336
## Pull changes from remote branch
3437
Much like the [git pull](https://git-scm.com/docs/git-pull) command, this menu option pulls the most recent version of the current branch from a remote source, merging the changes into the local copy.
3538

@@ -40,7 +43,10 @@ This option will synchronize a local repo with the remote repo. The sync operati
4043
This menu option creates a new branch in the repository for changes to be committed to. It also changes the current branch to be the created branch. This mimics the behavior of the [git checkout -b](https://git-scm.com/docs/git-checkout) command.
4144

4245
## Check out an existing branch
43-
This option changes the currently checkout branch to a chosen branch. This mimics the behavior of the [git checkout](https://git-scm.com/docs/git-checkout) command.
46+
This option refreshes the local list of branches available in the upstream repository, and then changes the currently checkedout branch to the provided branch. This mimics the behavior of the [git fetch --prune](https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---prune) and [git checkout](https://git-scm.com/docs/git-checkout) commands.
47+
48+
If the desired branch does not exist in your local or in the remote, then you will receive the "Selected branch does not exist" error message.
49+
4450
## Export all
4551
This option exports class files to the local file tree at the configured location.
4652

0 commit comments

Comments
 (0)