Skip to content

Commit d4a8d85

Browse files
hsudhofcopybara-github
authored andcommitted
Explicitly set git-dir for bare repos in tool_test
Don't fail on urls that don't parse as URI PiperOrigin-RevId: 635523854 Change-Id: Ia82e12d39ff8cc4b665964cf313f0bc010ddb888
1 parent 02e9fa3 commit d4a8d85

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

copybara/integration/tool_test.sh

+10-12
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ EOF
183183
check_copybara_rev_id "$destination" "$second_commit"
184184

185185
( cd $destination || return
186-
run_git show $primary > $TEST_log
186+
run_git --git-dir="$destination" show $primary > $TEST_log
187187
)
188188

189189
expect_log "-first version for drink"
@@ -228,7 +228,7 @@ EOF
228228
check_copybara_rev_id "$destination" "$commit_three"
229229

230230
( cd $destination || return
231-
run_git log "${primary}~1..${primary}" > $TEST_log
231+
run_git --git-dir="$destination" log "${primary}~1..${primary}" > $TEST_log
232232
)
233233
expect_not_log "commit two"
234234
expect_log "commit three"
@@ -238,12 +238,12 @@ EOF
238238
check_copybara_rev_id "$destination" "$commit_five"
239239

240240
( cd $destination || return
241-
run_git log "${primary}~2..${primary}~1" > $TEST_log
241+
run_git --git-dir="$destination" log "${primary}~2..${primary}~1" > $TEST_log
242242
)
243243
expect_log "commit four"
244244

245245
( cd $destination || return
246-
run_git log "${primary}~1..${primary}" > $TEST_log
246+
run_git --git-dir="$destination" log "${primary}~1..${primary}" > $TEST_log
247247
)
248248
expect_log "commit five"
249249

@@ -381,7 +381,7 @@ EOF
381381
expect_log ".*${commit_five:0:10}.*commit five.*Bara Kopi <[email protected]>.*"
382382

383383
( cd $destination || return
384-
run_git "log" "${primary}~1..${primary}" > $TEST_log
384+
run_git --git-dir="$destination" "log" "${primary}~1..${primary}" > $TEST_log
385385
)
386386
# By default we include the whole history if last_rev cannot be found. --squash-without-history
387387
# can be used for disabling this.
@@ -397,7 +397,7 @@ EOF
397397
check_copybara_rev_id "$destination" "$commit_four"
398398

399399
( cd $destination || return
400-
run_git log "${primary}~1..${primary}" > $TEST_log
400+
run_git --git-dir="$destination" log "${primary}~1..${primary}" > $TEST_log
401401
)
402402
# "commit one" should not be included because it was migrated before
403403
expect_not_log "commit one"
@@ -411,7 +411,7 @@ EOF
411411
check_copybara_rev_id "$destination" "$commit_five"
412412

413413
( cd $destination || return
414-
run_git log "${primary}~1..${primary}" > $TEST_log
414+
run_git --git-dir="$destination" log "${primary}~1..${primary}" > $TEST_log
415415
)
416416
# We are forcing to use commit_three as the last migration. This has
417417
# no effect in squash workflow but it changes the release notes.
@@ -460,7 +460,7 @@ EOF
460460
check_copybara_rev_id "$destination" "$commit_three"
461461

462462
( cd $destination || return
463-
run_git log > $TEST_log
463+
run_git --git-dir="$destination" log > $TEST_log
464464
)
465465
expect_log "commit one"
466466
expect_not_log "commit two"
@@ -471,8 +471,7 @@ function empty_git_bare_repo() {
471471
repo=$(temp_dir repo)
472472
cd $repo || return
473473
run_git init . --bare > $TEST_log 2>&1 || fail "Cannot create repo"
474-
run_git --work-tree="$(mktemp -d)" commit --allow-empty -m "Empty repo" \
475-
> $TEST_log 2>&1 || fail "Cannot commit to empty repo"
474+
run_git --git-dir="$repo" --work-tree="$(mktemp -d)" commit --allow-empty -m "Empty repo"
476475
echo $repo
477476
}
478477

@@ -923,7 +922,6 @@ function test_command_copybara_filename_no_correct_name() {
923922
function setup_reversible_check_workflow() {
924923
remote=$(temp_dir remote)
925924
destination=$(empty_git_bare_repo)
926-
927925
pushd $remote || return
928926
run_git init .
929927
echo "Is the reverse of the reverse forward?" > test.txt
@@ -1334,7 +1332,7 @@ EOF
13341332
check_copybara_rev_id "$destination" "$commit_one"
13351333

13361334
( cd $destination || return
1337-
run_git log > $TEST_log
1335+
run_git --git-dir="$destination" log > $TEST_log
13381336
)
13391337
expect_log "c1 foooo destination/[a-f0-9]\{1,\} bar"
13401338
}

java/com/google/copybara/git/GitModule.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -2967,7 +2967,15 @@ protected LazyResourceLoader<EndpointProvider<?>> maybeGetGitHubApi(
29672967

29682968
@Nullable protected CredentialFileHandler getCredentialHandler(
29692969
String url, @Nullable Object starlarkValue) {
2970-
URI uri = URI.create(url);
2971-
return getCredentialHandler(uri.getHost(), uri.getPath(), starlarkValue);
2970+
try {
2971+
if (GITHUB_COM.isGitHubUrl(url)) {
2972+
url = GITHUB_COM.normalizeUrl(url);
2973+
}
2974+
URI uri = URI.create(url);
2975+
return getCredentialHandler(uri.getHost(), uri.getPath(), starlarkValue);
2976+
} catch (ValidationException | IllegalArgumentException parseEx) {
2977+
options.get(GeneralOptions.class).console().verboseFmt("Unable to parse %s as URI", url);
2978+
}
2979+
return null;
29722980
}
29732981
}

0 commit comments

Comments
 (0)