Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT</strong>: What follows is a naive "first approach" which cannot validate as a viable solution. </p> <p>The issue is far quite more complicated and I will try to refine my approach but this is not a current priority.</p> <hr> <p>The way I am about to tackle with this issue is by soft linking the "unique" file or directory to a file or directory in a .local folder.</p> <p>The structure of this folder must be created for the first time -at the master branch before creating other branches- with the following command:</p> <pre><code>cd ./$(git rev-parse --show-cdup) &amp;&amp; mkdir -p .local/$(echo "$USER")/$(git symbolic-ref --short -q HEAD) </code></pre> <p>This command will create -in the root of the repository- the tree: </p> <pre><code>.local/&lt;username&gt;/&lt;git branch&gt;. </code></pre> <p>The "unique" files of the repository have to be moved to a relevant directory under this tree and have to be soft linked.</p> <p>For example:</p> <p>The unique file </p> <pre><code>./path/to/file/&lt;my_file&gt; </code></pre> <p>will be manually moved to:</p> <pre><code>./.local/&lt;username&gt;/&lt;git branch&gt;/path/to/file/&lt;my_file&gt; </code></pre> <p>while a symlink will be manually created in its old position linking to the new one.</p> <pre><code>"./path/to/file/&lt;my_file&gt;" -&gt; "./.local/&lt;username&gt;/&lt;git branch&gt;/path/to/file/&lt;my_file&gt;" </code></pre> <p>The symlink might also be added in the .gitignore file:</p> <pre><code>path/to/file/&lt;my_file&gt; </code></pre> <p>If other branches already exist, the .local folder from the master branch has to be checked out and the above procedure has to be repeated manually for the current branch.</p> <p>From now on two scripts called post-merge and post-checkout in: </p> <pre><code>.git/hooks/post-merge .git/hooks/post-checkout </code></pre> <p>will hopefully manage to to update the symlinks after each merge if the permissions are set to 755. </p> <p>During the first pull/merge it will create a local environment where all the "unique" files from the origin repository will be copied and symlinked.</p> <p>The user has to delete or arrange accordingly the .local subfolders and from then on the links will be automatically updated -when needed- by a script written in bash which mainly uses sed.</p> <p>I have not thoroughly tested the script due to time constraints. It seems to be working in my fedora 19 environment and I will update the post if changes have to be made. </p> <p>I a more git oriented solution would still be very welcome.</p> <p>post-merge:</p> <pre><code>#! /bin/sh # "origin": Refers to the existing merged files (soft links) information that will be overriden. # "local": Refers to the local system information that will replace origin information. #Get local user name to define the repository directory. local_user=$(echo "$USER") #Get local branch name to define the branch directory. local_branch=$(git symbolic-ref --short -q HEAD) #Go to the root of the repository cd ./$(git rev-parse --show-cdup) #Create local environment local_environment=$(echo './.local/'"$local_user"'/'"$local_branch"'/') mkdir -p $local_environment #Grub and manipulate all soft links. symlink_no=0 for link in $(find -L ./ -xtype l); do symlink_no=$[symlink_no+1] # Grub information from each symlink source_file=$(ls -la $link | sed -n 's/^.*[0-9]\+:[0-9]\+\s\(.*\)\s-&gt;.*$/\1/p') origin_target_file=$(ls -la $link | sed -n 's/.*&gt;\s\+\(.*\)$/\1/p') relative_to_root_origin_target_file=$(ls -la $link | sed -n 's/.*&gt;\s.*\(.\/.local.*\)$/\1/p') find_origin_user='s/.*local\/\([a-zA-Z0-9._-]\+\).*/\1/p' origin_user=$(echo $origin_target_file | sed -n "$find_origin_user") find_origin_branch='s/.*local\/'"$origin_user"'\/\([a-zA-Z0-9._-]\+\).*/\1/p' origin_branch=$(echo $origin_target_file | sed -n "$find_origin_branch") local_target_file=$(echo $origin_target_file | sed -n 's/local\/'"$origin_user"'\/'"$origin_branch"'/local\/'"$local_user"'\/'"$local_branch"'/p') relative_to_root_local_target_file=$(echo $relative_to_root_origin_target_file | sed -n 's/local\/'"$origin_user"'\/'"$origin_branch"'/local\/'"$local_user"'\/'"$local_branch"'/p') remove_file_from_target_path='s/\(.*\)\/.*$/\1/p' find_local_target_layout=$(echo $relative_to_root_origin_target_file | sed -n "$remove_file_from_target_path" | sed -n 's/.*'"$origin_branch"'\/\(.*$\)/\1/p') local_environment_path=$(echo "$local_environment""$find_local_target_layout") #Wording header. echo '' echo '' echo 'Checking for symlink [' "$symlink_no"' ]:' "$source_file" echo '------------------------------------------------------' echo '' # ------------------- Target File Manipulation --------------------------------- #Check if target file does not exist in local environment. if [ ! -f "$relative_to_root_local_target_file" ]; then #If true, verify that the source file exists and copy it. if [ -f "$relative_to_root_origin_target_file" ]; then mkdir -p "$local_environment_path" rsync -va "$relative_to_root_origin_target_file" "$relative_to_root_local_target_file" echo '' origin_target_file_exists=1 local_target_file_exists=1 echo 'The source file has been created: ' "$relative_to_root_local_target_file" else echo 'The source file does not exist: ' "$relative_to_root_origin_target_file" origin_target_file_exists=0 local_target_file_exists=0 fi else local_target_file_exists=1 echo 'The local file "'"$relative_to_root_local_target_file" '" already exists.' fi source_path=$(echo $source_file | sed -n "$remove_file_from_target_path") source_check_target=$(echo "$source_path"'/'"$local_target_file") #-------------------- Source File Manipulation --------------------------------- # If target file exists: if [[ $local_target_file_exists -eq 1 ]]; then #Check the source file if it is already linked. if [ "$local_target_file" == "$origin_target_file" ]; then #Is it a correct link? if [ -f $source_check_target ]; then echo 'symlink "' "$source_file" '-&gt;' "$local_target_file" '" already exists and it is correct.' else echo '*********** This is a broken link: ' "$source_file" echo ' **********************' fi else #Delete existing symlink rm "$source_file" #Create new symlink according to local environment ln -s "$local_target_file" "$source_file" echo 'symlink "' "$source_file" '-&gt;' "$local_target_file" '" has been created.' fi else echo '*********** This is a broken link: ' "$source_file" echo ' **********************' fi done </code></pre> <p>post-checkout:</p> <pre><code>#! /bin/sh # Start from the repository root. cd ./$(git rev-parse --show-cdup) # Delete .pyc files and empty directories. find . -name "*.pyc" -delete #find . -type d -empty -delete #----------------Symlink manipulation--------------------------------------- #Get local user name to define the repository directory. local_user=$(echo "$USER") #Get local branch name to define the branch directory. local_branch=$(git symbolic-ref --short -q HEAD) #Go to the root of the repository cd ./$(git rev-parse --show-cdup) #Grub and manipulate all soft links. symlink_no=0 for link in $(find -L ./ -xtype l); do symlink_no=$[symlink_no+1] # Grub information from each symlink source_file=$(ls -la $link | sed -n 's/^.*[0-9]\+:[0-9]\+\s\(.*\)\s-&gt;.*$/\1/p') origin_target_file=$(ls -la $link | sed -n 's/.*&gt;\s\+\(.*\)$/\1/p') relative_to_root_origin_target_file=$(ls -la $link | sed -n 's/.*&gt;\s.*\(.\/.local.*\)$/\1/p') find_origin_user='s/.*local\/\([a-zA-Z0-9._-]\+\).*/\1/p' origin_user=$(echo $origin_target_file | sed -n "$find_origin_user") find_origin_branch='s/.*local\/'"$origin_user"'\/\([a-zA-Z0-9._-]\+\).*/\1/p' origin_branch=$(echo $origin_target_file | sed -n "$find_origin_branch") local_target_file=$(echo $origin_target_file | sed -n 's/local\/'"$origin_user"'\/'"$origin_branch"'/local\/'"$local_user"'\/'"$local_branch"'/p') relative_to_root_local_target_file=$(echo $relative_to_root_origin_target_file | sed -n 's/local\/'"$origin_user"'\/'"$origin_branch"'/local\/'"$local_user"'\/'"$local_branch"'/p') remove_file_from_target_path='s/\(.*\)\/.*$/\1/p' find_local_target_layout=$(echo $relative_to_root_origin_target_file | sed -n "$remove_file_from_target_path" | sed -n 's/.*'"$origin_branch"'\/\(.*$\)/\1/p') local_environment_path=$(echo "$local_environment""$find_local_target_layout") source_path=$(echo $source_file | sed -n "$remove_file_from_target_path") source_check_target=$(echo "$source_path"'/'"$local_target_file") #Wording header. echo '' echo '' echo 'Checking for symlink [' "$symlink_no"' ]:' "$source_file" echo '------------------------------------------------------' echo '' # ------------------- Target File Manipulation --------------------------------- #Check if target file does not exist in local environment. if [ -f "$relative_to_root_local_target_file" ]; then #Check the source file if it is already linked. if [ "$local_target_file" == "$origin_target_file" ]; then #Is it a correct link? if [ -f $source_check_target ]; then echo 'symlink "' "$source_file" '-&gt;' "$local_target_file" '" already exists and it is correct.' else echo '*********** This is a broken link: ' "$source_file" echo ' **********************' fi else #Delete existing symlink rm "$source_file" #Create new symlink according to local environment ln -s "$local_target_file" "$source_file" echo 'symlink "' "$source_file" '-&gt;' "$local_target_file" '" has been created.' fi else echo 'The source file does not exist: ' "$relative_to_root_local_target_file" fi done </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload