Skip to content

Commit

Permalink
Merge pull request #58 from nikita-skobov/topbase-add-label
Browse files Browse the repository at this point in the history
Topbase add label
  • Loading branch information
nikita-skobov authored Oct 17, 2020
2 parents 9f4ef36 + 9a59cd0 commit ed1ac73
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct Runner<'a> {
pub verbose: bool,
pub should_rebase: bool,
pub should_topbase: bool,
pub topbase_add_label: bool,
pub repo_file: RepoFile,
pub repo_root_dir: PathBuf,
pub topbase_top_ref: Option<String>,
Expand Down Expand Up @@ -56,6 +57,7 @@ impl<'a> Runner<'a> {
verbose: is_verbose,
should_rebase: is_rebase,
should_topbase: is_topbase,
topbase_add_label: false,
repo_file: RepoFile::new(),
topbase_top_ref: None,
repo_original_ref: None,
Expand All @@ -75,6 +77,11 @@ impl<'a> Runner<'a> {
}
}

pub fn add_label_before_topbase(mut self, flag: bool) -> Self {
self.topbase_add_label = flag;
self
}

// get the current ref that this git repo is pointing to
// save it for later
pub fn save_current_ref(mut self) -> Self {
Expand Down
1 change: 1 addition & 0 deletions src/split_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ pub fn run_split_out(matches: &ArgMatches) {
.get_repository_from_current_dir()
.change_to_repo_root()
.safe_to_proceed()
.add_label_before_topbase(true)
.generate_arg_strings()
.make_and_checkout_output_branch();

Expand Down
13 changes: 13 additions & 0 deletions src/topbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ impl<'a> Topbase for Runner<'a> {
}
}

// only add label in certain circumstances,
// otherwise a label being added is unnecessary
// and annoying
if self.topbase_add_label {
// if we've made it this far, that
// means we have commits to topbase
// so we should add a label here of the upstream
// branch, so if the user does a git log after topbase
// they can visualize which commits were added on top
let label_name = format!("{}-remote", current_branch);
let _ = exec_helpers::execute(&["git", "branch", label_name.as_str(), upstream_branch.as_str()]);
}

// rebase_data="pick <hash> <msg>
// pick <hash> <msg>
// pick <hash> <msg>
Expand Down
46 changes: 46 additions & 0 deletions test/splitout/end-to-end.bats
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,52 @@ function teardown() {
[[ "$(git status)" == *"rebase in progress"* ]]
}

@test '--topbase should add a branch label before rebasing' {
repo_file_contents="
remote_repo=\"..$SEP$test_remote_repo2\"
include=(\"lib/\")
"
echo "$repo_file_contents" > repo_file.sh

mkdir -p lib/
echo "libfile1.txt" > lib/libfile1.txt
git add lib/libfile1.txt && git commit -m "libfile1"

# make the same 'contribution' on the remote repo
# this mimics a scenario where you have previously
# contributed to that repo, so the next time you contribute,
# topbase will only add your most recent commits
curr_dir="$PWD"
cd "$BATS_TMPDIR/test_remote_repo2"
mkdir -p lib/
echo "libfile1.txt" > lib/libfile1.txt
git add lib/libfile1.txt && git commit -m "libfile1"
cd "$curr_dir"

# this is the recent contribution that will be topbased
echo "libfile1-mod" >> lib/libfile1.txt
git add lib/libfile1.txt && git commit -m "libfile1mod"

run $PROGRAM_PATH split-out repo_file.sh -t --verbose
echo "$output"
echo "$(git branch -v)"
echo -e "\n$(git branch --show-current):"
echo "$(git log --oneline)"
[[ $status == "0" ]]
[[ "$(git branch --show-current)" == "test_remote_repo2" ]]
output_log="$(git log --oneline)"
output_commits="$(git log --oneline | wc -l)"

# topbase should add a label to where the top of
# our libfile1mod was applied onto test_remote_repo2
[[ "$(git branch -v)" == *"test_remote_repo2-remote"* ]]
# the commit of this branch label should exist in our actual
# topbased branch. ie: this tests to make sure the branch
# label was applied in the right place
latest_label_commit="$(git log test_remote_repo2-remote --oneline -n 1)"
[[ "$output_log" == *"$latest_label_commit"* ]]
}

@test '--rebase should not say success if there were rebase merge conflicts' {
repo_file_contents="
remote_repo=\"..$SEP$test_remote_repo2\"
Expand Down

0 comments on commit ed1ac73

Please sign in to comment.