Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git: Add a substitution variable for the current git repository #30378

Closed
Gruntfuggly opened this issue Jul 11, 2017 · 19 comments
Closed

Git: Add a substitution variable for the current git repository #30378

Gruntfuggly opened this issue Jul 11, 2017 · 19 comments
Labels
feature-request Request for new features or functionality git GIT issues *out-of-scope Posted issue is not in scope of VS Code
Milestone

Comments

@Gruntfuggly
Copy link

The equivalent of:

$(git rev-parse --show-toplevel 2>/dev/null)

would be really useful...

@vscodebot vscodebot bot added the git GIT issues label Jul 11, 2017
@joaomoreno
Copy link
Member

Where would you use it in?

@joaomoreno joaomoreno added the under-discussion Issue is under discussion for relevance, priority, approach label Jul 11, 2017
@Gruntfuggly
Copy link
Author

In the browse and include paths used by the cpp plugin - assuming it would be available...

@joaomoreno
Copy link
Member

OK, wouldn't the current workspace path be enough for you?

@Gruntfuggly
Copy link
Author

Gruntfuggly commented Jul 12, 2017

No - unfortunately our code base is large, so I have multiple workspaces within the same repo. The browse and includes paths have several entries which are outside the workspace, but within the git repo. Relative paths don't always work because some workspaces are at different levels within the repo. The repo can also be checked out in any other folder. So the one thing that is consistent between them all is the root of the repository.

@joaomoreno joaomoreno added this to the Backlog milestone Jul 12, 2017
@joaomoreno joaomoreno added feature-request Request for new features or functionality and removed under-discussion Issue is under discussion for relevance, priority, approach labels Jul 12, 2017
@joaomoreno joaomoreno removed their assignment Jul 12, 2017
@Thaina
Copy link

Thaina commented Jul 13, 2017

Also want this feature. I want to set environment variable for launch.json and tasks.json to match the current branch name

@Thaina
Copy link

Thaina commented Aug 22, 2017

@joaomoreno Isn't this already be a variable in vscode?

https://github.com/Microsoft/vscode/blob/eac49a321b84cb9828430e9dcd3f34243a3480f7/extensions/git/src/statusbar.ts#L36

Can we access it in variable substitution?

@db4
Copy link

db4 commented Oct 9, 2017

@joaomoreno, I'm second to @Thaina question. Maybe $(git-branch) can be accessed via ${command:CommandID} syntax?

@Gruntfuggly
Copy link
Author

Gruntfuggly commented Nov 10, 2017

@Thaina You can actually do this for the tasks.json file. You can add

            "options": {
                "env": {
                    "WHATEVER": "VALUE"
                }
            }

The cool thing I found out today is that you can do something like:

"GIT_BRANCH":"`echo git rev-parse --abbrev-ref HEAD`"

which will set $GIT_BRANCH to your current branch, which can be accessed using ${GIT_BRANCH} in the command...

@Thaina
Copy link

Thaina commented Nov 10, 2017

@Gruntfuggly I suspect that it only be accessed in command which will execute that. If I access environment variable directly in the code would it be the branch name or that git command text?

@Gruntfuggly
Copy link
Author

Gruntfuggly commented Nov 10, 2017

@Thaina I currently do:

           "command": ". ${WORKSPACE}/env.sh; qmake <etc.> ; make <etc.>",
            "options": {
                "env": {
                    "WORKSPACE": "`echo $(git rev-parse --show-toplevel 2>/dev/null)`"
                }
            },

Which finds the root folder of the git repo and exectutes the env.sh script in the right place, but also the qmake has access to the WORKSPACE variable and is used to pull in other files.

I've realised I put the quotes in the wrong place in my first example (fixed now).

@Thaina
Copy link

Thaina commented Feb 20, 2018

@joaomoreno Really, can we have a command that just return that $(git-branch) variable?

Shouldn't it as easy as

commands.registerCommand('git.branch', () => $(git-branch));
{
    "GIT_BRANCH" : "${command:git.branch}"
}

?

@joaomoreno
Copy link
Member

Since you can have multiple git repositories open, what would you expect in that case?

@joaomoreno joaomoreno added the info-needed Issue requires more information from poster label Sep 18, 2018
@joaomoreno joaomoreno changed the title Feature request: Add a substitution variable for the current git repository Git Add a substitution variable for the current git repository Sep 18, 2018
@joaomoreno joaomoreno changed the title Git Add a substitution variable for the current git repository Git: Add a substitution variable for the current git repository Sep 18, 2018
@Thaina
Copy link

Thaina commented Sep 18, 2018

@joaomoreno It should be the git repo of the project itself when it running or debugging

@joaomoreno
Copy link
Member

joaomoreno commented Sep 18, 2018

We can implement it as a command. But commands don't have any context... So it would not know which repository you'd mean.

@Thaina
Copy link

Thaina commented Sep 18, 2018

@joaomoreno
Copy link
Member

That is an icon.

@vscodebot
Copy link

vscodebot bot commented Sep 26, 2018

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@vscodebot vscodebot bot closed this as completed Sep 26, 2018
@joaomoreno joaomoreno removed the info-needed Issue requires more information from poster label Sep 27, 2018
@joaomoreno joaomoreno reopened this Sep 27, 2018
@Thaina
Copy link

Thaina commented Jul 18, 2019

Still not possible?

@joaomoreno joaomoreno added the *out-of-scope Posted issue is not in scope of VS Code label Oct 9, 2019
@vscodebot
Copy link

vscodebot bot commented Oct 9, 2019

This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. More details here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding and happy coding!

@vscodebot vscodebot bot closed this as completed Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality git GIT issues *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

4 participants