Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aur-fetch: unset GIT_DIR and GIT_WORK_TREE #636

Merged
merged 1 commit into from Nov 22, 2019
Merged

aur-fetch: unset GIT_DIR and GIT_WORK_TREE #636

merged 1 commit into from Nov 22, 2019

Conversation

tomeon
Copy link
Contributor

@tomeon tomeon commented Nov 4, 2019

Using master at 1b4782e, aur-fetch exits with nonzero status under the following conditions:

  1. It needs to fetch more than one repository
  2. At least one repository (other than the first one listed on the command line) is being fetched for the first time (initial git clone):
$ cd "$(mktemp -d)"
$ aur fetch aurutils aurutils-git 
Cloning into 'aurutils'...                                         
remote: Enumerating objects: 348, done.                            
remote: Counting objects: 100% (348/348), done.                    
remote: Compressing objects: 100% (232/232), done.                 
remote: Total 348 (delta 117), reused 347 (delta 116)              
Receiving objects: 100% (348/348), 66.21 KiB | 622.00 KiB/s, done. 
Resolving deltas: 100% (117/117), done.                            
HEAD is now at 3872019 upgpkg: aurutils 2.3.2-1                    
From https://aur.archlinux.org/aurutils                            
 = [up to date]      master     -> origin/master                   
Already up to date.                                                
Current branch master is up to date.                               
fatal: working tree 'aurutils' already exists.                     
==> ERROR: fetch: aurutils-git: Failed to clone repository 

The issue appears to be that aur-fetch doesn't unset GIT_DIR or GIT_WORK_TREE at the beginning of the "main" loop, thus reusing the values of GIT_DIR and GIT_WORK_TREE set on the prior iteration.

This merge request adds unset GIT_DIR GIT_WORK_TREE to the beginning of the main loop in aur-fetch, as well as a regression test case.

TIA for your consideration :)

@AladW
Copy link
Member

AladW commented Nov 4, 2019

This should be fixed along the way in 4dbab52

Anyway, a test case, nice. 👍

test/issue-636 Outdated
export AURDEST

cleanup() {
rm -rf --one-file-system --preserve-root "${AURDEST?}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question since "cleanup" is used in other places with temporary files: why those extra flags to rm, if the target string is quoted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things: an abundance of caution and (marginally) better diagnostics (well, three, including force of habit). Certainly not wedded to this approach, though, so I've harmonized this trap function with others in the existing codebase.

test/issue-636 Outdated
@@ -0,0 +1,14 @@
#!/bin/bash

AURDEST="$(mktemp -d --tmpdir "aurutils-${BASH_SOURCE[0]##*/}.XXXXXXXX")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it suffices to set argv0=issue-636, aurutils-$argv0 as other aur scripts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@AladW
Copy link
Member

AladW commented Nov 15, 2019

Should be fixed in master, but I'd still be interested in merging the regression test!

@tomeon
Copy link
Contributor Author

tomeon commented Nov 20, 2019

Should be fixed in master

Indeed! I have rebased the branch on master, dropping my change to aur-fetch, and the regression test exits without error. So, barring false negatives... :)

but I'd still be interested in merging the regression test!

I've updated the PR in (what I hope is) accordance with your comments; LMKWYT.

@AladW
Copy link
Member

AladW commented Nov 21, 2019

Thanks for the update. Just a small nitpick: since aur-fetch does not actually use AURDEST, I'd remove it (and the export) and simply set $tmp like other scripts do.

Copy link
Collaborator

@rafasc rafasc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to have missed this in my previous review.
The PR is not based on current master. Would be nice if you did that along with the suggestions from @AladW

to ensure that GIT_DIR/GIT_WORK_TREE environment variables are properly
set on each iteration of the aur-fetch main loop
@tomeon
Copy link
Contributor Author

tomeon commented Nov 21, 2019

Thanks for the update. Just a small nitpick: since aur-fetch does not actually use AURDEST, I'd remove it (and the export) and simply set $tmp like other scripts do.

Ah, yes -- suspect that was an artifact of an earlier test implementation that used aur-sync rather than calling aur-fetch directly. s/AURDEST/tmp/g done.

@tomeon
Copy link
Contributor Author

tomeon commented Nov 21, 2019

I seem to have missed this in my previous review.
The PR is not based on current master. Would be nice if you did that along with the suggestions from @AladW

Just pushed a rebase on master; are you also looking for the test script to exercise some newly-added feature(s)?

@tomeon tomeon requested a review from rafasc November 21, 2019 20:07
@AladW
Copy link
Member

AladW commented Nov 21, 2019

It looks good to me. If we wanted to test more features, I'd say this belongs to other separate tests.

Copy link
Collaborator

@rafasc rafasc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@rafasc
Copy link
Collaborator

rafasc commented Nov 21, 2019

@tomeon tests for new features would be nice, but we need to address some aspects regarding tests in general. I.e. Implement proper infrastructure for testing to avoid issues like #645.
We have #356 suggesting TAP, but at some point it was also discussed using a simpler shell/makefile based suite.

Regardless of the approach chosen, we also need some sort of library with functions for common tasks, e.g. setting up repos, configs, etc. Making tests easier to write and run will, hopefully, help turning the #497 list into actual tests.

Speaking for myself here, but I rarely run the ones we have. Proper infrastructure, and perhaps automation (hello github actions), would help making sure we actually run the tests. Otherwise it becomes hard to justify the effort that needs to be put in.

@tomeon
Copy link
Contributor Author

tomeon commented Nov 21, 2019

@rafasc -- sounds like a bigger discussion, and out-of-scope for this issue, but: what about BATS?

Seems to tick some of the boxes you listed:

Plus there's an available Docker image for use with (say) Travis CI, and an AUR package that could be used with (e.g.) builds.sr.ht.

Food for thought, perhaps :)

@AladW AladW merged commit 9bf4208 into aurutils:master Nov 22, 2019
@rafasc rafasc mentioned this pull request Nov 22, 2019
AladW added a commit that referenced this pull request Dec 31, 2019
AladW added a commit that referenced this pull request Jan 16, 2020
AladW added a commit that referenced this pull request Jan 16, 2020
AladW added a commit that referenced this pull request Jan 20, 2020
AladW added a commit that referenced this pull request Jan 24, 2020
AladW added a commit that referenced this pull request Jan 26, 2020
AladW added a commit that referenced this pull request Jan 26, 2020
AladW added a commit that referenced this pull request Jan 26, 2020
AladW added a commit that referenced this pull request Jan 28, 2020
dhouck added a commit to dhouck/aurutils that referenced this pull request Feb 1, 2020
dhouck added a commit to dhouck/aurutils that referenced this pull request Feb 1, 2020
dhouck added a commit to dhouck/aurutils that referenced this pull request Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants