-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git: test import of remote-only branch
This test coverage will become more important when we make changes to remote branch importing.
- Loading branch information
Showing
2 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
use std::path::Path; | ||
|
||
use crate::common::{get_stderr_string, TestEnvironment}; | ||
|
||
|
@@ -37,3 +38,46 @@ fn test_git_export_conflicting_git_refs() { | |
export or their "parent" branches. | ||
"###); | ||
} | ||
|
||
#[test] | ||
fn test_git_import_remote_only_branch() { | ||
let test_env = TestEnvironment::default(); | ||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
// Create non-empty git repo to add as a remote | ||
let git_repo_path = test_env.env_root().join("git-repo"); | ||
let git_repo = git2::Repository::init(git_repo_path).unwrap(); | ||
let signature = | ||
git2::Signature::new("Some One", "[email protected]", &git2::Time::new(0, 0)).unwrap(); | ||
let mut tree_builder = git_repo.treebuilder(None).unwrap(); | ||
let file_oid = git_repo.blob(b"content").unwrap(); | ||
tree_builder | ||
.insert("file", file_oid, git2::FileMode::Blob.into()) | ||
.unwrap(); | ||
let tree_oid = tree_builder.write().unwrap(); | ||
let tree = git_repo.find_tree(tree_oid).unwrap(); | ||
test_env.jj_cmd_success( | ||
&repo_path, | ||
&["git", "remote", "add", "origin", "../git-repo"], | ||
); | ||
|
||
git_repo | ||
.commit( | ||
Some("refs/heads/feature1"), | ||
&signature, | ||
&signature, | ||
"message", | ||
&tree, | ||
&[], | ||
) | ||
.unwrap(); | ||
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]); | ||
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###" | ||
feature1: 9f01a0e04879 message | ||
"###); | ||
} | ||
|
||
fn get_branch_output(test_env: &TestEnvironment, repo_path: &Path) -> String { | ||
test_env.jj_cmd_success(repo_path, &["branch", "list"]) | ||
} |