User Tools

Site Tools


howto:git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howto:git [2021/12/26 10:59] va7fihowto:git [2021/12/26 12:26] (current) – [Test Scenarios] va7fi
Line 1: Line 1:
 ====== Git ====== ====== Git ======
 ===== Test Scenarios ===== ===== Test Scenarios =====
 +Summary:
 +  * When cloning from remote to local or pushing from local to remote, ''www-data'' group ownership and ''770'' permissions are not preserved.
 +  * When pushing local changes to remote, the remote master can't be checkout out.
 +
 +References:
 +  * [[https://stackoverflow.com/questions/3207728/retaining-file-permissions-with-git |stackoverflow]] question about permissions.
 +  * Using [[https://githooks.com/ |git hooks]] to run pre- and post- scripts to fix permissions.
 +  
 ==== Initial Cloning ==== ==== Initial Cloning ====
-Summary: ownership is not preserved. 
- 
   * Create two files in a ''remote'' folder to simulate the wiki install on the server.   * Create two files in a ''remote'' folder to simulate the wiki install on the server.
  
   * Change their permissions and ownership to match what's on the server:<code bash>   * Change their permissions and ownership to match what's on the server:<code bash>
 ~/gittest/remote$ ls -l ~/gittest/remote$ ls -l
- 
 total 24 total 24
 -rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:20 file1.txt -rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:20 file1.txt
Line 19: Line 24:
 git commit -m 'initial commit on remote' git commit -m 'initial commit on remote'
 git log git log
- 
 commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789 (HEAD -> master) commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789 (HEAD -> master)
 Author: Patrick Truchon <patoo@rbox.me> Author: Patrick Truchon <patoo@rbox.me>
Line 33: Line 37:
   * The log on the local copy looks good:<code bash>   * The log on the local copy looks good:<code bash>
 ~/gittest/local$ git log ~/gittest/local$ git log
- 
 commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789 (HEAD -> master, origin/master, origin/HEAD) commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789 (HEAD -> master, origin/master, origin/HEAD)
 Author: Patrick Truchon <patoo@rbox.me> Author: Patrick Truchon <patoo@rbox.me>
Line 41: Line 44:
 </code> </code>
  
-  * But the ''www-data'' group ownership wasn't preserved:<code bash>+  * But the ''www-data'' group ownership and the 770 permissions weren't preserved:<code bash>
 ~/gittest/local$ ls -l ~/gittest/local$ ls -l
- 
 total 24 total 24
 -rwxrwxr-x 1 ptruchon ptruchon 26 Dec 26 10:24 file1.txt -rwxrwxr-x 1 ptruchon ptruchon 26 Dec 26 10:24 file1.txt
Line 49: Line 51:
 </code> </code>
  
-  * Change the group back to ''www-data'':<code bash> +  * Change the group back to ''www-data'' and permissions back to 770:<code bash> 
-sudo chgrp www-data *+sudo chgrp www-data *; chmod 770 *
 ls -l ls -l
- 
 total 24 total 24
--rwxrwxr-1 ptruchon www-data 26 Dec 26 10:24 file1.txt +-rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:24 file1.txt 
--rwxrwxr-1 ptruchon www-data 26 Dec 26 10:24 file2.txt+-rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:24 file2.txt
 </code> </code>
 +
  
 ==== Making Local Changes ==== ==== Making Local Changes ====
-Summary: no issues here. 
- 
   * Edit ''file1.txt'' from the local directory.<code bash>   * Edit ''file1.txt'' from the local directory.<code bash>
 ~/gittest/local$ git status ~/gittest/local$ git status
- 
 On branch master On branch master
 Your branch is up to date with 'origin/master'. Your branch is up to date with 'origin/master'.
Line 79: Line 78:
 git commit -m 'changed file1.txt from local' git commit -m 'changed file1.txt from local'
 git status git status
- 
 On branch master On branch master
 Your branch is ahead of 'origin/master' by 1 commit. Your branch is ahead of 'origin/master' by 1 commit.
Line 87: Line 85:
  
 git log git log
- 
 commit b7d91058fed9fe64c96525a3d0bef56c682ade68 (HEAD -> master) commit b7d91058fed9fe64c96525a3d0bef56c682ade68 (HEAD -> master)
 Author: Patrick Truchon <patoo@rbox.me> Author: Patrick Truchon <patoo@rbox.me>
Line 100: Line 97:
     initial commit on remote     initial commit on remote
 </code> </code>
 +
  
 ==== Push Changes to Remote ==== ==== Push Changes to Remote ====
-Summary:  Need to checkout a different branch on remote first and permissions are not preserved. +  Attempting to push changes to remote while master is still checked out on remote doesn't work:<code bash>
- +
-  Try to push changes to remote while master is still checked out on remote:<code bash>+
 ~/gittest/local$ git push origin master ~/gittest/local$ git push origin master
- 
 Enumerating objects: 5, done. Enumerating objects: 5, done.
 Counting objects: 100% (5/5), done. Counting objects: 100% (5/5), done.
Line 132: Line 127:
 </code> </code>
  
-  * Checkout a temporary branch from remote:<code bash>+  * Workaround is to checkout a temporary branch on remote:<code bash>
 ~/gittest/remote$ git checkout -b tmp ~/gittest/remote$ git checkout -b tmp
- 
 Switched to a new branch 'tmp' Switched to a new branch 'tmp'
 </code> </code>
  
-  * Push changes to remote while tmp is checked out on remote:<code bash>+  * Then push the local changes to remote:<code bash>
 ~/gittest/local$ git push origin master ~/gittest/local$ git push origin master
- 
 Enumerating objects: 5, done. Enumerating objects: 5, done.
 Counting objects: 100% (5/5), done. Counting objects: 100% (5/5), done.
Line 153: Line 146:
   * Check status and log from local:<code bash>   * Check status and log from local:<code bash>
 ~/gittest/local$ git status ~/gittest/local$ git status
- 
 On branch master On branch master
 Your branch is up to date with 'origin/master'. Your branch is up to date with 'origin/master'.
Line 160: Line 152:
  
 ~/gittest/local$ git log ~/gittest/local$ git log
- 
 commit b7d91058fed9fe64c96525a3d0bef56c682ade68 (HEAD -> master, origin/master, origin/HEAD) commit b7d91058fed9fe64c96525a3d0bef56c682ade68 (HEAD -> master, origin/master, origin/HEAD)
 Author: Patrick Truchon <patoo@rbox.me> Author: Patrick Truchon <patoo@rbox.me>
Line 172: Line 163:
  
     initial commit on remote     initial commit on remote
 +</code>
 +
 +  * On remote, checkout master and delete the temporary branch<code bash>
 +~/gittest/remote$ git checkout master; git branch -d tmp
 +Switched to branch 'master'
 +Deleted branch tmp (was 0e5ccde).
 +</code>
 +
 +  * Status and log both look good:<code bash>
 +git status
 +On branch master
 +nothing to commit, working tree clean
 +
 +git log
 +commit b7d91058fed9fe64c96525a3d0bef56c682ade68 (HEAD -> master)
 +Author: Patrick Truchon <patoo@rbox.me>
 +Date:   Sun Dec 26 10:45:41 2021 -0800
 +
 +    changed file1.txt from local
 +
 +commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789
 +Author: Patrick Truchon <patoo@rbox.me>
 +Date:   Sun Dec 26 10:21:24 2021 -0800
 +
 +    initial commit on remote
 +</code>
 +
 +  * But group ownership of the modified file wasn't preserved<code bash>
 +~/gittest/remote$ ls -l
 +total 24
 +-rwxrwxr-x 1 ptruchon ptruchon 50 Dec 26 12:01 file1.txt
 +-rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:20 file2.txt
 </code> </code>
  
howto/git.1640545172.txt.gz · Last modified: 2021/12/26 10:59 by va7fi