18

SourceTree has a window called unstaged files where it shows files whose changes have not been committed. I want to right click on the file name & open it in an external editor. So I added a custom action -> Edit -> pathtoeditor\editor.exe $REPO\$FILE.

This launches the editor. But SourceTree also keeps showing a progress bar. progress bar The progress bar closes only after I close the external editor.

How do I avoid this? After opening the file in the external editor, I want SourceTree's UI to return to its normal state without waiting for the editor to exit.

7
  • It looks like the editor is still running. What happens when you close the editor application (not just the window that displays the file open by SourceTree)?
    – axiac
    Commented Jul 25, 2017 at 6:13
  • @axiac - yes, the editor is still running. When I close the editor the progress bar goes away. However, I want Sourcetree to just launch the external editor and not wait for it to close.
    – user93353
    Commented Jul 25, 2017 at 6:29
  • find an editor that return right-away. I guess Notepad++ behave like that. Another choice is to write a little batch/script to run the editor in background Commented Jul 25, 2017 at 8:20
  • @AdrianShum - the editor returns right away - that's not the issue - SourceTree waits for the child (and all grandchild processes) to exit.
    – user93353
    Commented Jul 25, 2017 at 8:44
  • @user93353 It may be related: For example, my experience of 7zip on windows, if I set editor to notepad, when I edit file in place in 7zip, 7zip will wait until I close the editor and detect change in file. However it does not work for Notepad++, 7zip thinks I have closed editor right after file is opened. I believe Notepad++ command is just "telling" the running editor process to open a file. So SourceTree may not need to wait. That's just my guess though, as I don't have environment to test that out. By the way, you should at least mention which platform you are using. Commented Jul 25, 2017 at 8:50

3 Answers 3

12

This is an old question, but if someone else is looking for the answer currently the easiest way to accomplish this is to follow these steps

  1. Within SourceTree go to Tools -> Options
  2. Click Custom Actions
  3. Click Add
  4. Add the Caption
  5. For script to run, hit the three dot button and locate the .exe of the application you are wanting to open the file in
  6. Add the needed parameters to the parameters text box (in my case this is $FILE
  7. Click OK
  8. Restart SourceTree

New custom action window

Now if you right click on a file in Sourcetree and go to the custom actions menu it will now have the action you created. Click on it and it will open in the application you selected without keeping the progress bar open for no reason.

3
  • This use to work for me but now I get the same issue as the original poster of the SourceTree window staying open until the editor (VSCode) closes...
    – GazB
    Commented Aug 25, 2021 at 8:56
  • @GazB, strange, I still use this, though with VS Code rather than Notepad++. I'm on version 3.3.8, which I know isn't the latest version. I wonder if something may have changed in the latest updates.
    – dmoore1181
    Commented Aug 25, 2021 at 16:14
  • Use "$FILE" because a file path can contain spaces
    – Vadim
    Commented Feb 2, 2023 at 12:49
1
+25

Make a .bat file, say..."launchNotepad.bat" like so

@call pathtoEditor\editor %1

Make the batch file your script target, and your parameters stay as $REPO\$FILE. This'll make launching the editor your action, rather than the editor itself.

This has a few other advantages, like SourceTree picking up on updates to the batch file without having to restart it.

6
  • Already tried it. Doesn't work. Source tree blocks even then.
    – user93353
    Commented Aug 4, 2017 at 4:40
  • Huh. Worked for me. I did test it. (Using notepad++)
    – zzxyz
    Commented Aug 4, 2017 at 6:14
  • I just now again tested with notepad++. Doesn't work.
    – user93353
    Commented Aug 4, 2017 at 6:46
  • Weird, wonder what the difference between our environments is. Command extensions making call behave differently or something? (For the record, I was able to reproduce your issue, too.)
    – zzxyz
    Commented Aug 4, 2017 at 18:23
  • What did you have to change to reproduce my issue?
    – user93353
    Commented Aug 4, 2017 at 18:59
0

The issue is that SourceTree is waiting for the launched process to finish (which could be useful - for example when launching a merge tool, or some other task that requires action from SourceTree when it completes).

To launch a truly independent instance of your editor, use

cmd

as the "Script to run" and

/C start "" path_to_editor <parameters> "$REPO/$FILE"

as the parameter.

The /C option on cmd causes the command window to close as soon as it executes the start command, and the empty first parameter to the "start" is a dummy value for the command window that will never open. If path_to_editor contains spaces, then you have to enclose it in quotations.

1
  • I tried this and got the same issue, SourceTree blocks. I put cmd in the first field and put /c start "" notepad in the second field. It opens the notepad editor, but SourceTree remains blocked.
    – Diogo
    Commented Mar 14, 2023 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.