Fossil Forum

How to get the branch name
Login

How to get the branch name

How to get the "parent" branch name

(1.1) By Francois Vogel (fvogel) on 2022-02-27 08:48:39 edited from 1.0 [link] [source]

Given a branch named br_A, I would like to get the name of the branch from which br_A originates, i.e. the branch from which br_A was branched.

I believe this could be achieved by looking for the first (the oldest) commit in branch br_A, then obtain the parent commit of this commit, and output the branch name of this parent commit.

Not so straightforward as a principle, and even less when talking to actual implementation through fossil commands.

How would you do this?

Thanks for your help, and thanks for fossil!

(2) By Florian Balmer (florian.balmer) on 2022-02-27 09:14:08 in reply to 1.1 [link] [source]

On Windows:

fossil tag ls root:current | findstr /BIC:"branch="

References:

(3) By Florian Balmer (florian.balmer) on 2022-02-27 09:18:09 in reply to 2 [link] [source]

I meant:

fossil tag ls root:current | findstr /BLC:"branch="

(Either version works, but this is the correct one.)

(4) By Francois Vogel (fvogel) on 2022-02-27 09:50:01 in reply to 3 [link] [source]

Thank you very much!

The root:current trick definitely is what I was missing.

When running the provided command however I get no output.

But when running simply fossil tag ls root:current I get exactly what I want.

My fossil version is 2.13, I believe this is the cause for the need of the pipe to findstr with the latest fossil (2.18). I will dig into this further.

Thanks again!

(5) By Florian Balmer (florian.balmer) on 2022-02-27 10:05:15 in reply to 4 [link] [source]

The pipe just removes other (non-branch-name) tags. Maybe that the branch= prefix was added to the output after Fossil 2.13?

With Fossil 2.18, I see:

branch=BRANCHNAME

And to get just the branch name, I'd have to do:

for /F "usebackq tokens=1,* delims==" %A in (`fossil tag ls root:current ^| findstr /BLC:"branch="`) do echo.%B

(6) By Francois Vogel (fvogel) on 2022-02-27 22:06:49 in reply to 5 [link] [source]

Yes, that's it. fossil-2.18 apparently added more output to the fossil tag ls command.

Thanks a lot again, you rock!

(7.1) By Daniel Dumitriu (danield) on 2022-03-01 23:25:10 edited from 7.0 in reply to 1.1 [link] [source]

With Unix utilities:

fossil info root:br_A | awk '/^hash:/{print $2}'

or

fossil info root:br_A| grep '^hash:' | cut -d' ' -f10

Edit: replaced' parent' with 'hash'.

(8) By Stephan Beal (stephan) on 2022-03-01 23:28:12 in reply to 7.0 [source]

With Unix utilities:

With the caveat/disclaimer that we have never guaranteed any specific output format or output stability, so formulations of such scripts should avoid things like hard-coding character offsets. Somewhat ironically, the less specific they are, the more likely they are to survive minor output formatting changes. (For example, Daniel's first example is less specific than the second.)

We generally try to avoid breaking client-side scripts via changes in output but we have never guaranteed it and don't "bend over backwards" to avoid it.

(9) By Daniel Dumitriu (danield) on 2022-03-02 10:08:51 in reply to 8 [link] [source]

Fair enough. I was thinking "one-time find", not scripting.

Anyway, my one-liner (more portable as fossil info root:BRANCH | grep "^hash:" | grep -o "[0-9a-f]\{40,\}") was not the answer, since it returns the hash of the last commit before branching.

The stable-enough, Unixy correct answer is based on Florian's suggestion:

fossil tag ls root:BRANCH | grep "^branch=" | cut -d= -f2