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

Potential bug report // Need help to understand “get_current_branch” in “bench/bench/utils/app.py” #1551

Closed
fixundfertig123 opened this issue Apr 7, 2024 · 1 comment

Comments

@fixundfertig123
Copy link
Contributor

Hello everyone.

I am sort of new to Frappe / bench and starting to get into it. Therefore my question could somehow be inappropriate since it could have significant impact. To better understand some erpnext 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)

(https://github.com/frappe/bench/blob/d728b808832c081aca6bb6771e6206974cb75c60/bench/utils/app.py#L171C1-L175C77)

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.

Cheers

@fixundfertig123
Copy link
Contributor Author

Can anyone confirm my observation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants