Page 1 of 2

Display current checked out git branch name

Posted: 16 May 2019 03:51
by jlahijani
Many developers customize their command line (bash, etc.) to show what git branch name they have checked out when they are in a folder that's under a git repository. Example:
https://coderwall.com/p/fasnya/add-git- ... ash-prompt

See the yellow "(develop)" part on the first line? That's the name of the branch and it's there as a label at the very end of the command prompt (ignore the other parts of this image):
Image

Is there a way to do the equivalent of this in XYplorer? When I go to a folder that's under a git repo, I'd like to know the branch name I have currently checked out (ideally somewhere at the top and distractingly visible). This is very important because depending on which git branch you have checked out, some files/folders may appear and some won't, which can be confusing if you forget about the fact that branches are in play and may affect what you're seeing.

Re: Display current checked out git branch name

Posted: 16 May 2019 14:05
by Leito
Never thought about this, but now that you suggested it, I think that's a really neat idea! :tup:

I think the branch name should be displayed in the tab name.

EDIT: should this be moved to Wishes? I don't think this is something we can properly do with scripting.

Re: Display current checked out git branch name

Posted: 16 May 2019 15:18
by highend
I don't think this is something we can properly do with scripting.
Sure it can be done with scripting but it needs to be invoked manually...

Code: Select all

    $branch  = regexreplace(runret("git branch"), "\r?\n");
    $tabName = tab("get", "name");
    if (!$tabName) { $tabName = tab("get", "caption"); }
    $tabName = regexreplace($tabName, " \[\* .+?\]$");
    if (strpos($branch, "*") != -1) {
        $branch = regexreplace($branch, "^(?:\* )(.+?)(?=\r?\n|$)", "$1");
        tab("rename", "$tabName [* $branch]");
    } else {
        tab("rename", $tabName);
    }
1.png
1.png (1.56 KiB) Viewed 306 times
2.png
2.png (1.87 KiB) Viewed 306 times

Re: Display current checked out git branch name

Posted: 16 May 2019 15:25
by admin
Can anybody explain this to a non-GITter? I have no idea what this is about. But if it's a simple thing I'm happy to add it...

Re: Display current checked out git branch name

Posted: 16 May 2019 15:26
by Leito
highend wrote:
16 May 2019 15:18
it needs to be invoked manually...
My point exactly. For this to be actually enjoyable/beneficial, I don't see myself calling this script X times a day.

Plus once your tab is renamed, it stayed renamed, even if you browse to a different folder.

Re: Display current checked out git branch name

Posted: 16 May 2019 15:27
by highend
On each folder change invoke "git branch" and if there is an entry that begins with "*",
that's the name of the current branch. Add it to the tabs name like in the script
I've posted above...

Re: Display current checked out git branch name

Posted: 16 May 2019 15:27
by highend
Plus once your tab is renamed, it stayed renamed, even if you browse to a different folder.
Ofc it does, I already said that it needs to be invoked manually...

Re: Display current checked out git branch name

Posted: 16 May 2019 15:34
by Leito
admin wrote:
16 May 2019 15:25
Can anybody explain this to a non-GITter? I have no idea what this is about.
https://www.atlassian.com/git/tutorials/using-branches

EDIT: this one is interesting as well without going into too much details: https://backlog.com/git-tutorial/using-branches/

Re: Display current checked out git branch name

Posted: 16 May 2019 15:52
by admin
Thanks, but no time to read this ATM. So, let's put is this way: But is the wish here?

Re: Display current checked out git branch name

Posted: 16 May 2019 16:08
by Leito
Basically, we use a git repository (a folder on our file system) that holds several branches. A branch represents a version of the files (and subfolders) in the repository. At a moment in time, we're always checked out to one branch (and only one). When we switch branches, it modifies the content of the folder (corresponding to the git repository). The wish here is to know to which branch (identified by its name: the default branches are usually named master, develop; or any other name you wish) we are currently checked out.

My proposal is to append it to the tab name.

Ideally, XYplorer should detect if the tab is listing the content of a git repository, and if so, get the branch name and display it automatically.

Re: Display current checked out git branch name

Posted: 16 May 2019 16:21
by admin
Far out. A bit exotic maybe for a general purpose file manager?

Re: Display current checked out git branch name

Posted: 16 May 2019 16:33
by Leito
Maybe.

But you could add support to other VCS (SVN, Mercurial...) as well (Git is the most common, so first to do), and it would be a nice feature for developers.

Re: Display current checked out git branch name

Posted: 19 May 2019 12:43
by SammaySarkar
Don, git is HUGE. Adding support for git status and metadata will be very attractive to a lot of potential customers!

the git executable's output structure is easily parseable by code; maybe you can just call git on location change to get necessary branch and repo status info. Git surely has some more accessible library too.

Re: Display current checked out git branch name

Posted: 19 May 2019 13:09
by admin
Thanks for the tip. Up to now I did not hear much from the GIT community. If that changes I will be happy to add this stuff. Looks easy enough...

Re: Display current checked out git branch name

Posted: 19 May 2019 20:07
by xyuser123
I've never been a fan of adding integration with specific third party products. I think a more general solution would be an option to run a script on directory change, so that users who want this feature can use a script like the one highend posted.