Open Remote URL for git repositories

This post is to demonstrate the concept of conditional buttons, the visibility of which depends on the content of the current folder.

This requirement has been discussed many times on this forum. Yet I don't see a complete working example.

The gist is that, the button "Remote Origin" shows if the current folder is managed by git, i.e., there is a sub folder named .git. The button disappears elsewhere to avoid cluttering the toobar.

dopus_jXNv3tRIF1

As suggested in some places, the visibility of the button is controlled by reading a variable isInGit; another script git-repo-detector.js runs the dirty content detection and sets the variable.

<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>Remote Origin</label>
	<icon1>/hostpictures/icons/Git-Icon-1788C.ico,0</icon1>
	<function type="batch">
		<instruction>@hideif:!$tab:isInGit</instruction>
		<instruction />
		<instruction>for /f &quot;tokens=*&quot; %%a in (&apos;git  -C {sourcepath} remote get-url origin&apos;) do set url=%%a</instruction>
		<instruction>start &quot;&quot; &quot;%url%&quot;</instruction>
	</function>
</button>

git-repo-detector.js.txt (1004 Bytes)

More git-conditioanl buttons can be created with the help of git-repo-detector.js.

Limitation

For performance concerns, git-repo-detector.js detects the existence of the .git folder up to 3 levels. It does not invoke the actual git executable.

2 Likes