Skip to content

Commit 26eed61

Browse files
authored
Merge pull request #788 from raymond-rebbeck/remote-checkout
Sync IRIS with repo changes when switching to a remote branch
2 parents d39c4b9 + 5c9d73c commit 26eed61

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- Changing remotes in the git project settings pages now works if remote is not already defined (#746)
2222
- User-specific basic mode setting can now be changed when settingsUIReadOnly is set (#775)
2323
- Fixed an error displaying the Web UI after reverting a commit (#776)
24+
- Fixed checkout of a remote branch not syncing files with IRIS (#783)
2425
- Fixed errors exporting items when directory casing does not match mappings (#781)
2526
- Improved accessibility of UI when tabbing through items (#764)
2627

cls/SourceControl/Git/Utils.cls

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,8 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
18601860
set newArgs($increment(newArgs)) = command
18611861

18621862
set syncIrisWithDiff = 0 // whether IRIS needs to be synced with repo file changes using diff output
1863+
set syncIrisWithDiffAfterGit = 0 // whether to sync using diff output after the git command is performed
1864+
set syncIrisWithDiffVerbose = 1 // whether to use verbose output when syncing using diff output
18631865
set syncIrisWithCommand = 0 // // whether IRIS needs to be synced with repo file changes using command output
18641866
set diffBase = ""
18651867
set diffCompare = ""
@@ -1888,16 +1890,26 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
18881890

18891891
if (command = "checkout") {
18901892
set syncIrisWithDiff = 1
1893+
// Sync using diff output after the checkout has been performed
1894+
// Allows syncing remote branches as the diff will otherwise fail prior
1895+
set syncIrisWithDiffAfterGit = 1
18911896
if hasFileList {
18921897
set invert = 1
18931898
} elseif $data(args) && $data(args(args),diffCompare) {
1894-
// no-op
1899+
// Record the current branch to diff against after the checkout
1900+
set diffBase = ..GetCurrentBranch()
18951901
}
18961902
} elseif (command = "restore") {
18971903
// Leave diffCompare empty, this actually does the right thing.
18981904
set syncIrisWithDiff = 1
18991905
} elseif (command = "pull") {
19001906
set syncIrisWithDiff = 1
1907+
// If performing a pull don't perform a diff until after the pull has occured.
1908+
// This is to avoid a double fetch, as pull performs one for us and also to avoid a potential
1909+
// race condition if the remote changes between now and the pull actually being performed.
1910+
set syncIrisWithDiffAfterGit = 1
1911+
// Verbose output should not be required as pull already outputs a summary
1912+
set syncIrisWithDiffVerbose = 0
19011913
// The current revision, prior to the pull, will be compared against
19021914
set diffCompare = ..GetCurrentRevision()
19031915
} elseif (command = "merge") || (command = "rebase") {
@@ -1927,12 +1939,18 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
19271939
set newArgs($increment(newArgs)) = args(i)
19281940
if (args(i) = "checkout") {
19291941
set syncIrisWithDiff = 1
1942+
// Sync using diff output after the checkout has been performed
1943+
// Allows syncing remote branches as the diff will otherwise fail prior
1944+
set syncIrisWithDiffAfterGit = 1
19301945
if hasFileList {
19311946
set invert = 1
19321947
} else {
19331948
set diffCompare = args(i + 1)
19341949
if args = (i + 2) {
19351950
set diffBase = args(i + 2)
1951+
} else {
1952+
// Record the current branch to diff against after the checkout
1953+
set diffBase = ..GetCurrentBranch()
19361954
}
19371955
}
19381956
} elseif (args(i) = "restore") {
@@ -1964,18 +1982,16 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
19641982
set syncIrisWithCommand = 0
19651983
}
19661984

1967-
// If performing a pull don't perform a diff until after the pull has occured.
1968-
// This is to avoid a double fetch, as pull performs one for us and also to avoid a potential
1969-
// race condition if the remote changes between now and the pull actually being performed.
1970-
if syncIrisWithDiff && (command '= "pull") {
1985+
// If syncing with diff output before the git command
1986+
if syncIrisWithDiff && 'syncIrisWithDiffAfterGit {
19711987
if diffBase = "" {
19721988
set diffBase = ..GetCurrentBranch()
19731989
}
19741990

19751991
do ..RunGitCommand("fetch", .errorStream, .outputStream,"--prune")
19761992
kill errorStream, outputStream
19771993
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errorStream,.outputStream, diffBase_$Case(diffCompare,"":"",:"..")_diffCompare, "--name-status")
1978-
do ..ParseDiffStream(outputStream,,.files)
1994+
do ..ParseDiffStream(outputStream,syncIrisWithDiffVerbose,.files)
19791995
}
19801996

19811997
set outLog = ##class(%Library.File).TempFilename()
@@ -1998,11 +2014,10 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
19982014
}
19992015
}
20002016

2001-
// If performing a pull then do a diff now after the pull has occured.
2002-
if syncIrisWithDiff && (command = "pull") {
2003-
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errorStream,.outputStream, diffCompare, "--name-status")
2004-
// Verbose output should not be required as pull already outputs a summary
2005-
do ..ParseDiffStream(outputStream,0,.files)
2017+
// If syncing with diff output after the git command
2018+
if syncIrisWithDiff && syncIrisWithDiffAfterGit {
2019+
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errorStream,.outputStream, diffBase_$Case(diffCompare,"":"",:"..")_diffCompare, "--name-status")
2020+
do ..ParseDiffStream(outputStream,syncIrisWithDiffVerbose,.files)
20062021
}
20072022

20082023
set errStream = ##class(%Stream.FileCharacter).%OpenId(errLog,,.sc)

0 commit comments

Comments
 (0)