Commits

Jens Alfke committed 1779f7c

Use --login arg to bash when getting the hg command path, to make sure it runs its profile script (fixes #10)

Comments (0)

Files changed (1)

 
 
 static NSString* runShell( NSString* command, NSError **outError) {
-    MYTask *sh = [[MYTask alloc] initWithCommand: [sEnvironment objectForKey: @"SHELL"]
+    NSString *shellPath = [sEnvironment objectForKey: @"SHELL"];
+    if (!shellPath) {
+        Warn(@"No value for $SHELL!");
+        return nil;
+    }
+    MYTask *sh = [[MYTask alloc] initWithCommand: shellPath
                                        arguments: [NSArray arrayWithObjects: @"-c", command ,nil]];
+    if ($equal(shellPath,@"/bin/bash"))
+        [sh prependArguments: @"--login",nil];  // To get @*%&$ bash to read its .profile script
+    
     if ([sh run: outError])
         return [sh.output stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
     else {
     }
         
     // Ask the shell where 'hg' is. (Note that we can't check the PATH env var directly,
-    // because it's not set up by the app's parent, launchd. Only shells define it.)
+    // because it's not set up by the app's parent, launchd. Only shells define it, and user
+    // setup scripts like .cshrc and .bash_profile customize it.)
     NSError *error = nil;
     hgPath = runShell(@"which hg", &error);
     if (hgPath) {
 }
 
 
-+ (void) initialize
-{
-    if( self == [HgOperation class] ) {
-        [self setupEnvironment];
-        sHgToolPath = [self findHgTool];
-    }
-}
-
-
 static NSString* getAbsolutePath( id dir )
 {
     if( [dir isKindOfClass: [NSString class]] )
                arguments: (NSArray*)arguments
 {
     Assert(subcommand);
+    if (!sHgToolPath) {
+        // First-time initialization:
+        [HgOperation setupEnvironment];
+        sHgToolPath = [HgOperation findHgTool];
+    }
+    
     self = [super initWithCommand: sHgToolPath arguments: arguments];
     if (self != nil) {
         _subcommand = subcommand;