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
Last revisionBoth sides next revision
howto:git [2021/12/26 10:31] – [Test Scenario] va7fihowto:git [2021/12/26 12:24] – [Test Scenarios] va7fi
Line 1: Line 1:
 ====== Git ====== ====== Git ======
-===== Test Scenario =====+===== 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 ====
   * 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>
-ptruchon@ThinkPad-T440:~/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 21: Line 30:
     initial commit on remote     initial commit on remote
 </code> </code>
 +
 +  * Create a local folder and clone from remote:<code bash>
 +git clone ~/gittest/remote/ ~/gittest/local/
 +</code>
 +
 +  * The log on the local copy looks good:<code bash>
 +~/gittest/local$ git log
 +commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789 (HEAD -> master, origin/master, origin/HEAD)
 +Author: Patrick Truchon <patoo@rbox.me>
 +Date:   Sun Dec 26 10:21:24 2021 -0800
 +
 +    initial commit on remote
 +</code>
 +
 +  * But the ''www-data'' group ownership and the 770 permissions weren't preserved:<code bash>
 +~/gittest/local$ ls -l
 +total 24
 +-rwxrwxr-x 1 ptruchon ptruchon 26 Dec 26 10:24 file1.txt
 +-rwxrwxr-x 1 ptruchon ptruchon 26 Dec 26 10:24 file2.txt
 +</code>
 +
 +  * Change the group back to ''www-data'' and permissions back to 770:<code bash>
 +sudo chgrp www-data *; chmod 770 *
 +ls -l
 +total 24
 +-rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:24 file1.txt
 +-rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:24 file2.txt
 +</code>
 +
 +
 +==== Making Local Changes ====
 +  * Edit ''file1.txt'' from the local directory.<code bash>
 +~/gittest/local$ git status
 +On branch master
 +Your branch is up to date with 'origin/master'.
 +
 +Changes not staged for commit:
 +  (use "git add <file>..." to update what will be committed)
 +  (use "git restore <file>..." to discard changes in working directory)
 + modified:   file1.txt
 +
 +no changes added to commit (use "git add" and/or "git commit -a")
 +</code>
 +
 +  * Commit changes in git:<code bash>
 +git add .
 +git commit -m 'changed file1.txt from local'
 +git status
 +On branch master
 +Your branch is ahead of 'origin/master' by 1 commit.
 +  (use "git push" to publish your local commits)
 +
 +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 (origin/master, origin/HEAD)
 +Author: Patrick Truchon <patoo@rbox.me>
 +Date:   Sun Dec 26 10:21:24 2021 -0800
 +
 +    initial commit on remote
 +</code>
 +
 +
 +==== Push Changes to Remote ====
 +  * Attempting to push changes to remote while master is still checked out on remote doesn't work:<code bash>
 +~/gittest/local$ git push origin master
 +Enumerating objects: 5, done.
 +Counting objects: 100% (5/5), done.
 +Delta compression using up to 4 threads
 +Compressing objects: 100% (3/3), done.
 +Writing objects: 100% (3/3), 329 bytes | 329.00 KiB/s, done.
 +Total 3 (delta 0), reused 0 (delta 0)
 +remote: error: refusing to update checked out branch: refs/heads/master
 +remote: error: By default, updating the current branch in a non-bare repository
 +remote: is denied, because it will make the index and work tree inconsistent
 +remote: with what you pushed, and will require 'git reset --hard' to match
 +remote: the work tree to HEAD.
 +remote: 
 +remote: You can set the 'receive.denyCurrentBranch' configuration variable
 +remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
 +remote: its current branch; however, this is not recommended unless you
 +remote: arranged to update its work tree to match what you pushed in some
 +remote: other way.
 +remote: 
 +remote: To squelch this message and still keep the default behaviour, set
 +remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
 +To /home/ptruchon/gittest/remote/
 + ! [remote rejected] master -> master (branch is currently checked out)
 +error: failed to push some refs to '/home/ptruchon/gittest/remote/'
 +</code>
 +
 +  * Workaround is to checkout a temporary branch on remote:<code bash>
 +~/gittest/remote$ git checkout -b tmp
 +Switched to a new branch 'tmp'
 +</code>
 +
 +  * Then push the local changes to remote:<code bash>
 +~/gittest/local$ git push origin master
 +Enumerating objects: 5, done.
 +Counting objects: 100% (5/5), done.
 +Delta compression using up to 4 threads
 +Compressing objects: 100% (3/3), done.
 +Writing objects: 100% (3/3), 329 bytes | 329.00 KiB/s, done.
 +Total 3 (delta 0), reused 0 (delta 0)
 +To /home/ptruchon/gittest/remote/
 +   0e5ccde..b7d9105  master -> master
 +</code>
 +
 +  * Check status and log from local:<code bash>
 +~/gittest/local$ git status
 +On branch master
 +Your branch is up to date with 'origin/master'.
 +
 +nothing to commit, working tree clean
 +
 +~/gittest/local$ git log
 +commit b7d91058fed9fe64c96525a3d0bef56c682ade68 (HEAD -> master, origin/master, origin/HEAD)
 +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>
 +
 +  * 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>
 +
 +==== www-data:www-data files ====
 +Sometimes Dokuwiki saves new files with the ''www-data:www-data'' ownership.  When this happens, Git is not able to override the changes.
 +
 +  * Change ownership of ''file2.txt'' or remote:<code bash>
 +~/gittest/remote$ sudo chown www-data:www-data file2.txt 
 +ls -l
 +total 24
 +-rwxrwxr-x 1 ptruchon www-data 50 Dec 26 12:01 file1.txt
 +-rwxrwx--- 1 www-data www-data 26 Dec 26 10:20 file2.txt
 +</code>
 +
 +  * Edit ''file2.txt'' on local and commit the changes:<code bash>
 +~/gittest/local$ git add .
 +git commit -m 'edited file2.txt on local'
 +[master b7c9353] edited file2.txt on local
 + 1 file changed, 1 insertion(+)
 +
 +git status
 +On branch master
 +Your branch is ahead of 'origin/master' by 1 commit.
 +  (use "git push" to publish your local commits)
 +
 +nothing to commit, working tree clean
 +
 +git log
 +commit b7c93538a15efe16ac60956ce3f77526ce43ec1d (HEAD -> master)
 +Author: Patrick Truchon <patoo@rbox.me>
 +Date:   Sun Dec 26 12:22:38 2021 -0800
 +
 +    edited file2.txt on local
 +
 +commit b7d91058fed9fe64c96525a3d0bef56c682ade68 (origin/master, origin/HEAD)
 +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>
 +
  
howto/git.txt · Last modified: 2021/12/26 12:26 by va7fi