1

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)

1
  • Manually calling value printed by 'echo git checkout "$branch"' works properly, so it's an issue with resolving manually passed parameter by git Commented Oct 12, 2016 at 12:17

3 Answers 3

1

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 ']}")

Sign up to request clarification or add additional context in comments.

Comments

0

You should have a look at git submodules.

1 Comment

Unfortunately it won't work with gerrit infrastructure/allowed access in my company
0

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

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

1 Comment

Well, that shortens the script, but the parameters themselves were passed properly (I've checked this, by calling 'echo git checkout "$branch"') there seems to be a problem with actual passing of said parameter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.