@@ -324,63 +324,58 @@ public void GitConfiguration_Set_All_ThrowsException()
324324 public void GitConfiguration_Unset_Global_UnsetsGlobalConfig ( )
325325 {
326326 string repoPath = CreateRepository ( out string workDirPath ) ;
327- try
328- {
329- ExecGit ( repoPath , workDirPath , "config --global core.foobar alice" ) . AssertSuccess ( ) ;
330- ExecGit ( repoPath , workDirPath , "config --local core.foobar bob" ) . AssertSuccess ( ) ;
331327
332- string gitPath = GetGitPath ( ) ;
333- var trace = new NullTrace ( ) ;
334- var trace2 = new NullTrace2 ( ) ;
335- var processManager = new TestProcessManager ( ) ;
336- var git = new GitProcess ( trace , trace2 , processManager , gitPath , repoPath ) ;
337- IGitConfiguration config = git . GetConfiguration ( ) ;
328+ // Use an isolated global config file so tests work even when HOME is not set
329+ // to a valid directory (e.g., in package build environments like AUR).
330+ using var _ = new GitTestUtilities . EnvVarScope (
331+ "GIT_CONFIG_GLOBAL" , Path . Combine ( workDirPath , ".gitconfig-global" ) ) ;
338332
339- config . Unset ( GitConfigurationLevel . Global , "core.foobar" ) ;
333+ ExecGit ( repoPath , workDirPath , "config --global core.foobar alice" ) . AssertSuccess ( ) ;
334+ ExecGit ( repoPath , workDirPath , "config --local core.foobar bob" ) . AssertSuccess ( ) ;
340335
341- GitResult globalResult = ExecGit ( repoPath , workDirPath , "config --global core.foobar" ) ;
342- GitResult localResult = ExecGit ( repoPath , workDirPath , "config --local core.foobar" ) ;
336+ string gitPath = GetGitPath ( ) ;
337+ var trace = new NullTrace ( ) ;
338+ var trace2 = new NullTrace2 ( ) ;
339+ var processManager = new TestProcessManager ( ) ;
340+ var git = new GitProcess ( trace , trace2 , processManager , gitPath , repoPath ) ;
341+ IGitConfiguration config = git . GetConfiguration ( ) ;
343342
344- Assert . Equal ( string . Empty , globalResult . StandardOutput . Trim ( ) ) ;
345- Assert . Equal ( "bob" , localResult . StandardOutput . Trim ( ) ) ;
346- }
347- finally
348- {
349- // Cleanup global config changes
350- ExecGit ( repoPath , workDirPath , "config --global --unset core.foobar" ) ;
351- }
343+ config . Unset ( GitConfigurationLevel . Global , "core.foobar" ) ;
344+
345+ GitResult globalResult = ExecGit ( repoPath , workDirPath , "config --global core.foobar" ) ;
346+ GitResult localResult = ExecGit ( repoPath , workDirPath , "config --local core.foobar" ) ;
347+
348+ Assert . Equal ( string . Empty , globalResult . StandardOutput . Trim ( ) ) ;
349+ Assert . Equal ( "bob" , localResult . StandardOutput . Trim ( ) ) ;
352350 }
353351
354352 [ Fact ]
355353 public void GitConfiguration_Unset_Local_UnsetsLocalConfig ( )
356354 {
357355 string repoPath = CreateRepository ( out string workDirPath ) ;
358356
359- try
360- {
361- ExecGit ( repoPath , workDirPath , "config --global core.foobar alice" ) . AssertSuccess ( ) ;
362- ExecGit ( repoPath , workDirPath , "config --local core.foobar bob" ) . AssertSuccess ( ) ;
357+ // Use an isolated global config file so tests work even when HOME is not set
358+ // to a valid directory (e.g., in package build environments like AUR).
359+ using var _ = new GitTestUtilities . EnvVarScope (
360+ "GIT_CONFIG_GLOBAL" , Path . Combine ( workDirPath , ".gitconfig-global" ) ) ;
361+
362+ ExecGit ( repoPath , workDirPath , "config --global core.foobar alice" ) . AssertSuccess ( ) ;
363+ ExecGit ( repoPath , workDirPath , "config --local core.foobar bob" ) . AssertSuccess ( ) ;
363364
364- string gitPath = GetGitPath ( ) ;
365- var trace = new NullTrace ( ) ;
366- var trace2 = new NullTrace2 ( ) ;
367- var processManager = new TestProcessManager ( ) ;
368- var git = new GitProcess ( trace , trace2 , processManager , gitPath , repoPath ) ;
369- IGitConfiguration config = git . GetConfiguration ( ) ;
365+ string gitPath = GetGitPath ( ) ;
366+ var trace = new NullTrace ( ) ;
367+ var trace2 = new NullTrace2 ( ) ;
368+ var processManager = new TestProcessManager ( ) ;
369+ var git = new GitProcess ( trace , trace2 , processManager , gitPath , repoPath ) ;
370+ IGitConfiguration config = git . GetConfiguration ( ) ;
370371
371- config . Unset ( GitConfigurationLevel . Local , "core.foobar" ) ;
372+ config . Unset ( GitConfigurationLevel . Local , "core.foobar" ) ;
372373
373- GitResult globalResult = ExecGit ( repoPath , workDirPath , "config --global core.foobar" ) ;
374- GitResult localResult = ExecGit ( repoPath , workDirPath , "config --local core.foobar" ) ;
374+ GitResult globalResult = ExecGit ( repoPath , workDirPath , "config --global core.foobar" ) ;
375+ GitResult localResult = ExecGit ( repoPath , workDirPath , "config --local core.foobar" ) ;
375376
376- Assert . Equal ( "alice" , globalResult . StandardOutput . Trim ( ) ) ;
377- Assert . Equal ( string . Empty , localResult . StandardOutput . Trim ( ) ) ;
378- }
379- finally
380- {
381- // Cleanup global config changes
382- ExecGit ( repoPath , workDirPath , "config --global --unset core.foobar" ) ;
383- }
377+ Assert . Equal ( "alice" , globalResult . StandardOutput . Trim ( ) ) ;
378+ Assert . Equal ( string . Empty , localResult . StandardOutput . Trim ( ) ) ;
384379 }
385380
386381 [ Fact ]
0 commit comments