I set a variable
WORKSPACE="$(git rev-parse --show-toplevel)" in
~/.bashrc - which essentially sets
$WORKSPACE to the root of the git repository
so that I can write alias for some of the operations like
building an image,
going to my component directory in the repo etc.
Now I have created a bash shell script to create a new git worktree with a specified directory name and branch name.
My script syntax would go like this -
my_script -c <branch_name> -d <directory_name>
Now the challenge is once I create a new worktree the variable
$WORKSPACE should be set to the newly created git worktree's directory name.
Currently I am doing -
cd $DIR -> which is `directory_name` WORKSPACE="$(git rev-parse --show-toplevel)"
But this is not helping, as the set value of
$WORKSPACE is for the non-interactive session where the script is running and not for the interactive bash shell (from where the script was triggered). So if I am triggering the alias to build an image, it is not triggered from the context of newly created worktree directory.
How can I address this issue?