Skip to content

Commit

Permalink
topbase only add label if splitout
Browse files Browse the repository at this point in the history
it doesnt make sense for topbase to always add a label. the only time it makes sense to do so is for splitout because the upstream branch gets deleted in splitout, whereas splitin the upstream branch is the users original branch, so it doesnt make sense to delete that, and for topbase as a standalone command, BOTH branches already exist, so theres no need to add a label then either
  • Loading branch information
nikita-skobov committed Oct 17, 2020
1 parent d987101 commit 9a59cd0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 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
19 changes: 12 additions & 7 deletions src/topbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,18 @@ impl<'a> Topbase for Runner<'a> {
}
}

// 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()]);
// 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>
Expand Down

0 comments on commit 9a59cd0

Please sign in to comment.