@@ -447,8 +447,7 @@ ClassMethod MergeDefaultRemoteBranch(Output alert As %String = "") As %Boolean
447447 do ..RunGitWithArgs (.errStream , .outStream , " fetch" , " origin" , defaultMergeBranch _" :" _defaultMergeBranch )
448448 do ..PrintStreams (errStream , outStream )
449449
450- do ..RunGitWithArgs (,.outStream , " rev-parse" , " HEAD" )
451- set startSha = outStream .ReadLine ()
450+ set startSha = ..GetCurrentRevision ()
452451
453452 // Start a transaction so code changes can be rolled back
454453 set initTLevel = $TLevel
@@ -556,6 +555,13 @@ ClassMethod GetCurrentBranch() As %String
556555 quit branchName
557556}
558557
558+ ClassMethod GetCurrentRevision () As %String
559+ {
560+ do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" rev-parse" ,,.errStream ,.outStream ," HEAD" )
561+ set revision = outStream .ReadLine (outStream .Size )
562+ quit revision
563+ }
564+
559565ClassMethod Pull (remote As %String = " origin" ) As %Status
560566{
561567 New %gitSCOutputFlag
@@ -1731,7 +1737,11 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
17311737 } elseif (command = " restore" ) {
17321738 // Leave diffCompare empty, this actually does the right thing.
17331739 set syncIrisWithDiff = 1
1734- } elseif (command = " merge" ) || (command = " rebase" ) || (command = " pull" ) {
1740+ } elseif (command = " pull" ) {
1741+ set syncIrisWithDiff = 1
1742+ // The current revision, prior to the pull, will be compared against
1743+ set diffCompare = ..GetCurrentRevision ()
1744+ } elseif (command = " merge" ) || (command = " rebase" ) {
17351745 set syncIrisWithCommand = 1
17361746 if $data (args ) && $data (args (args ),diffCompare ) {
17371747 // no-op
@@ -1795,7 +1805,10 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
17951805 set syncIrisWithCommand = 0
17961806 }
17971807
1798- if syncIrisWithDiff {
1808+ // If performing a pull don't perform a diff until after the pull has occured.
1809+ // This is to avoid a double fetch, as pull performs one for us and also to avoid a potential
1810+ // race condition if the remote changes between now and the pull actually being performed.
1811+ if syncIrisWithDiff && (command '= " pull" ) {
17991812 if diffBase = " " {
18001813 set diffBase = ..GetCurrentBranch ()
18011814 }
@@ -1809,23 +1822,30 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
18091822 set outLog = ##class (%Library.File ).TempFilename ()
18101823 set errLog = ##class (%Library.File ).TempFilename ()
18111824
1812- set command = $extract (..GitBinPath (),2 ,*-1 )
1825+ set gitCommand = $extract (..GitBinPath (),2 ,*-1 )
18131826
18141827 set baseArgs = " /STDOUT=" _$$$QUOTE(outLog )_" /STDERR=" _$$$QUOTE(errLog )_$case (inFile , " " :" " , :" /STDIN=" _$$$QUOTE(inFile ))
18151828 try {
18161829 // Inject instance manager directory as global git config home directory
18171830 // On Linux, this avoids trying to use /root/.config/git/attributes for global git config
18181831 set env (" XDG_CONFIG_HOME" ) = ##class (%File ).ManagerDirectory ()
1819- set returnCode = $zf (-100 ," /ENV=env... " _baseArgs ,command ,newArgs ...)
1832+ set returnCode = $zf (-100 ," /ENV=env... " _baseArgs ,gitCommand ,newArgs ...)
18201833 } catch e {
18211834 if $$$isWINDOWS {
1822- set returnCode = $zf (-100 ,baseArgs ,command ,newArgs ...)
1835+ set returnCode = $zf (-100 ,baseArgs ,gitCommand ,newArgs ...)
18231836 } else {
18241837 // If can't inject XDG_CONFIG_HOME (older IRIS version), need /SHELL on Linux to avoid permissions errors trying to use root's config
1825- set returnCode = $zf (-100 ," /SHELL " _baseArgs ,command ,newArgs ...)
1838+ set returnCode = $zf (-100 ," /SHELL " _baseArgs ,gitCommand ,newArgs ...)
18261839 }
18271840 }
18281841
1842+ // If performing a pull then do a diff now after the pull has occured.
1843+ if syncIrisWithDiff && (command = " pull" ) {
1844+ do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" diff" ,,.errorStream ,.outputStream , diffCompare , " --name-status" )
1845+ // Verbose output should not be required as pull already outputs a summary
1846+ do ..ParseDiffStream (outputStream ,0 ,.files )
1847+ }
1848+
18291849 set errStream = ##class (%Stream.FileCharacter ).%OpenId (errLog ,,.sc )
18301850 set outStream = ##class (%Stream.FileCharacter ).%OpenId (outLog ,,.sc )
18311851 set outStream .TranslateTable =" UTF8"
0 commit comments