Potential bug report // Need help to understand "get_current_branch" in "bench/bench/utils/app.py"

Hello everyone.

I am sort of new to erpnext and starting to get into it. Therefore my question could somehow be inappropriate since it could have significant impact. To better understand some apps and inspecting its code implications I forked some apps and branched my work. My branch names are “structured” for organizational purpose, e.g. “myname/testA” or “myname/testB”.

When running “bench update” I discovered some odd behavior and update failures caused by the “get_current_branch” method (see below) in “bench/bench/utils/app.py”

def get_current_branch(app, bench_path="."):
	from bench.utils import get_cmd_output

	repo_dir = get_repo_dir(app, bench_path=bench_path)
	return get_cmd_output("basename $(git symbolic-ref -q HEAD)", cwd=repo_dir)

The problem occurs due to the - in my opinion - improper combination of the “git symbolic-ref -q HEAD” command with the Linux “basename” command. Roughly spoken this combination only returns the last string of a path. However, this does not have to be the branch name!!!

Lets give an example. A valid git branch name “myname/testA” reference head should look like this: “refs/heads/myname/testA”. Applying above method “get_current_branch” returns only “testA” but should return “myname/testA”. Thereby the “bench update” routine fails since “git pull” is performed upon the wrong branch.

Possible solution:
A solution would be to use native git command without the “basename” command.

git symbolic-ref -q --short HEAD

Maybe I have missed something. Any feedback is highly welcome.


FYI, i created a ticket: