github.com/git-lfs/git-lfs@v2.5.2+incompatible/t/t-unlock.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  . "$(dirname "$0")/testlib.sh"
     4  
     5  begin_test "unlocking a lock by path with good ref"
     6  (
     7    set -e
     8  
     9    reponame="unlock-by-path-master-branch-required"
    10    setup_remote_repo_with_file "$reponame" "c.dat"
    11  
    12    git lfs lock --json "c.dat" | tee lock.log
    13  
    14    id=$(assert_lock lock.log c.dat)
    15    assert_server_lock "$reponame" "$id" "refs/heads/master"
    16  
    17    git lfs unlock --id="$id"
    18    refute_server_lock "$reponame" "$id" "refs/heads/master"
    19  )
    20  end_test
    21  
    22  begin_test "unlocking a lock by path with tracked ref"
    23  (
    24    set -e
    25  
    26    reponame="unlock-by-path-tracked-branch-required"
    27    setup_remote_repo "$reponame"
    28    clone_repo "$reponame" "$reponame"
    29  
    30    git lfs track "*.dat"
    31    echo "c" > c.dat
    32    git add .gitattributes c.dat
    33    git commit -m "add c.dat"
    34  
    35    git config push.default upstream
    36    git config branch.master.merge refs/heads/tracked
    37    git push origin master
    38  
    39    git lfs lock --json "c.dat" | tee lock.log
    40  
    41    id=$(assert_lock lock.log c.dat)
    42    assert_server_lock "$reponame" "$id" "refs/heads/tracked"
    43  
    44    git lfs unlock --id="$id"
    45    refute_server_lock "$reponame" "$id" "refs/heads/tracked"
    46  )
    47  end_test
    48  
    49  begin_test "unlocking a lock by path with bad ref"
    50  (
    51    set -e
    52  
    53    reponame="unlock-by-path-other-branch-required"
    54    setup_remote_repo "$reponame"
    55    clone_repo "$reponame" "$reponame"
    56  
    57    git lfs track "*.dat"
    58    echo "c" > c.dat
    59    git add .gitattributes c.dat
    60    git commit -m "add c.dat"
    61    git push origin master:other
    62  
    63    git checkout -b other
    64    git lfs lock --json "c.dat" | tee lock.log
    65  
    66    id=$(assert_lock lock.log c.dat)
    67    assert_server_lock "$reponame" "$id" "refs/heads/other"
    68  
    69    git checkout master
    70    git lfs unlock --id="$id" 2>&1 | tee unlock.log
    71    if [ "0" -eq "${PIPESTATUS[0]}" ]; then
    72      echo >&2 "fatal: expected 'git lfs lock \'a.dat\'' to fail"
    73      exit 1
    74    fi
    75  
    76    assert_server_lock "$reponame" "$id" "refs/heads/other"
    77    grep 'Expected ref "refs/heads/other", got "refs/heads/master"' unlock.log
    78  )
    79  end_test
    80  
    81  begin_test "unlocking a lock by id with bad ref"
    82  (
    83    set -e
    84  
    85    reponame="unlock-by-id-other-branch-required"
    86    setup_remote_repo "$reponame"
    87    clone_repo "$reponame" "$reponame"
    88  
    89    git lfs track "*.dat"
    90    echo "c" > c.dat
    91    git add .gitattributes c.dat
    92    git commit -m "add c.dat"
    93    git push origin master:other
    94  
    95    git checkout -b other
    96    git lfs lock --json "c.dat" | tee lock.log
    97  
    98    id=$(assert_lock lock.log c.dat)
    99    assert_server_lock "$reponame" "$id" "refs/heads/other"
   100  
   101    git checkout master
   102    git lfs unlock --id="$id" 2>&1 | tee unlock.log
   103    if [ "0" -eq "${PIPESTATUS[0]}" ]; then
   104      echo >&2 "fatal: expected 'git lfs lock \'a.dat\'' to fail"
   105      exit 1
   106    fi
   107  
   108    assert_server_lock "$reponame" "$id" "refs/heads/other"
   109    grep 'Expected ref "refs/heads/other", got "refs/heads/master"' unlock.log
   110  )
   111  end_test
   112  
   113  begin_test "unlocking a file makes it readonly"
   114  (
   115    set -e
   116  
   117    reponame="unlock_set_readonly"
   118    setup_remote_repo_with_file "$reponame" "c.dat"
   119  
   120    git lfs lock --json "c.dat"
   121    assert_file_writeable c.dat
   122  
   123    git lfs unlock "c.dat"
   124    refute_file_writeable c.dat
   125  )
   126  end_test
   127  
   128  begin_test "unlocking a file ignores readonly"
   129  (
   130    set -e
   131  
   132    reponame="unlock_set_readonly_ignore"
   133    setup_remote_repo_with_file "$reponame" "c.dat"
   134  
   135    git lfs lock --json "c.dat"
   136    assert_file_writeable c.dat
   137  
   138    git -c lfs.setlockablereadonly=false lfs unlock "c.dat"
   139    assert_file_writeable c.dat
   140  )
   141  end_test
   142  
   143  begin_test "force unlocking lock with missing file"
   144  (
   145    set -e
   146  
   147    reponame="force-unlock-missing-file"
   148    setup_remote_repo_with_file "$reponame" "a.dat"
   149  
   150    git lfs lock --json "a.dat" | tee lock.log
   151    id=$(assert_lock lock.log a.dat)
   152    assert_server_lock "$reponame" "$id"
   153  
   154    git rm a.dat
   155    git commit -m "a.dat"
   156    rm *.log *.json # ensure clean git status
   157    git status
   158  
   159    git lfs unlock "a.dat" 2>&1 | tee unlock.log
   160    grep "Unable to determine path" unlock.log
   161    assert_server_lock "$reponame" "$id"
   162  
   163    rm unlock.log
   164    git lfs unlock --force "a.dat" 2>&1 | tee unlock.log
   165    refute_server_lock "$reponame" "$id"
   166  )
   167  end_test
   168  
   169  begin_test "unlocking a lock (--json)"
   170  (
   171    set -e
   172  
   173    reponame="unlock_by_path_json"
   174    setup_remote_repo_with_file "$reponame" "c_json.dat"
   175  
   176    git lfs lock --json "c_json.dat" | tee lock.log
   177  
   178    id=$(assert_lock lock.log c_json.dat)
   179    assert_server_lock "$reponame" "$id"
   180  
   181    git lfs unlock --json "c_json.dat" 2>&1 | tee unlock.log
   182    grep "\"unlocked\":true" unlock.log
   183  
   184    refute_server_lock "$reponame" "$id"
   185  )
   186  end_test
   187  
   188  begin_test "unlocking a lock by id"
   189  (
   190    set -e
   191  
   192    reponame="unlock_by_id"
   193    setup_remote_repo_with_file "$reponame" "d.dat"
   194  
   195    git lfs lock --json "d.dat" | tee lock.log
   196    assert_file_writeable d.dat
   197  
   198    id=$(assert_lock lock.log d.dat)
   199    assert_server_lock "$reponame" "$id"
   200  
   201    git lfs unlock --id="$id"
   202    refute_file_writeable d.dat
   203  )
   204  end_test
   205  
   206  begin_test "unlocking a lock without sufficient info"
   207  (
   208    set -e
   209  
   210    reponame="unlock_ambiguous"
   211    setup_remote_repo_with_file "$reponame" "e.dat"
   212  
   213    git lfs lock --json "e.dat" | tee lock.log
   214  
   215    id=$(assert_lock lock.log e.dat)
   216    assert_server_lock "$reponame" "$id"
   217  
   218    git lfs unlock 2>&1 | tee unlock.log
   219    grep "Usage: git lfs unlock" unlock.log
   220    assert_server_lock "$reponame" "$id"
   221  )
   222  end_test
   223  
   224  begin_test "unlocking a lock while uncommitted"
   225  (
   226    set -e
   227  
   228    reponame="unlock_modified"
   229    setup_remote_repo_with_file "$reponame" "mod.dat"
   230  
   231    git lfs lock --json "mod.dat" | tee lock.log
   232  
   233    id=$(assert_lock lock.log mod.dat)
   234    assert_server_lock "$reponame" "$id"
   235  
   236    echo "\nSomething" >> mod.dat
   237  
   238    git lfs unlock "mod.dat" 2>&1 | tee unlock.log
   239    [ ${PIPESTATUS[0]} -ne "0" ]
   240  
   241    grep "Cannot unlock file with uncommitted changes" unlock.log
   242  
   243    assert_server_lock "$reponame" "$id"
   244  
   245    # should allow after discard
   246    git checkout mod.dat
   247    git lfs unlock "mod.dat" 2>&1 | tee unlock.log
   248    refute_server_lock "$reponame" "$id"
   249  )
   250  end_test
   251  
   252  begin_test "unlocking a lock with ambiguious arguments"
   253  (
   254    set -e
   255  
   256    reponame="unlock_ambiguious_args"
   257    setup_remote_repo_with_file "$reponame" "a.dat"
   258  
   259    git lfs lock --json "a.dat" | tee lock.log
   260  
   261    id=$(assert_lock lock.log a.dat)
   262    assert_server_lock "$reponame" "$id"
   263  
   264    git lfs unlock --id "$id" a.dat 2>&1 | tee unlock.log
   265    if [ "0" -eq "${PIPESTATUS[0]}" ]; then
   266      echo >&2 "expected ambiguous \`git lfs unlock\` command to exit, didn't"
   267      exit 1
   268    fi
   269  
   270    grep "Usage:" unlock.log
   271    assert_server_lock "$reponame" "$id"
   272  )
   273  end_test
   274  
   275  begin_test "unlocking a lock while uncommitted with --force"
   276  (
   277    set -e
   278  
   279    reponame="unlock_modified_force"
   280    setup_remote_repo_with_file "$reponame" "modforce.dat"
   281  
   282    git lfs lock --json "modforce.dat" | tee lock.log
   283  
   284    id=$(assert_lock lock.log modforce.dat)
   285    assert_server_lock "$reponame" "$id"
   286  
   287    echo "\nSomething" >> modforce.dat
   288  
   289    # should allow with --force
   290    git lfs unlock --force "modforce.dat" 2>&1 | tee unlock.log
   291    grep "Warning: unlocking with uncommitted changes" unlock.log
   292    refute_server_lock "$reponame" "$id"
   293  )
   294  end_test
   295  
   296  begin_test "unlocking a lock while untracked"
   297  (
   298    set -e
   299  
   300    reponame="unlock_untracked"
   301    setup_remote_repo_with_file "$reponame" "notrelevant.dat"
   302  
   303    git lfs track "*.dat"
   304    # Create file but don't add it to git
   305    # Shouldn't be able to unlock it
   306    echo "something" > untracked.dat
   307    git lfs lock --json "untracked.dat" | tee lock.log
   308  
   309    id=$(assert_lock lock.log untracked.dat)
   310    assert_server_lock "$reponame" "$id"
   311  
   312    git lfs unlock "untracked.dat" 2>&1 | tee unlock.log
   313    [ ${PIPESTATUS[0]} -ne "0" ]
   314  
   315    grep "Cannot unlock file with uncommitted changes" unlock.log
   316  
   317    assert_server_lock "$reponame" "$id"
   318  
   319    # should allow after add/commit
   320    git add untracked.dat
   321    git commit -m "Added untracked"
   322    git lfs unlock "untracked.dat" 2>&1 | tee unlock.log
   323    refute_server_lock "$reponame" "$id"
   324  )
   325  end_test