just playing with tangled
at gvimdiff 2.9 kB view raw
1// Copyright 2025 The Jujutsu Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15use testutils::git; 16 17use crate::common::TestEnvironment; 18 19#[test] 20fn test_git_root_git_backend_noncolocated() { 21 let test_env = TestEnvironment::default(); 22 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 23 let work_dir = test_env.work_dir("repo"); 24 25 let output = work_dir.run_jj(["git", "root"]); 26 insta::assert_snapshot!(output, @r#" 27 $TEST_ENV/repo/.jj/repo/store/git 28 [EOF] 29 "#); 30} 31 32#[test] 33fn test_git_root_git_backend_colocated() { 34 let test_env = TestEnvironment::default(); 35 test_env 36 .run_jj_in(".", ["git", "init", "--colocate", "repo"]) 37 .success(); 38 let work_dir = test_env.work_dir("repo"); 39 40 let output = work_dir.run_jj(["git", "root"]); 41 insta::assert_snapshot!(output, @r#" 42 $TEST_ENV/repo/.git 43 [EOF] 44 "#); 45} 46 47#[test] 48fn test_git_root_git_backend_external_git_dir() { 49 let test_env = TestEnvironment::default(); 50 let work_dir = test_env.work_dir("").create_dir("repo"); 51 let git_repo_work_dir = test_env.work_dir("git-repo"); 52 let git_repo = git::init(git_repo_work_dir.root()); 53 54 // Create an initial commit in Git 55 let tree_id = git::add_commit( 56 &git_repo, 57 "refs/heads/master", 58 "file", 59 b"contents", 60 "initial", 61 &[], 62 ) 63 .tree_id; 64 git::checkout_tree_index(&git_repo, tree_id); 65 assert_eq!(git_repo_work_dir.read_file("file"), b"contents"); 66 insta::assert_snapshot!( 67 git_repo.head_id().unwrap().to_string(), 68 @"97358f54806c7cd005ed5ade68a779595efbae7e" 69 ); 70 71 work_dir 72 .run_jj([ 73 "git", 74 "init", 75 "--git-repo", 76 git_repo_work_dir.root().to_str().unwrap(), 77 ]) 78 .success(); 79 80 let output = work_dir.run_jj(["git", "root"]); 81 insta::assert_snapshot!(output, @r#" 82 $TEST_ENV/git-repo/.git 83 [EOF] 84 "#); 85} 86 87#[test] 88fn test_git_root_simple_backend() { 89 let test_env = TestEnvironment::default(); 90 test_env 91 .run_jj_in(".", ["debug", "init-simple", "repo"]) 92 .success(); 93 let work_dir = test_env.work_dir("repo"); 94 95 let output = work_dir.run_jj(["git", "root"]); 96 insta::assert_snapshot!(output, @r#" 97 ------- stderr ------- 98 Error: The repo is not backed by a Git repo 99 [EOF] 100 [exit status: 1] 101 "#); 102}