z/OS Tools & Language

Expand all | Collapse all

Maintaining extended file attributes across Git branch changes

  • 1.  Maintaining extended file attributes across Git branch changes

    Posted 12-09-2017 14:46

    As we’ve implemented Git on z/OS right now, extended file attributes can be lost if you switch branches. You can maintain them with a post-checkout hook. The hook we’re using on the RDL project is:

    main:
    
       address syscall "chdir" toplevel()
       call bpxwunix "find . -type d",,stdout.
    
       do # = 1 to stdout.0
          if \starts("./.git", stdout.#) then
             "extattr -Fnl" stdout.#"/* 2>/dev/null"
       end
    
    exit 0
    

    It sets the nl attribute recursively on all files that are not in .git directories.

    Edit: The toplevel function returns the result of a “git rev-parse --show-toplevel” command. The starts function returns a boolean indicating whether the second string starts with the first.



  • 2.  RE: Maintaining extended file attributes across Git branch changes

    Posted 12-11-2017 07:59

    Hello, Tony!
    I’ve tried to replicate your issue but attributes look intact after switching branches in my case.

    $ ls -EH tests/
    total 336
    drwxr-xr-x              2 TS5651   PDUSER      8192 Dec 11 05:21 ./
    drwxr-xr-x             15 TS5651   PDUSER      8192 Dec 11 05:24 ../
    -rw-r--r--  --s- ----   1 TS5651   PDUSER       274 Dec 11 05:21 .gitignore
    -rw-r--r--  --s- ----   1 TS5651   PDUSER       555 Dec 11 05:21 Makefile.am
    -rw-r--r--  --s- ----   1 TS5651   PDUSER      1115 Dec 11 05:21 tst-dlopen.c
    ...
    $ extattr -Fnl tests/*
    $ ls -EH tests/
    total 336
    drwxr-xr-x              2 TS5651   PDUSER      8192 Dec 11 05:21 ./
    drwxr-xr-x             15 TS5651   PDUSER      8192 Dec 11 05:24 ../
    -rw-r--r--  --s- ----   1 TS5651   PDUSER       274 Dec 11 05:21 .gitignore
    -rw-r--r--  --s- nl     1 TS5651   PDUSER       555 Dec 11 05:21 Makefile.am
    -rw-r--r--  --s- nl     1 TS5651   PDUSER      1115 Dec 11 05:21 tst-dlopen.c
    ...
    $ git checkout master_zos
    Switched to branch 'master_zos'
    Your branch is up-to-date with 'origin/master_zos'.
    $ git checkout master
    Switched to branch 'master'
    Your branch is up-to-date with 'origin/master'.
    $ ls -EH tests/
    total 336
    drwxr-xr-x              2 TS5651   PDUSER      8192 Dec 11 05:21 ./
    drwxr-xr-x             15 TS5651   PDUSER      8192 Dec 11 05:32 ../
    -rw-r--r--  --s- ----   1 TS5651   PDUSER       274 Dec 11 05:21 .gitignore
    -rw-r--r--  --s- nl     1 TS5651   PDUSER       555 Dec 11 05:21 Makefile.am
    -rw-r--r--  --s- nl     1 TS5651   PDUSER      1115 Dec 11 05:21 tst-dlopen.c
    ...
    $ extattr -FNA tests/*
    $ ls -EH tests/
    total 336
    drwxr-xr-x              2 TS5651   PDUSER      8192 Dec 11 05:21 ./
    drwxr-xr-x             15 TS5651   PDUSER      8192 Dec 11 05:32 ../
    -rw-r--r--  --s- ----   1 TS5651   PDUSER       274 Dec 11 05:21 .gitignore
    -rw-r--r--  --s- ----   1 TS5651   PDUSER       555 Dec 11 05:21 Makefile.am
    -rw-r--r--  --s- ----   1 TS5651   PDUSER      1115 Dec 11 05:21 tst-dlopen.c
    ...
    $ git version
    git version 2.3.5_zos_b014
    

    Could you please specify exact steps to reproduce your issue, your git and bash versions so we can reproduce your case correctly. Thanks



  • 3.  RE: Maintaining extended file attributes across Git branch changes

    Posted 12-11-2017 12:41

    Hi, uxus - if that is indeed your name. :slight_smile: To recreate the problem, switch to master_zos, delete a file that is also on master, then switch back to master. Thanks!



  • 4.  RE: Maintaining extended file attributes across Git branch changes

    Posted 12-12-2017 13:20

    Hi again, Danil. I’ve found another way to reproduce the issue:

    1. echo 'data' > testfile
    2. chtag -tc IBM-1047 testfile
    3. extattr -Fnl testfile
    4. ls -H - note that the nl attribute is on
    5. git add testfile
    6. git stash
    7. git stash pop
    8. ls -H - note that the nl attribute is off