How to parametrize git checkout using bash script

I have directory with project sharing multiple versions and I've tried creating simple script that would checkout proper versions for every module with configuration is seperate files (2.6 is one of those).

Config files look like:

<module_name1> <branch_name1>
<module_name2> <branch_name2>

Script:

Edited

while read path branch;
do
  cd $path
  echo
  echo $path
  echo "$branch"
  git checkout "$branch"
  cd ..
done < 2.6

Unfortunately git does not seem to recognize branch names passed this way resulting in error:

' did not match any file(s) known to git.

I'd like an advice how can I fix such script, or create it in another way?

(or maybe some tool for configurable mass checkouting?...)

EDIT:

After some testing, it seems that git considers value passed by '$branch' as an empty string (I've checked it's content earlier with echo)

Upvotes: 1

Views: 1461

Answers (3)

Apparently reading variables this way from separate file, corrupts them by adding carriege return, thus it started working after trimming.

(It was that much more nastier, that it had corrupted echo output and I've found it only after streaming its result to another file instead of console)

FIX: branch=$(echo "${branch//[$'\t\r\n ']}")

Upvotes: 1

G. Sliepen
G. Sliepen

Reputation: 7973

Use read's ability to split the input line into multiple variables:

while read path branch; do
  cd "$path"
  git checkout "$branch"
  ...

Upvotes: 0

Gernot
Gernot

Reputation: 384

You should have a look at git submodules.

Upvotes: 0

Related Questions